# MCP composition

**Last updated:** 2026-11-22T07:10:00-03:00 (UTC-3)

Composition publishes one governed MCP endpoint, `/v1/mcp`, over several upstream MCP servers. A client configures a single server and sees, under one session, every tool its gateway key may run on the servers the operator listed. It extends the [MCP ingress](/docs/features/mcp-ingress/): same protocol revision (2025-11-25), transport, sessions, errors and [execution trail](/docs/features/mcp-execution-audit/).

| Flag | Default | What it turns on |
| --- | --- | --- |
| `mcp_composition` | `false` | `POST`, `GET`, `DELETE /v1/mcp` and its protected-resource metadata; requires `mcp_ingress`; a public resource right (`mcp_composition`) under plan entitlements, besides `mcp_execution` and `mcp_ingress` |

## What is composed

Only the servers listed in `mcp_execution.composition.servers` are composed, boot (YAML) or console-approved. Listing a server grants nothing: each still needs its execution trust and per-tool grants, and composition applies exactly those, server by server. A key therefore sees in `/v1/mcp` the same tools it would see on each server's own endpoint, and nothing more: a server the key cannot use contributes no tool and is not named. `initialize` answers 404 when the key can use none of the listed servers.

## Names

A composed tool is named `<server>__<tool>`, for example `weather__forecast`. The server part never contains `__` (configuration refuses such an ID), so a name splits at its first `__` without ambiguity, even when the tool's own name contains `__`. A name longer than 128 characters once namespaced is never shortened, which could collide: it is left out and reported. Two identical composed names (only possible through a misconfiguration) are both left out. Each tool also carries its provenance in `_meta`:

```json
{
  "name": "weather__forecast",
  "description": "Forecast for a city",
  "inputSchema": {"type": "object", "properties": {"city": {"type": "string"}}},
  "_meta": {"ai-gateway/server": "weather", "ai-gateway/tool": "forecast"}
}
```

With `mcp_composition_snapshot` (off by default; requires `mcp_composition` and `mcp_connect`), a tool of a [console-managed server](/docs/features/mcp-discovery-history/) also carries `"ai-gateway/snapshot_id"`: the reviewed discovery snapshot its approval pins, read right after that server's discovery, within the listing's 30-second budget, so a re-approval in between can label the page with the newer snapshot. A client can compare it across listings to notice a re-approval. Servers declared in YAML have no snapshot and carry no field.

## Discovery

`tools/list` discovers the listed servers one at a time, each through its own per-server path and bounded by `discovery_timeout_seconds`, the whole listing within 30 seconds. A composed listing therefore holds at most one of the gateway's bounded MCP operation slots and never starves other tenants. Discovery is partial by design:

- a server that fails, times out or is not reached within the 30-second budget is left out of that page and named in `_meta["ai-gateway/unavailable_servers"]`;
- tools left out by length or duplication are named in `_meta["ai-gateway/omitted_tools"]`;
- a console-managed tool whose schema drifted since approval stays quarantined, as on its own endpoint.

Tools are sorted by name and paged by `page_size`; `nextCursor` is bound to the session (another session's cursor is refused with -32602). Each page discovers again, so a page reflects grants and quarantine at that moment.

## Calls

`tools/call` takes the composed name, finds the server prefix in the configured list and runs exactly the per-server call: that server's grants, credentials, schema validation and execution record, sent once and never retried. A name with an unlisted server, a listed server the key cannot use, an unknown tool, a tool the key may not run or a composed name over 128 characters answers -32602 and nothing is sent; the first two answer identically, so the list cannot be probed. An `Idempotency-Key` header applies as on the REST route.

## Configuration

Boot configuration under `mcp_execution.composition`, read-only in `GET /api/v1/admin/config` (`mcp_execution.composition`; it was a top-level `mcp_composition`) and the console, which shows `page_size` and `discovery_timeout_seconds`. A restart applies a change.

```yaml
features:
  mcp_ingress: true
  mcp_composition: true
mcp_execution:
  composition:
    servers: [weather, tickets]   # explicit; empty composes nothing
    discovery_timeout_seconds: 10 # 1-30
    page_size: 100                # 1-500
```

| Field | Default | Bounds | Meaning |
| --- | --- | --- | --- |
| `servers` | `[]` | at most 64 unique IDs of `[A-Za-z0-9_.-]{1,64}`, no `__`, no trailing `_` | Servers composed behind `/v1/mcp` |
| `discovery_timeout_seconds` | `10` | 1-30 | Bound of one server's discovery |
| `page_size` | `100` | 1-500 | Tools per `tools/list` page |

Some clients read only the first page of `tools/list`; keep `page_size` above the composed tool count for them.

## Console

**MCP registry → Connect an MCP client** offers **All approved servers (composed)** with the endpoint, the composed servers and a client configuration with a key placeholder.

## Upgrade

No migration: composed sessions are ingress sessions without a server. Turn the flag on after `mcp_ingress`.
