# MCP server

### What it is

AIProxy has a [Model Context Protocol](https://modelcontextprotocol.io) server, so a coding agent such as Claude Code or Codex can integrate AIProxy into your app for you: create the app and service, submit your provider key, drop the service URL and partial key into your code, turn on device verification, and confirm the first request went through. The same server lets an agent watch a live app: recent requests, traffic summaries, the audit log, and bans.

It is hosted by the dashboard, so there is nothing to install. Every tool calls the same code as the [admin API](/docs/admin-api.html), and every change it makes is recorded in the app's audit log with the actor `mcp`.

```
https://dashboard.aiproxy.com/mcp
```

### Connecting

The server is authenticated with the same keys as the admin API: the admin API key for an agent that may change things, or the read-only API key for one that only watches. Both are generated on the [account page](https://dashboard.aiproxy.com/account) and shown once. The key travels as a bearer token; there is no separate login.

##### Claude Code

Add it to your user configuration, so the key never lands in a repository:

```
claude mcp add --transport http --scope user aiproxy https://dashboard.aiproxy.com/mcp \
  --header "Authorization: Bearer $AIPROXY_ADMIN_KEY"
```

Claude Code's project-level `.mcp.json` can also declare the server with `"type": "http"` and an `Authorization` header. If you do that, keep the key out of the file: Claude Code expands `${AIPROXY_ADMIN_KEY}` placeholders from the environment, though some releases have had trouble expanding them inside `headers`, so check with `/mcp` that the server shows as connected.

##### Codex

```
codex mcp add aiproxy --url https://dashboard.aiproxy.com/mcp --bearer-token-env-var AIPROXY_ADMIN_KEY
```

Which writes to `~/.codex/config.toml`:

```
[mcp_servers.aiproxy]
url = "https://dashboard.aiproxy.com/mcp"
bearer_token_env_var = "AIPROXY_ADMIN_KEY"
```

Then ask the agent to integrate AIProxy, or invoke the server's `integrate_aiproxy` prompt, which walks it through the steps below.

An agent holding the admin key can create and delete services and submit provider keys. Give it the read-only key unless you want it to make changes, and keep both keys out of your app and out of source control.

### Tools

The read tools are available to both keys. The write tools are only offered to the admin key, so a read-only session never sees them.

| Tool | What it does |
| --- | --- |
| `list_apps` | Every app in the account with its services and this month's usage. The `uuid` and `api_uuid` values the other tools take. |
| `get_app` | One app: services, usage, DeviceCheck and App Attest configuration including the Simulator bypass tokens, and current bans. |
| `get_service` | One service in full: settings, key names, endpoint allowlist with rate limits and overrides, alerts, and the provider paths AIProxy already knows. |
| `recent_requests` | The newest requests, with provider status, AIProxy rejections, token counts, and timing. Filter by service, client ID, or failures only. |
| `traffic_summary` | Aggregates over a window: requests, clients, tokens, provider status counts, rejections by type, and the top clients. |
| `audit_log` | Every configuration change, newest first, with who made it. |
| `create_app` | Creates an app. |
| `create_service` | Creates a service and, with a provider key, submits the key in the same call. Returns `service_url` and the one-time `partial_key`. Also builds Foundation Models routers, remote config, and log ingest services. |
| `add_provider_key` | Submits a provider key to an existing service and returns its one-time partial key. Use it to rotate keys. |
| `configure_app_attest` | Sets the app's Apple team ID and bundle ID and returns the Simulator bypass token. |
| `set_verification` | Chooses `app_attest`, `device_check`, or `none` for a service. |
| `set_endpoint_allowlist` | Adds provider paths and restricts the service to them. |
| `set_rate_limit` | Caps requests per user or per IP in a window, for the service or one endpoint. Updates an existing limit for the same scope and window instead of duplicating it. |
| `ban_client`, `unban_client` | Ban or unban a client ID or IP address across the app. |

The public documentation pages are exposed as resources under `aiproxy://docs/`, so the agent can read the [integration guide](/docs/integration-guide.html) or the [client contract](/docs/build-your-own-client.html) without leaving the session.

### What the integration looks like

With the server connected and the admin key, a prompt like "integrate AIProxy for OpenAI into this app" leads the agent through:

1. `list_apps`, then `create_app` if the project has no app yet.
2. `create_service` with `api.openai.com` and your OpenAI key, which it asks you for. The partial key comes back once; the agent writes it and the service URL into your code and does not repeat it in its summary.
3. Adds the AIProxySwift package and the service initializer, or the raw HTTP headers on other platforms.
4. `configure_app_attest` with your team ID and bundle ID, then `set_verification` with `app_attest`, and sets the bypass token in your Xcode scheme for the Simulator.
5. `set_rate_limit` for a per-user cap and, if the app uses a few endpoints, `set_endpoint_allowlist`.
6. After you run the app once, `recent_requests` to confirm a request reached the provider.

Anything the tools do not cover, from model overrides to remote config flags, is on the [admin API](/docs/admin-api.html), which the agent can call with the same key.

### Protocol notes

The endpoint speaks the MCP Streamable HTTP transport and is stateless: each `POST` carries one JSON-RPC message and needs no session, so any MCP client that can send a bearer header works. `GET` (the optional server-to-client stream) is not offered. Requests must send `Accept: application/json`; `text/event-stream` may be included as well. A missing or invalid key returns `401`.


