---
title: "How to connect Grok to your MCP server | FluxOS MCP Blog"
description: "Three ways to connect Grok to a server published on FluxOS MCP: the xAI API, Grok in the terminal, and the app's connectors. With examples."
url: "https://www.fluxosmcp.com/en/blog/how-to-connect-grok-to-your-mcp-server"
lang: "en-US"
---

[Blog](https://www.fluxosmcp.com/en/blog) · Nov 25, 2026 · FluxOS MCP Team

# How to connect Grok to your MCP server

[Leia este artigo em português](https://www.fluxosmcp.com/blog/como-ligar-o-grok-ao-seu-servidor-mcp)

An MCP server does not belong to one assistant. The same address that serves Claude serves Grok, with nothing changed in FluxOS MCP: the only thing that changes is the side you connect from.

Grok has three ways in. Two accept the FluxOS MCP key with clear documentation. The third, the app, has an uncertainty worth knowing about up front.

## Before you start: address and key

You need two things, and both are in FluxOS MCP:

- **The server address.** On the **Conexão** (Connection) tab of the published server (or, for the client, on the **Ferramentas e conexão** (Tools and connection) page of the portal). It looks like `https://SEU-DOMINIO/mcp/dados-publicos`, where `SEU-DOMINIO` is your domain.
- **An access key.** Created on the client’s **Chaves** (Keys) tab. It starts with `amk_` and is shown only once.

In the examples, the server is `dados-publicos` from the [OpenAPI tutorial](https://www.fluxosmcp.com/en/blog/tutorial-postal-codes-holidays-and-rates-in-your-ai-assistant-with-openapi), with tools for CEP (Brazilian postal code) lookups, holidays, and rates. Swap in your own.

FluxOS MCP speaks **Streamable HTTP** and authenticates **by key only**, sent in the `Authorization: Bearer` header. There is no OAuth. That determines which assistants can connect, as you will see.

## Path 1: the xAI API

For anyone building a product with Grok. The API has a tool of type `mcp`: you pass the server address in the request and xAI handles the connection.

```bash
curl https://api.x.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
  "model": "grok-4.7",
  "input": [
    {
      "role": "user",
      "content": "What is the address for CEP 01001-000?"
    }
  ],
  "tools": [
    {
      "type": "mcp",
      "server_url": "https://SEU-DOMINIO/mcp/dados-publicos",
      "server_label": "dados-publicos",
      "server_description": "Looks up Brazilian postal codes (CEP), national holidays, and official rates for Brazil.",
      "headers": { "Authorization": "Bearer amk_SUA_CHAVE" }
    }
  ]
}'

```

Notice that there are **two different keys** in the same request, and they are easy to mix up:

- `$XAI_API_KEY`, in the request header, is your xAI key.
- `amk_SUA_CHAVE`, inside `tools`, is the FluxOS MCP key, which xAI passes along to your server.

The tool’s fields:

- `server_url`: the server address. xAI accepts Streamable HTTP, which is the transport FluxOS MCP uses.
- `server_label`: a label for the server. Grok uses it as a prefix on the tool names.
- `server_description`: optional, but it helps Grok understand what the server is for.
- `headers`: extra headers sent to the server. This is where the key goes.
- `allowed_tools`: optional. Lists the tools that are allowed. When empty, all of them are.

There is also an `authorization` field, described as “a token placed in the Authorization header.” We prefer `headers` in the example because there the value is written out in full, including `Bearer`, without depending on how the field builds the header.

### With the xAI SDK, in Python

```python
import os

from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import mcp

client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
    model="grok-4.7",
    tools=[
        mcp(
            server_url="https://SEU-DOMINIO/mcp/dados-publicos",
            server_label="dados-publicos",
            extra_headers={"Authorization": f"Bearer {os.getenv('FLUXOS_MCP_KEY')}"},
            allowed_tool_names=["consultar_cep", "listar_feriados"],
        ),
    ],
)

chat.append(user("Which 2026 national holidays in Brazil fall on a Monday?"))
print(chat.sample().content)

```

In the SDK the names change slightly: `headers` becomes `extra_headers` and `allowed_tools` becomes `allowed_tool_names`.

### Allow only a few tools

Without `allowed_tools`, the definition of **every** tool on the server goes into the model’s context. xAI itself recommends restricting them, for two reasons: less context spent and less risk. A server with twenty tools, of which the application uses two, should allow two.

## Path 2: Grok in the terminal

Grok has a command-line tool with MCP support, and the command is almost identical to the one for Claude Code:

```bash
export FLUXOS_MCP_KEY="amk_SUA_CHAVE"

grok mcp add --transport http dados-publicos https://SEU-DOMINIO/mcp/dados-publicos \
  --header "Authorization: Bearer ${FLUXOS_MCP_KEY}"

```

To verify:

```bash
grok mcp list
grok mcp doctor dados-publicos

```

`doctor` diagnoses configuration and connectivity, and it is the first place to look when something fails. Inside Grok, `/mcps` opens the list of servers.

The tools show up with the server name in front: `dados-publicos__consultar_cep`.

To have the server travel with the repository, use `--scope project`: the configuration goes into `.grok/config.toml` in the current folder. As with Claude Code, **keep the key in an environment variable** and never in the file. Watch the quotes: inside double quotes, it is your shell that replaces `${FLUXOS_MCP_KEY}` with the value before the command runs, and the key ends up written in the configuration. For a shared file, use single quotes in `--header`, or edit the file and leave `${FLUXOS_MCP_KEY}` in place of the key: Grok does the substitution when it loads the file.

A useful detail if you use both: Grok in the terminal also reads Claude’s MCP configuration, including the project’s `.mcp.json`. If you already set up the server for [Claude Code](https://www.fluxosmcp.com/en/blog/how-to-connect-claude-code-to-your-mcp-server), it may already be there.

## Path 3: the Grok app

The app has **custom connectors**. The documented path:

1. Open `grok.com/connectors`.
2. Click **New Connector** and choose **Custom**.
3. Enter the server address and complete the authentication it asks for.

The uncertainty is in step 3\. xAI’s documentation says “complete the required authentication” and describes the built-in connectors as OAuth-based, but it **does not say whether a custom connector accepts a fixed key** in the header, which is what FluxOS MCP uses.

We have not tested it. Before you count on this path, open the form and see whether there is a field for a token or a header. If OAuth is the only option, the app does not connect to a FluxOS MCP server today. Paths 1 and 2 do.

## When it won’t connect

The server responds with a code that tells you why:

- **401:** the key is missing, wrong, revoked, or expired. Check that you copied the whole key.
- **402:** the client’s subscription is awaiting payment.
- **403:** the client’s subscription is suspended or canceled.
- **429:** the key went over its per-minute or per-day limit. The message says how many seconds to wait before trying again.

If a tool does not show up, check that the server is **published** and that the tool is among those allowed for that key.

## Next steps

Got Grok connected? The same server works with [Claude Code](https://www.fluxosmcp.com/en/blog/how-to-connect-claude-code-to-your-mcp-server), [the Claude app and API](https://www.fluxosmcp.com/en/blog/how-to-use-your-mcp-server-with-claude-app-and-api), and [Codex and the OpenAI API](https://www.fluxosmcp.com/en/blog/how-to-connect-chatgpt-and-codex-to-your-mcp-server). Use a different key for each one: that way FluxOS MCP shows usage separately per assistant.
