MCP gateway
Agents reach far more than models: through the Model Context Protocol they read repositories, tickets, files and databases, and every tool result goes straight back into the prompt. PromptGate puts those servers behind one MCP endpoint, so an agent needs one entry in its config and every tool call is logged, rate-limited and inspected like model traffic.
agent ──▶ PromptGate /mcp ──┬──▶ github (remote, Streamable HTTP) ├──▶ linear (remote, Streamable HTTP) └──▶ files (local program over stdio)Tools are renamed <server>__<tool> — github__create_issue,
files__read_file — so names from different servers never clash.
What the MCP gateway can do
Section titled “What the MCP gateway can do”| feature | does | |
|---|---|---|
| one endpoint for every server | remote servers (Streamable HTTP) and local programs (stdio) behind /mcp; lists fetched in parallel and cached |
servers |
| moving agents | mcp import takes over the servers of Claude Code, Cursor, VS Code and Claude Desktop; mcp setup points the agent at the gateway |
moving agents |
| tool allowlists | per server tools.allow / deny; per key, servers or single tools |
below |
| read, write, delete | per key and server or tool: an agent that should only read sees and calls only the read tools | agent permissions |
| approvals | approve: delete: tool calls that delete wait until the agent’s user says yes in their client |
approvals |
| tool search | mcp.tool_search: two tools — find and call — instead of hundreds of definitions in every prompt |
below |
| limits | per server or per tool, shared by every key — protects the server | below |
| guardrails in both directions | tool arguments, results, prompts, resources — and tool definitions (“tool poisoning”) | below |
| OAuth | tokens for remote servers, renewed by PromptGate, also discovered from the server (oauth: auto) |
OAuth |
| endpoint tools | every AI Gateway endpoint is a tool, endpoint__<slug>, called through the model pipeline |
endpoint tools |
| PromptGate’s own tools | stats, logs, config, keys, endpoints, limits, budgets — for keys with control: read or write |
control tools |
| every protocol version | 2026-07-28 (stateless) and the earlier session versions, on both sides, mixed freely | protocol versions |
| local programs | started on demand with a clean environment; the whole process tree stopped; restarted after crashes | local programs |
| logs, stats, metrics | every call a log row; per-tool p50 and p95; Prometheus | below |
Everything in one config:
mcp: servers: github: # remote server url: https://api.githubcopilot.com/mcp/ headers: { Authorization: "Bearer ${GITHUB_TOKEN}" } timeout: 30s linear: url: https://mcp.linear.app/mcp oauth: auto # token discovered from the server tools: { allow: [list_issues, get_issue] } # only these files: # local program command: npx args: [-y, "@modelcontextprotocol/server-filesystem", /srv/docs] env: { NODE_OPTIONS: --max-old-space-size=256 } idle_stop: 10mkeys: - name: claude-code # or: promptgate keys create … --mcp … hash: sha256:… mcp: [github, files, linear/get_issue] # servers or single tools; empty = all access: { "*": write, mcp:github: read } # read/write/full; github: read-only tools only control: read # PromptGate's own tools, read-onlylimits: mcp: files: 120/m # per server … github/create_issue: 10/h # … or per tool "*": 600/m # every server without its own entryguardrails: secrets: { action: block } # global rules cover tool calls too mcp: files: # reads untrusted documents prompt_injection: { roles: [user, tool] } pii: { action: redact }Connecting agents
Section titled “Connecting agents”Agents connect to http://127.0.0.1:7878/mcp (surfaces.mcp_gateway.mount)
with a pg_ key. The MCP gateway accepts only pg_ keys, in every
auth.mode — there is no provider key to pass through — so create one
first: promptgate keys create claude-code.
# Claude Codeclaude mcp add --transport http promptgate http://127.0.0.1:7878/mcp \ --header "Authorization: Bearer pg_…"# Codex — ~/.codex/config.toml[mcp_servers.promptgate]url = "http://127.0.0.1:7878/mcp"bearer_token_env_var = "PROMPTGATE_KEY"// Cursor — .cursor/mcp.json{ "mcpServers": { "promptgate": { "url": "http://127.0.0.1:7878/mcp", "headers": { "Authorization": "Bearer pg_…" } } } }promptgate mcp setup claude-code|cursor|codex|claude-desktop writes
these entries for you, and promptgate mcp import takes the agents’
own servers over — see moving agents.
What agents get:
- Tools and prompts of every server the key may use, renamed
<server>__<name>. A call goes to the server under the tool’s own name. A tool the key ortools.allow/denydoesn’t allow is answered like one that doesn’t exist. - Resources keep the servers’ own URIs; a read goes to the server that lists the resource, else to the one whose resource template matches it.
- Lists are fetched from all servers in parallel and cached for
mcp.list_ttl(or a server’s shorterttlMs); a reload starts changed servers with an empty cache. A server that fails is left out of the list and named in its_meta(dev.promptgate/unavailable) — the rest keep working. The merged list comes in one page. - Progress of a long call is relayed as it arrives when the agent
asked for it (
progressToken) and acceptstext/event-stream. - Cancelling —
notifications/cancelled, or closing the request — cancels the call at the server too. - Sessions (legacy agents) live in memory and are bound to the key that opened them; after a restart, or a day unused, the agent gets 404 and opens a new one, as the protocol intends.
- Browsers: a request with an
Originheader must come from the gateway’s own host or a page on this machine (DNS rebinding).
Tool search
Section titled “Tool search”Every tool definition the agent lists goes into every prompt. Ten
servers are easily hundreds of tools and tens of thousands of tokens —
paid on each turn, and some agents refuse more than a few dozen tools.
With mcp.tool_search, agents list two tools instead:
| tool | does |
|---|---|
promptgate__find_tools |
{query, limit} — the tools the key may use that match best by name and description (default 8, at most 25), with their input schemas |
promptgate__call_tool |
{name, arguments} — calls the tool it names, exactly as a direct call: allowlists, access levels and approvals, guardrails, limits, log rows under the tool’s own name |
mcp.tool_search |
lists |
|---|---|
off (default) |
every tool |
on |
the two search tools |
auto |
the two search tools when the key may use more than 40 tools, else every tool |
Ten servers of twenty small tools list 27,961 bytes of definitions;
with tool_search: on, 813, and a search returns about 1 KB. Searching
runs in PromptGate over the cached lists, without a model and without
calling a server. Tools the key may not use are never found.
Keys, limits and guardrails
Section titled “Keys, limits and guardrails”Keys name the servers or single tools they may use (keys[].mcp, or
promptgate keys create … --mcp github --mcp linear/get_issue); limits
and guardrails take a server or server/tool — see the
example above.
Limits on MCP servers protect the server: they count calls from every
key together, like provider limits. A call over one gets JSON-RPC error
-32029 with retryAfter (seconds) in its data; the server never sees
it. A tool limit and its server’s limit are both taken, or neither.
Guardrails
Section titled “Guardrails”The guardrails inspect MCP traffic in both directions, with the same guards and settings as model traffic:
- What the agent sends — a tool’s or prompt’s arguments — counts as
content of role
assistant: the model wrote it. Request rules (ip_allowlist,time_window,length) apply too, also toresources/read. - What a server returns — tool results (text, embedded resources,
structuredContent), prompts and resources — counts as roletool. Binary data, media types and_metaare not read.
So a guard covers MCP exactly where it covers those roles in model
requests. secrets and pii read every role and so both directions out
of the box. prompt_injection and keywords read user content by
default; instructions planted in tool results — the main risk of MCP —
are caught once you add tool (roles: [user, tool], as for files
in the example above), or
roles: { user: block, tool: mask } — the recommended protection — to
mask them in results instead of failing the call.
| action | arguments | results |
|---|---|---|
block |
JSON-RPC error -32001; the server is never called |
a tool result with isError and the reason (the model learns why); for prompts and resources error -32001 |
mask |
the server gets [EMAIL] |
the agent gets [EMAIL] |
redact |
the server gets [[EMAIL_001]]; the agent gets the original back wherever the result repeats it — also in Mcp-Param-* headers the server sees only the token |
like mask, with tokens |
log |
logged, passed on | logged, passed on |
Results are inspected whole; they are bounded by mcp.max_result_bytes
anyway. Levels: global → guardrails.mcp.<server> → the key’s rules.
The web UI’s What applies page shows the merged rules for a key and an
MCP server. Findings are in the request log’s guard column and in
promptgate_guardrail_findings_total.
Tool definitions count as role tool too: descriptions of tools,
prompts and resources — and of their parameters — go into the model’s
prompt, and instructions planted there (“tool poisoning”) meet the same
guards. A blocked definition is left out of the list (and logged), a
masked one is listed masked. Each list is inspected once per guard set
and cached with it. Progress messages are not inspected.
Logs, stats and metrics
Section titled “Logs, stats and metrics”Every MCP request except ping and server/discover is a row in the
request log, with surface mcp: the method as route, the server as
provider and the tool, prompt or resource as model; cost 0. A tool that
answered with isError is logged with status 200 and “the tool reported
an error”; a server that couldn’t be reached with 502, a call over a
limit with 429, an agent that gave up with 499.
promptgate logs --surface mcp # MCP requests only (ai: model requests only)promptgate stats --by tool # per server/tool: requests, errors, p50, p95promptgate stats --surface mcp --by keyMCP requests have their own minute totals, so stats, budgets, cost and
anomalies of model traffic never count tool calls. The
console shows them with mcp instead of sse. Metrics:
promptgate_mcp_requests_total, promptgate_mcp_request_duration_seconds
and promptgate_mcp_server_up — see metrics.
Command line
Section titled “Command line”promptgate mcp connects to the servers directly — local programs are
started and stopped again — so it works without a running gateway.
| command | description |
|---|---|
mcp servers |
every server with transport, target, status, protocol version and tool count; exit 1 if one fails; --timeout, --json |
mcp tools [server] |
the tools agents see, <server>__<tool> and the first line of the description, after tools.allow/deny, endpoint tools included (mcp tools endpoint lists only them); --json prints the full definitions |
mcp import [file…] |
the servers of Claude Code, Claude Desktop, Cursor and VS Code configs as mcp.servers, secrets as ${ENV}; --write, --force — see moving agents |
mcp setup <agent> |
the entry that points claude-code, cursor, codex or claude-desktop at the gateway; --write, --global, --create-key |
mcp connect |
stdio shim to the running gateway, for agents that only start programs |
mcp call <server__tool> |
calls one tool through the gateway’s routing and prints the result — text as is, other content named; --args '{"q":"x"}', --json, --timeout (5m); progress goes to stderr; exit 1 when the tool reports an error |
$ promptgate mcp call files__read_text_file --args '{"path":"/srv/docs/README.md"}'# PromptGate…
$ promptgate mcp serversNAME TRANSPORT TARGET STATUS PROTOCOL TOOLSfiles stdio npx -y @modelcontextprotocol/server-file… ok 2025-06-18 (legacy) 14github http https://api.githubcopilot.com/mcp/ ok 2026-07-28 (modern) 51