> For the complete documentation index, see [llms.txt](https://docs.metamynd.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metamynd.ai/sdks/mcp-gateway.md). Agents can also search and read this documentation through its [MCP server](https://docs.metamynd.ai/~gitbook/mcp).

# mcp-gateway

`@metamynd/mcp-gateway` puts any AI app that uses MCP tools under MetaMynd governance **without changing any code**: Claude Desktop, Claude Code, Cursor, VS Code, the OpenAI Agents SDK, LangChain / LangGraph, Grok Bot (through remote mode, below) and any other MCP client. The app sees one MCP server, `metamynd`; behind it, every tool call is checked against the agent's mandate before the real tool runs.

{% code overflow="wrap" %}

```
npx -y @metamynd/mcp-gateway@<version> --config mcp-gateway.json
```

{% endcode %}

* **Runtime:** Node ≥ 22. Built on the MCP TypeScript SDK v2 and <a href="https://docs.metamynd.ai/sdks/agentsafe-guard-agent-side" target="_blank">agentsafe-guard</a>.
* **Exports:** the `mcp-gateway` command; `./catalog`, `./extension` and `./hosts` for integrators (typed).
* **Source:** <a href="https://github.com/Metamynd/metamynd-mcp-gateway" target="_blank">Metamynd/metamynd-mcp-gateway</a> (MIT) · **npm:** <a href="https://www.npmjs.com/package/@metamynd/mcp-gateway" target="_blank">@metamynd/mcp-gateway</a>, published with provenance.

Most owners never run it by hand: **Connect to an AI app** on the agent's page in the dashboard builds everything. See <a href="https://docs.metamynd.ai/guides/connect-an-agent-to-an-ai-app" target="_blank">Connect an Agent to an AI App</a>.

#### How it works <a href="#user-content-how-it-works" id="user-content-how-it-works"></a>

{% code overflow="wrap" %}

```
 AI app (Claude Desktop, Cursor, …) ──MCP──▶ mcp-gateway ──MCP──▶ the real tools (Notion, HubSpot, …)                                                 │                  ▲ their credentials live here only                                                 └──▶ MetaMynd: allow · refuse · hold for a person
```

{% endcode %}

The gateway is an MCP **server** to the app and an MCP **client** to each upstream server. To MetaMynd it is the agent: it signs with the agent's key and makes the same authorize, capture and void calls as `guardTool`. For each tool call:

1. **Check the arguments.** Only the reviewed `allowedArgs` are sent; anything else is refused before MetaMynd is asked (`Not sent: …`).
2. **Authorize** with the tool's action, its value fields (amount, currency, merchant) for a tool that moves money, the reviewed context (e.g. `riskLevel`), and the complete arguments as the payload, so the decision is bound to exactly these arguments.
3. **On allow,** call the real tool, then capture the hold (at 0 for a read). A call the upstream rejects before running is voided.
4. **On a refusal,** answer with the reason code; the tool is never called.
5. **On escalate,** answer *held for approval* at once and remember the request. Once a person approves it, the same call made again runs exactly once.

Refusals and holds are tool results with `isError: true`, so every app shows them to the model, which explains them to the user. If MetaMynd can't be reached, the call is refused (`GATE_UNREACHABLE`); the tool is not called.

#### What the app sees <a href="#user-content-what-the-app-sees" id="user-content-what-the-app-sees"></a>

* Tools are named `<upstream>__<tool>` (at most 48 characters), so tools from different servers never collide.
* **Every listed tool is governed.** A tool without a reviewed mapping is not listed; there is no "allow ungoverned" switch.
* Each description gains one line: *Governed by MetaMynd: may be refused or held for approval.*
* Apps decide when to ask the user from MCP hints. The gateway drops the upstream's own hints (they are its claims about itself) and sets them from the reviewed `effect`: `read` → read-only; `destructive` → destructive; no effect → no hint, so the app stays cautious.
* A tool whose definition changed since it was reviewed is withheld until it is reviewed again (its `schemaHash` no longer matches).

#### Configuration: `mcp-gateway.json` <a href="#user-content-configuration-mcp-gatewayjson" id="user-content-configuration-mcp-gatewayjson"></a>

```
{  "agentConfig": "./agent.metamynd.json",        // the agent's identity (no key in it)  "agentKey": "keychain:mm-docs-helper-agent-key", // where the key comes from: keychain:<name> or ${VAR}, never the key  "upstreams": {    "notion": {      "command": "npx", "args": ["-y", "@notionhq/notion-mcp-server@2.5.2"],      "env": { "NOTION_TOKEN": "keychain:mm-docs-helper-notion-notion-token" }    }  },  "tools": {    "notion.API-post-search": {      "action": "notion-read",                    // the mandate action this tool runs under      "effect": "read",                           // read | write | destructive (the hint apps get)      "allowedArgs": ["query", "sort", "filter", "start_cursor", "page_size"],      "context": { "riskLevel": "low" },      "schemaHash": "sha256:…"                    // the reviewed tool definition    }  },  "escalationWaitMs": 0                           // optional: wait up to 30 s for a person's decision}
```

| Field                     | Meaning                                                                                                                                                                                                                                                   |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `agentConfig`             | The agent file (`agent.metamynd.json`), relative to this file.                                                                                                                                                                                            |
| `agentKey`                | Optional. Where the agent's key comes from when an app starts the gateway from a folder: `keychain:<name>` (the OS keychain) or `${VAR}`. A key written here is refused. The Claude Desktop extension passes its key another way, so it doesn't use this. |
| `upstreams.<name>`        | A local server (`command`, `args`, `env`) or a remote one (`url`, `headers`). **A credential is required**: the gateway holds it, so the AI can't use the tool without MetaMynd. Values are references only: `keychain:<name>` or `${VAR}`.               |
| `tools.<upstream>.<tool>` | `action` (required), value fields `amount` / `currency` / `merchant` (argument names; dotted for nested ones) for a tool that moves money, `allowedArgs`, `effect`, `context`, `schemaHash`, and `onToolError: "void"` for a tool that is safe to retry.  |
| `escalationWaitMs`        | 0 to 30000. Apps give up on a tool call after about a minute, so the gateway never waits longer.                                                                                                                                                          |

The gateway refuses to start if any reference can't be resolved, if a tool is still marked `"review": true`, or if anything else in the file is wrong, and lists every problem at once.

#### Commands <a href="#user-content-commands" id="user-content-commands"></a>

```
mcp-gateway --config mcp-gateway.json                    # run it for an app, over stdiomcp-gateway init --config mcp-gateway.json               # draft a mapping for every upstream toolmcp-gateway secret set <name>                            # store a credential in the OS keychain (input hidden)mcp-gateway secret check <name>                          # say whether it's there (never prints it)mcp-gateway config --host cursor --config mcp-gateway.json   # the snippet that adds it to an appmcp-gateway extension --config mcp-gateway.json          # build a Claude Desktop extension (.mcpb)mcp-gateway token create --label grok-bot                # an access token for remote mode (shown once)mcp-gateway token list | token revoke <id>               # list, or revoke from the next requestmcp-gateway serve --http --config mcp-gateway.json       # remote mode, over Streamable HTTP (see below)
```

`init` connects to each upstream, lists its tools and drafts a mapping for **every** tool, each marked `"review": true`. A person reviews them, because a server's own hints are only claims (a server could call a payment "read-only"). `config --host` knows Claude Desktop, Claude Code, Cursor, VS Code, the OpenAI Agents SDK (Python and JavaScript) and LangChain / LangGraph, and always pins the gateway's exact version.

#### Remote mode (0.3.0 and later) <a href="#user-content-remote-mode-030-and-later" id="user-content-remote-mode-030-and-later"></a>

Some AI apps can't start a local process; they connect to a URL. Grok Bot's **Remote HTTPS** connectors are one. For these, `serve --http` serves the same governed tools over MCP Streamable HTTP. Governance doesn't change: the same mapping and checks, and every call decided by MetaMynd.

It runs **on your own server**: MetaMynd does not host gateways, and never holds your tools' credentials. Step by step: <a href="https://docs.metamynd.ai/framework-examples/grok-bot" target="_blank">Connect Grok Bot</a>.

| Check        | Behaviour                                                                                                                                                                                          |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Access token | Every request needs `Authorization: Bearer mmgw_…`, one token per app installation. Without a valid, unrevoked token: `401`, and nothing is sent to MetaMynd. Only a hash of each token is stored. |
| TLS          | Plain HTTP only on a loopback address, unless TLS is configured (`--tls-cert`, `--tls-key`) or you say a TLS proxy is in front (`--behind-tls-proxy`).                                             |
| Limits       | 1 MiB per request, 120 requests a minute and 16 at once per token, and a cap on failed sign-ins. A browser `Origin` is refused unless listed with `--allowed-origin`.                              |
| Identity     | Every token on a gateway acts as the same agent. Run one gateway per agent.                                                                                                                        |

Not yet: OAuth sign-in, several agents on one gateway, and passing the signed request on to an upstream that runs <a href="https://docs.metamynd.ai/sdks/agentsafe-mcp-guard-service-side" target="_blank">agentsafe-mcp-guard</a>.

#### The curated catalog <a href="#user-content-the-curated-catalog" id="user-content-the-curated-catalog"></a>

For owners who don't write code, MetaMynd reviews MCP servers tool by tool: <a href="https://github.com/Metamynd/metamynd-mcp-gateway/tree/main/catalog" target="_blank">catalog/</a>. Each entry pins an exact server version, describes every tool in plain language with its action and effect, names the credentials, and says which of the service's own permissions each action needs. CI installs every pinned server and fails if a tool changed, vanished or appeared unreviewed. Today: **Notion**, **HubSpot** and **Brave Search**.

#### Security model <a href="#user-content-security-model" id="user-content-security-model"></a>

| Threat                               | What stops it                                                                                               |
| ------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| The AI reaches the tool another way  | The tool's credential is only in the gateway. Remove any direct connection to the same server from the app. |
| Prompt injection pushes past a limit | MetaMynd decides from the mandate; the model's wording doesn't matter.                                      |
| The AI reads the agent's key         | The key is in the signer daemon or the OS keychain, never in a file the app or its tools can read.          |
| A tool changes after review          | `schemaHash` pins the definition; a changed tool is withheld.                                               |
| Smuggled arguments                   | Only `allowedArgs` are sent; value fields are type-checked; the decision is bound to the exact arguments.   |
| A retry runs twice                   | Authorizations are single-use; an approved held request is claimed once.                                    |
| MetaMynd unreachable                 | Refused, `GATE_UNREACHABLE`; nothing runs.                                                                  |

#### Tested with real clients <a href="#user-content-tested-with-real-clients" id="user-content-tested-with-real-clients"></a>

`npm run conformance` makes the same governed calls (allowed, over the limit, held, smuggled argument) through the **MCP TypeScript SDK**, the **OpenAI Agents SDK** (JavaScript and Python) and **LangChain / LangGraph**, each starting the gateway itself. CI requires identical verdicts from all of them, and that the real tool ran only for the allowed call. Desktop apps are checked by hand before each release.

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.metamynd.ai/sdks/mcp-gateway.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
