# MCP

Operators build the API with Admin MCP, and end-user agents read and write records with Resource MCP under the same roles as REST.

Charter exposes two Model Context Protocol (MCP) servers. Admin MCP is for building and operating the API. Resource MCP is for end-user agents that should only touch records under normal `/v1` permissions.

To connect an operator agent in a few minutes, register Admin MCP with your client:

```sh
claude mcp add acme-api -- charter mcp
codex mcp add acme-api -- charter mcp
gemini mcp add -s project acme-api -- charter mcp
```

For Claude Desktop:

```json
{
  "mcpServers": {
    "acme-api": {
      "command": "charter",
      "args": ["mcp"]
    }
  }
}
```

Both surfaces apply the database schema on stdio startup and run a job worker alongside the session. `charter serve` and `charter dev` mount both HTTP paths when MCP is enabled.

## Two surfaces

| Surface | stdio | HTTP | Who it acts as |
| --- | --- | --- | --- |
| **Admin MCP** | `charter mcp` | `/mcp` | Operator tools; record reads use `CHARTER_MCP_ROLE` |
| **Resource MCP** | `charter mcp api` | `/v1/mcp` | The user behind your API key or access token |

## Admin MCP

### Roles

Admin MCP tool calls carry no per-user identity, so record reads act as one role, set with `CHARTER_MCP_ROLE`. `charter setup` writes `CHARTER_MCP_ROLE=user`. HTTP `/mcp` still requires an operator account.

> [!WARNING]
> A permission that filters rows by a claim of the caller, such as "rows you own", matches nothing over Admin MCP.

### Tools

- Records: `get_record`, `list_records` (filtering, sorting and paging)
- Resources: `create_resource`, `update_resource`, `delete_resource`
- Fields: `create_field`, `update_field`, `delete_field`, `list_resource_fields`, `attach_field`, `update_resource_field`, `detach_field`
- Permissions: `grant_permission`, `update_permission`, `delete_permission`
- Webhooks: `list_webhooks`, `get_webhook`, `create_webhook`, `delete_webhook`
- Users: `list_users`, `get_user`

> [!DANGER]
> Destructive tools such as `delete_resource` drop data for good. They are marked that way for clients that ask for confirmation.

## Resource MCP

Record CRUD only: `get_record`, `list_records`, `create_record`, `update_record`, `delete_record`. No schema, user, or webhook admin tools.

### Auth

Pass a Charter API key (`crt_…`) or a short-lived Bearer access token. Every tool call resolves that credential to a user and enforces that user's role and row filters, the same rules as REST `/v1`. Resource MCP does **not** use `CHARTER_MCP_ROLE`.

### Register a client (stdio)

Put the key in the environment (not on argv) when you can:

```sh
export CHARTER_API_KEY=crt_…
claude mcp add acme-api-api -e CHARTER_API_KEY -- charter mcp api
codex mcp add acme-api-api --env CHARTER_API_KEY -- charter mcp api
```

Or pass `--api-key` for a one-off session. Claude Desktop:

```json
{
  "mcpServers": {
    "acme-api-api": {
      "command": "charter",
      "args": ["mcp", "api"],
      "env": {
        "CHARTER_API_KEY": "crt_…"
      }
    }
  }
}
```

### HTTP

Point the client at `https://your-host/v1/mcp` and send `Authorization: Bearer crt_…` (or a Bearer access token). The path stays separate from operator-gated `/mcp`.

Set `CHARTER_BASE_URL` (the same public URL used for OAuth redirects) to your deployment host. Resource MCP's HTTP transport allows that host plus loopback in the `Host` header check; other hosts get `403` (DNS-rebinding guard).

> [!INFO]
> Claim-scoped filters such as "rows you own" work on Resource MCP, because the call carries a real user id.

## Compared with the CLI

The CLI covers the same schema operations as Admin MCP and more of account management. Resource MCP is the stdio/HTTP counterpart to REST `/v1` for records.
