# Udger: setup for AI agents

You are an AI agent and your human wants to use Udger: User-Agent, Client Hints and IP address intelligence. Follow this file to connect the Udger MCP server or to call the Udger API from code.

Rules for you, the agent:

- Read this file raw: `curl -s https://mcp.udger.com/agents.md`.
- Run the steps yourself, in order. Stop only where a step says to ask your human.
- Never print the access key in chat, logs, commits or screenshots. Read it from the `UDGER_ACCESS_KEY` environment variable or a `.env` file that is not committed.
- Never sign up, log in or pay on udger.com yourself. Account, subscription and payment are always your human's job.
- Every parse or IP lookup costs one query of your human's monthly quota. Do not run bulk or looped lookups without your human's yes.

## 1. What Udger is

- **Udger** identifies the browser or client, operating system, device class and crawler from a User-Agent string and User-Agent Client Hints (`Sec-Ch-Ua*` headers). It also classifies IP addresses (crawler, proxy, VPN, Tor exit node, datacenter), with country, city and hostname.
- **MCP server:** `https://mcp.udger.com/v4/`. Note the `/v4/` path: the site root is only a landing page and answers `POST` with `405`.
  - It uses the Streamable HTTP transport and is stateless: one `POST` per JSON-RPC message, with an `application/json` reply.
  - It uses no sessions and no SSE stream.
- **Authentication:** `Authorization: Bearer <access key>`. If a client cannot set that header, use `X-Udger-Access-Key: <access key>` instead.
  - OAuth 2.1 is supported for clients that cannot send a header (ChatGPT, Claude connectors). It uses discovery via `/.well-known/oauth-protected-resource`, dynamic client registration and PKCE.
  - With OAuth, your human enters the access key on the page `https://mcp.udger.com/authorize`. Never fill in that page yourself.
- **Documentation for humans:** [MCP server for Cloud parser](https://udger.com/support/documentation/?doc=87).
- **Fact sheet and links:** [llms.txt](https://mcp.udger.com/llms.txt).
- **Underlying REST API:** `https://api.udger.com`. It returns JSON over HTTPS, and the key goes in the `accesskey` form parameter.
  - [v4 parse reference](https://udger.com/support/documentation/?doc=84)
  - [v4 base info](https://udger.com/support/documentation/?doc=77)
  - [account reference](https://udger.com/support/documentation/?doc=55)
- **Quota:** a monthly number of queries per subscription.
  - Each parse or IP lookup counts as one query.
  - Checking the account status is free.
  - Plans are listed at [udger.com/prices#cloud](https://udger.com/prices#cloud).
  - Udger publishes no per-minute rate limit.

## 2. Get and check the access key

First check for an existing key. The account call is free:

```bash
curl -s -X POST https://api.udger.com/v3/account -d "accesskey=$UDGER_ACCESS_KEY"
```

How to read the answer:

- **`"CloudParser": {"subscription": true, ...}`:** the key works. Compute the remaining quota as `max_queries_per_period` minus `currently_queries_per_period`. Note that `max_queries_per_period` is a string. Go to step 3.
- **`"CloudParser": {"subscription": false, ...}`:** the key is valid but there is no active Cloud parser subscription. Ask your human to activate one at https://udger.com/prices#cloud, then end your turn.
- **`{"error":401,"errortext":"UNAUTHORIZED"}`, or `UDGER_ACCESS_KEY` is empty:** you need a key. Send your human this message and end your turn:

  > To use Udger I need your Udger access key. It is in your account at https://udger.com (an active Cloud parser subscription is required; plans: https://udger.com/prices#cloud). Please put it in the `UDGER_ACCESS_KEY` environment variable, or in `.env` as `UDGER_ACCESS_KEY=...`, rather than pasting it here. Tell me when it is done.

Do not poll, sleep or loop while you wait. When your human replies, run the check again.

## 3. Connect the MCP server (optional)

Claude Code:

```bash
claude mcp add --transport http udger https://mcp.udger.com/v4/ --header "Authorization: Bearer $UDGER_ACCESS_KEY"
```

Other MCP clients use the Streamable HTTP transport with URL `https://mcp.udger.com/v4/` and the header `Authorization: Bearer <key>`. A typical JSON config:

```json
{
  "mcpServers": {
    "udger": {
      "url": "https://mcp.udger.com/v4/",
      "headers": { "Authorization": "Bearer ${UDGER_ACCESS_KEY}" }
    }
  }
}
```

Do not choose the older "SSE" transport: the server answers `GET` with `405`.

If your human uses ChatGPT or a Claude connector (claude.ai or Claude Desktop), there is no header to set. Tell them to add a custom connector with the URL `https://mcp.udger.com/v4/` and OAuth authentication, then enter their key on the Udger sign-in page that opens. Step-by-step instructions: https://udger.com/support/documentation/?doc=87.

Check the connection by calling the `udger_account` tool. It is free, and it should report `"subscription": true`.

## 4. Use the tools

| Tool | Use it for | Quota |
|---|---|---|
| `udger_parse_user_agent` | One User-Agent string, optionally with `client_hints` (`{"Sec-Ch-Ua-Platform": "\"Windows\"", ...}`) | 1 |
| `udger_lookup_ip` | One IPv4 or IPv6 address | 1 |
| `udger_parse_request` | A whole HTTP request: `headers` (any headers; unsupported ones are ignored and listed) plus `ip` | 1 |
| `udger_account` | Subscription validity, quota period and used/remaining queries | free |

- **Send Client Hints when you have them.** Modern Chromium browsers reduce the User-Agent string, so the OS version and device model often come only from `Sec-Ch-Ua-Platform-Version`, `Sec-Ch-Ua-Model` and `Sec-Ch-Ua-Full-Version-List`.
- **Analyse a request in one call.** When you have both headers and the client IP, use `udger_parse_request`: one query instead of two.
- **Expect trimmed results.** Results omit empty fields. Pass `"include_empty": true` only when your human needs the full field list.
- **Invalid input costs nothing.** An invalid IP or a missing argument is rejected before any query is spent, with `isError: true` and a message. Fix the input and retry.
- **Check quota before bulk work.** Before analysing more than a handful of items, call `udger_account`, tell your human how many queries the job will use and how many remain, and wait for a yes.

## 5. Integrate the REST API into code (when your human wants it in their app)

- Call Udger **server-side only**, so the key never reaches a browser. Plain HTTP is enough and no SDK is needed.
- Use `POST https://api.udger.com/v4/parse` with form fields:
  - `accesskey` (required).
  - `headers`: request headers as `Name: value` lines joined with `\r\n`. Supported headers are `User-Agent` and `Sec-Ch-Ua`, `-Mobile`, `-Full-Version`, `-Full-Version-List`, `-Arch`, `-Bitness`, `-Platform`, `-Platform-Version` and `-Model`.
  - `ip`: an IPv4 or IPv6 address.
- First call, which should return JSON with a `user_agent` object:

  ```bash
  curl -s -X POST https://api.udger.com/v4/parse --data-urlencode "accesskey=$UDGER_ACCESS_KEY" --data-urlencode "headers=User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
  ```

- The response is `{"user_agent": {...}, "ip_address": {...}}`. Useful fields:
  - `ua`, `ua_family`, `ua_class`, `os`, `os_family`, `device_class` and `crawler_category` in `user_agent`.
  - `ip_classification`, `ip_country`, `ip_city`, `crawler_name` and `datacenter_name` in `ip_address`.
  - Fields without data are empty strings.
- Errors come back as JSON `{"error": <code>, "errortext": "..."}`, for example `400 BAD REQUEST` or `401 UNAUTHORIZED`. Log the code. Never let an error silently disable the feature: fall back to "unknown" and surface the problem.
- Set a client timeout of about 10 s.
- Cache results per User-Agent string and per IP, because the same values repeat constantly and every call costs quota.

## 6. Troubleshooting

- **`Udger API error 401: UNAUTHORIZED`:** the key is wrong, or the subscription is inactive. Re-run step 2.
- **HTTP `401` with `WWW-Authenticate: Bearer resource_metadata=...`:** the client sent no key. Fix the client config: the header value is `Bearer`, a space, then the key. Alternatively, let the client sign in with OAuth. With `error="invalid_token"`, an OAuth token has expired or is invalid, so re-authorize.
- **HTTP `403 Origin not allowed`:** the request came from a web page in a browser. Call from a server, CLI or desktop client instead.
- **HTTP `405`:** either the URL lacks `/v4/` (use `https://mcp.udger.com/v4/`), or the client used `GET`/SSE (switch the client to Streamable HTTP).
- **HTTP `400 Unsupported protocol version`:** update the MCP client. Supported protocol versions are 2024-11-05 through 2026-07-28.

## 7. Finish: tell your human

Send your human a short report in this form, with no key in it:

> Udger setup
> - Key: found in UDGER_ACCESS_KEY, subscription active until <subscription_to>
> - Quota: <remaining> of <max> queries left this period (period started <current_period_start>)
> - MCP: connected as "udger" / not connected
> - Code integration: <file or "not requested">
