> 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/framework-examples/grok-bot.md). Agents can also search and read this documentation through its [MCP server](https://docs.metamynd.ai/~gitbook/mcp).

# Grok Bot

{% hint style="info" %}
**Developer preview.** Remote mode and its Grok Bot setup are new. The gateway is tested in CI with real MCP clients, but Grok Bot's own limits (call timeout, how many tools it shows) aren't documented by xAI. If something behaves differently in your account, please tell us.&#x20;
{% endhint %}

Give Grok Bot tools that run as one of your agents, under that agent's mandate. Every tool call is checked by MetaMynd first: allowed calls run, the rest are refused or wait for your approval, and each one appears in the agent's activity.

This uses the <a href="https://docs.metamynd.ai/sdks/mcp-gateway" target="_blank">MetaMynd MCP gateway</a> in **remote mode** (version 0.3.0 or later). You run it on your own server, and Grok Bot connects to it over HTTPS.

<figure><img src="https://3418616817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUIcKxsedP2fzCn1A9CVQ%2Fuploads%2FKS0vN9SvTVeTLB0AHIb6%2Fmetamynd-grok-bot.png?alt=media&amp;token=c1bd603f-ec4b-43a8-8aec-80ac18fb45e3" alt=""><figcaption></figcaption></figure>

#### Why remote, not a Command connector <a href="#user-content-why-remote-not-a-command-connector" id="user-content-why-remote-not-a-command-connector"></a>

Grok Bot can add an MCP server in two ways: a **Command** that runs on the Bot's own cloud computer, or a **Remote HTTPS** URL.

A Command connector would put the gateway, and the tools' credentials and the agent's key with it, on the Bot's computer. That computer is shared by all your Bots, and the Bot's shell can run as root there. So the AI could read the credentials and call the service directly, without MetaMynd.

In **remote mode** the credentials and the agent's key stay on your server. The Bot's computer holds only an access token, which you can revoke at any time.

| Setup                                             | What MetaMynd can say                                                                                                                                                      |
| ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Remote HTTPS to your own gateway** (this guide) | Tool calls through the gateway are decided by MetaMynd and recorded. The AI can't use those tools another way, provided their credentials exist nowhere else it can reach. |
| Command connector on the Bot's computer           | Calls through the gateway are decided and recorded, but the AI can read the credentials and go around it. Not recommended.                                                 |

MetaMynd governs the tools you put behind the gateway. It does not control Grok Bot's browser, shell, web fetch or built-in connectors.

#### Before you start <a href="#user-content-before-you-start" id="user-content-before-you-start"></a>

* An agent with a mandate that grants the actions its tools need. 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> for how each tool runs under its own action.
* The agent's key, and its `agent.metamynd.json` file.
* A server you control, with Node 22 or later or Docker, reachable by Grok Bot over HTTPS. A server on a private network, or behind a private certificate authority, works too: Grok Bot asks you to approve it.
* An account with each service you want to connect, where you can create a credential with only the permissions its tools need.

#### 1. Prepare the gateway's folder <a href="#user-content-1-prepare-the-gateways-folder" id="user-content-1-prepare-the-gateways-folder"></a>

Write `mcp-gateway.json` as described on the <a href="https://docs.metamynd.ai/sdks/mcp-gateway" target="_blank">mcp-gateway</a> page, then draft and review the mapping:

{% code overflow="wrap" %}

```
npx -y @metamynd/mcp-gateway@0.3.0 init --config mcp-gateway.json
```

{% endcode %}

Review every drafted tool, and remove its `"review": true` flag once you've checked it. A server usually has no OS keychain, so reference each credential as `${VAR}` and pass the agent's key in the `MCPGW_AGENT_KEY` environment variable.

#### 2. Create an access token for Grok Bot <a href="#user-content-2-create-an-access-token-for-grok-bot" id="user-content-2-create-an-access-token-for-grok-bot"></a>

{% code overflow="wrap" %}

```
npx -y @metamynd/mcp-gateway@0.3.0 token create --label "grok-bot" --state-dir /srv/metamynd/state
```

{% endcode %}

The token (`mmgw_…`) is printed once. Only a hash of it is kept. Put it straight into Grok Bot (step 4), never into a chat or a prompt.

#### 3. Start the gateway <a href="#user-content-3-start-the-gateway" id="user-content-3-start-the-gateway"></a>

With TLS in the gateway itself:

```
npx -y @metamynd/mcp-gateway@0.3.0 serve --http --host 0.0.0.0 --port 8787 \  --tls-cert cert.pem --tls-key key.pem \  --config mcp-gateway.json --state-dir /srv/metamynd/state
```

Or behind a TLS-terminating proxy on the same host (nginx, Caddy, a load balancer):

```
npx -y @metamynd/mcp-gateway@0.3.0 serve --http --host 127.0.0.1 --port 8787 --behind-tls-proxy \  --config mcp-gateway.json --state-dir /srv/metamynd/state
```

The gateway refuses to serve plain HTTP on a public address, and refuses to start without an access token. A <a href="https://github.com/Metamynd/metamynd-mcp-gateway/blob/main/Dockerfile" target="_blank">Dockerfile</a> is in the repository; see <a href="https://github.com/Metamynd/metamynd-mcp-gateway/blob/main/docs/remote.md" target="_blank">docs/remote.md</a> for running it in Docker.

#### 4. Add it to Grok Bot <a href="#user-content-4-add-it-to-grok-bot" id="user-content-4-add-it-to-grok-bot"></a>

In Grok Bot: **Add a custom connector → Remote HTTPS**.

* **Server URL:** `https://<your server>/mcp`
* **HTTP header:** `Authorization: Bearer <the token from step 2>`

If your team's admin restricts MCP servers or network access, the server must be allowed there. With **Apply to MCP servers** on, your server's host must also be on the team's network allow-list.

#### 5. Remove any direct connection to the same services <a href="#user-content-5-remove-any-direct-connection-to-the-same-services" id="user-content-5-remove-any-direct-connection-to-the-same-services"></a>

If Grok Bot can reach the same service another way (its own connector for it, or a credential on the Bot's computer), remove it. While that's there, the AI can use the service without MetaMynd. Give each service's credential only the permissions its tools need: that is the outer fence.

#### Using it <a href="#user-content-using-it" id="user-content-using-it"></a>

Ask Grok Bot to do something that needs the tools.

| What happens                                 | What it means                                                                                                                                                               |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The tool runs                                | MetaMynd allowed it. It's in the agent's governance activity.                                                                                                               |
| "MetaMynd refused this call (`REASON`)"      | Not allowed by the mandate or a rule. See the <a href="https://docs.metamynd.ai/agent-protocol/reason-code-registry" target="_blank">Reason Code Registry</a>. Nothing ran. |
| "MetaMynd is holding this call for approval" | A rule needs a person. Approve it in the dashboard, then ask again with the same request: it runs once.                                                                     |
| "Not sent: argument(s) not allowed"          | The AI sent something the tool's review doesn't allow. Nothing was sent.                                                                                                    |

#### One agent, every Bot <a href="#user-content-one-agent-every-bot" id="user-content-one-agent-every-bot"></a>

Grok Bot sends no identity of its own: each Bot acts as you. Every Bot using this connector is therefore the same MetaMynd agent, with the same mandate and the same activity log. To tell two Bots apart, run two gateways, each with its own agent and its own token.

#### Revoke access <a href="#user-content-revoke-access" id="user-content-revoke-access"></a>

```
npx -y @metamynd/mcp-gateway@0.3.0 token list --state-dir /srv/metamynd/statenpx -y @metamynd/mcp-gateway@0.3.0 token revoke <id> --state-dir /srv/metamynd/state
```

The gateway refuses the token from its next request; no restart is needed. To stop the agent everywhere at once, contain it on its page in the dashboard.

#### Troubleshooting <a href="#user-content-troubleshooting" id="user-content-troubleshooting"></a>

* **Grok Bot can't connect, or gets `401`.** Check the header is exactly `Authorization: Bearer mmgw_…` and that the token isn't revoked (`token list`).
* **`429 too many failed sign-ins`.** Too many requests with a wrong token came from one address. Wait a minute and fix the header.
* **`403 origin not allowed`.** The request came from a browser page. Grok Bot's connector doesn't send one; if you call the gateway from a web app of your own, add its origin with `--allowed-origin`.
* **The gateway won't start: "refusing to serve plain HTTP".** Give it a certificate, or put it behind a TLS proxy and pass `--behind-tls-proxy`.
* **Every call is refused with `GATE_UNREACHABLE`.** Your server can't reach MetaMynd. Nothing runs until it can.

<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/framework-examples/grok-bot.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.
