# MCP tool calls

> Allow or refuse each MCP tool, resource and prompt by name, for each agent or user, on a server that knows nothing about your policies.

An MCP (Model Context Protocol) server offers many tools behind one address, and they're rarely equally safe:
`get_weather` is not `delete_records`. Deciding by address alone would open or close the whole server. With the
gateway in front of it, each MCP call is decided as what it does, the tool, resource or prompt it names, so you
allow one tool and refuse another on the same server, for each agent or user, with policies in the realm.

A refusal comes back as a JSON-RPC error that MCP clients read natively, and an MCP client that has never met your
server finds where to sign in from the gateway's [resource metadata](/gateway/protect-apis/requests-and-refusals/#resource-metadata).

## Before you begin

- **The gateway running** in front of the MCP server: see [Run the gateway](/gateway/protect-apis/run-the-gateway/).
  Its image isn't published yet: ask your Cvyūh contact for it.
- **A realm administrator** in a group holding `RealmOwner`, to create the resource types, the policy set and the
  policies, with the API.
- **An MCP server that speaks Streamable HTTP**, at a path such as `/mcp`, and clients on protocol version
  `2026-07-28` or later.

## How it works

A client calls the server through the gateway, repeating the method and the name it acts on in headers:

```http
POST /mcp HTTP/1.1
Host: gw.example.com
Authorization: DPoP eyJ…
DPoP: eyJ…
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: get_weather
Content-Type: application/json

{ "jsonrpc": "2.0", "id": 1, "method": "tools/call",
  "params": { "name": "get_weather", "arguments": {} } }
```

On a path you've named as an MCP server, the gateway reads the call, checks the headers against the body, and decides
it as a resource of one of five types, named under the server's audience, with the MCP method as the action. This
call is decided as the action `tools/call` on `https://gw.example.com/mcp/tool/get_weather`.

| MCP method | Decided as | Resource name |
|---|---|---|
| `tools/call` | `tool` | `<audience>/tool/<name>` |
| `resources/read`, `resources/subscribe`, `resources/unsubscribe` | `resource` | `<audience>/resource/<uri>` |
| `prompts/get` | `prompt` | `<audience>/prompt/<name>` |
| `completion/complete` | `prompt` or `resource`, as its reference says | as above |
| `tasks/get`, `tasks/result`, `tasks/cancel` | `task` | `<audience>/task/<taskId>` |
| `tools/list`, `resources/list`, `prompts/list`, `tasks/list`, `logging/setLevel` | `mcp_server` | `<audience>` |
| `ping`, `initialize`, `notifications/*` | — | Pass on a valid token alone |

A method nothing maps is refused.

The name is taken whole, as one segment: every character other than letters, digits and `-._~` is percent-encoded,
so a tool called `get_*` is never read as a pattern, and a `/` or `..` in a resource URI never places it beneath
another.

The gateway publishes the server's metadata where MCP clients look, naming the realm. Its path is
`/.well-known/oauth-protected-resource` followed by the path of the server's audience: for
`https://gw.example.com/mcp`, that's `/.well-known/oauth-protected-resource/mcp`.

## Set it up

[Protect an MCP server](/gateway/guides/protect-an-mcp-server/) walks through it. In short, with the admin API at
`https://foobar.cvyuh.com/api/v0/am` ([Call the API](/develop/api/)):

1. **Create the MCP resource types** your server needs, each covering its names and listing the methods that act on
   it. For a server whose audience is `https://gw.example.com/mcp`:

   | `resourceType` | `patterns` | `actions` |
   |---|---|---|
   | `tool` | `https://gw.example.com/mcp/tool/*` | `tools/call` |
   | `resource` | `https://gw.example.com/mcp/resource/*` | `resources/read`, `resources/subscribe`, `resources/unsubscribe`, `completion/complete` |
   | `prompt` | `https://gw.example.com/mcp/prompt/*` | `prompts/get`, `completion/complete` |
   | `task` | `https://gw.example.com/mcp/task/*` | `tasks/get`, `tasks/result`, `tasks/cancel` |
   | `mcp_server` | `https://gw.example.com/mcp` | `tools/list`, `resources/list`, `prompts/list`, `tasks/list`, `logging/setLevel` |

2. **Create a policy set** whose `comparator` is `regex`, and link the types to it. A `regex` set matches the whole
   name and respects case, as tool names want; start a pattern with `(?i)` to ignore case.

3. **Write a policy** for each thing you allow, linked to the set and to its type. This one lets agents call
   `get_weather`:

   ```json
   {
     "active": true,
     "resources": ["https://gw.example.com/mcp/tool/get_weather"],
     "actionValues": { "tools/call": true },
     "subject": { "type": "JwtClaim", "claimName": "principal_type", "claimValue": "agent" }
   }
   ```

4. **Tell the gateway** which paths are the MCP server, its audience and the set: see [Settings](#settings).

## Good to know

- **Header and body must agree.** MCP clients repeat the method and name in `Mcp-Method` and, for `tools/call`,
  `prompts/get` and `resources/read`, `Mcp-Name`. A call whose headers disagree with its body, or that lacks a header
  its method needs, is refused, so a call can't be decided as one tool and run as another. `Mcp-Name` may be sent as
  `=?base64?<value>?=`, Base64 of the UTF-8 name.
- **Only current protocol versions.** A call without `MCP-Protocol-Version`, or with one older than `2026-07-28`, is
  refused.
- **Bodies up to 1 MiB.** A larger body is refused `413`, never decided on its headers alone.
- **Letter case follows the policy set.** In a `regex` set, `Get_Weather` is not `get_weather` unless the pattern
  starts with `(?i)`. In a `prefix` set, the default, case is ignored.
- **Refusals speak MCP.** A refusal keeps its HTTP status and its `Bearer` or `DPoP` challenge, with its reason in a
  JSON-RPC error body.
- **Listings aren't filtered.** `tools/list`, and the other listings, show every tool the server has, including ones
  the caller will be refused. A listing is decided for the server as a whole.
- **Behind your own proxy.** The `ext_authz` check reads the body your proxy sends with it. A proxy that sends no body
  can be decided on the MCP headers alone with the headers-only setting, but only for `tools/call`,
  `resources/read`, `prompts/get`, the listings and the calls that pass on a token alone, and only when that proxy has
  already held the headers to the body: see
  [Put the gateway behind your proxy](/gateway/guides/put-the-gateway-behind-your-proxy/#mcp-calls-without-the-body).
- **The server gets its own token, if you ask.** With [token swap](/gateway/protect-apis/token-swap/) on, each allowed call goes
  on under a token meant for the MCP server; without it, the caller's token goes through as it came.

## Coming next

- **MCP tool federation:** one endpoint for many servers' tools. See
  [What's next for MCP servers](/gateway/mcp-servers/whats-next/#mcp-tool-federation).

## Reference

### Settings

| Gateway setting | What it does |
|---|---|
| `JWT_AUDIENCE` | The server's resource name: the audience its tokens must carry, and where its metadata is published. Every MCP name sits under it |
| `MCP_PATHS` | The paths an MCP server answers at. A `POST` to one is decided as the call it makes. None by default |
| `POLICY_SET` | The set the calls are decided in |
| `UPSTREAM_AUDIENCE` | The MCP server's own resource name. Set, each allowed call goes on under a token meant for it |
| `SCOPES` | The scopes its metadata names |
| The headers-only setting | Decide a bodiless `ext_authz` check on its MCP headers alone (default off, which refuses such a check) |

The rest are in [Gateway configuration](/gateway/configuration/).

### Errors

Each refusal's body is a JSON-RPC error with a null `id`:

| HTTP status | JSON-RPC code | When |
|---|---|---|
| `400` | `-32020` | A header is missing, malformed or disagrees with the body; the protocol version is older than `2026-07-28`; the body isn't a JSON-RPC message |
| `400` | `-32602` | The call lacks what it's decided on, such as a `tools/call` with no `name` |
| `403` | `-32001` | A method the gateway doesn't decide, or a policy refuses the call |
| `413` | `-32001` | The body is over 1 MiB |

The headers and body are checked first. A well-formed call with no valid token is then refused `401` with its
challenge, as at any other path the gateway guards.

## Limits and defaults

| What | Default | Can it change? |
|---|---|---|
| A request body on an MCP path | Up to 1 MiB | No |
| Oldest protocol version | `2026-07-28` | No |
| Resource types | `tool`, `resource`, `prompt`, `task`, `mcp_server` | No: create the ones your server needs |
| Name matching | As the policy set's comparator: `prefix` ignores case, `regex` respects it | Per policy set |
| Listings | Decided for the server as a whole | No |

## What the client sees

A refused call gets the HTTP status and challenge any refusal gets, with a JSON-RPC error body that MCP clients show to
the user or the model, under [Errors](#errors). A client without a token gets `401` and the address of the server's
metadata, and starts its sign-in from there.

## Audit record

The gateway's MCP decisions aren't on the audit trail yet. Each refusal is a warning line in the gateway's own log,
with the path and the reason, and with the call it was decided as. A decision the gateway asks the realm for is a
`POLICY_DECIDED` record, naming the tool, resource or prompt. See
[Logs and tracing](/gateway/configuration/#logs-and-tracing).

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| Every call is `403 no_policies_loaded` | The MCP resource types aren't linked to the policy set, or no policy is linked to them | Link each type to the set, and each policy to its set and type |
| `Get_Weather` is refused though `get_weather` is allowed | A `regex` set matches case | Use the tool's exact name, or start the pattern with `(?i)` |
| Every call is `400` with `-32020` | The client is on an older protocol version, or doesn't send `Mcp-Method` and `Mcp-Name` | Update the client to `2026-07-28` or later |
| Every call is `401 invalid_token` | `JWT_AUDIENCE` isn't the server's audience, such as `https://gw.example.com/mcp` | Set it to the audience clients ask tokens for |
| Calls are decided as plain HTTP, not as tools | The path isn't in `MCP_PATHS` | Add it |
| A tool the caller can't call shows up in `tools/list` | Listings aren't filtered | Expected: the call itself is refused |

## Related

- [Protect an MCP server](/gateway/guides/protect-an-mcp-server/): the task, start to finish.
- [Token swap](/gateway/protect-apis/token-swap/): each MCP server gets a token of its own.
- [Bound tokens at the gateway](/gateway/protect-apis/bound-tokens/): agents' tokens bound to their key.
- [Policies](/workforce-identity/authorization/policies/): writing the rules.
