Tutorial · AI agents on social media

Grok MCP: connecting a remote server, and what it can post

By Antoine Blanco··8 min read

Grok speaks MCP in three different places, and each one connects a remote server its own way: the connectors page in the Grok app, the grok mcp add command in the CLI, and an mcp entry in the API tools array. Only two of the three handle OAuth. Everything below comes from xAI's own docs, read on November 25, 2026.

Pick the wrong surface and you will spend an afternoon looking for an OAuth flow that is not there.

The three Grok surfaces that speak MCP

Surface How you add a server Auth it handles Good for
Grok app (grok.com) Connectors page, New Connector, Custom OAuth and API keys, in the dialog Chatting with your own tools
grok CLI grok mcp add --transport http <name> <url> OAuth automatically, or a static header Terminal work, repo-scoped servers
Grok API {"type": "mcp", ...} in tools A bearer token you pass yourself Agents and backend jobs

The app and the CLI are for you. The API is for the thing you are building. They do not share configuration, so a server you added in the app is not available to your API calls.

Add a remote MCP server in the Grok app

Three steps, from the connectors doc:

  1. Go to grok.com/connectors.
  2. Click New Connector, then Custom.
  3. Enter the MCP server URL and complete any authentication it asks for.

Grok then discovers the tools your server exposes and uses them in conversation like a built-in connector. Connectors are available to all Grok users; on Business and Enterprise a team admin has to provision the connector in the cloud console first, so on a company account you may not be able to add one yourself.

One hard limit: your server has to be reachable from the public internet. Grok rejects localhost and private ranges such as 127.0.0.1, 10.x.x.x, 172.16.x.x and 192.168.x.x. For a server you are developing locally, xAI's tunneling guide points at ngrok or a Cloudflare quick tunnel, with one warning worth repeating: Cloudflare quick tunnels do not support SSE. If your server still uses the SSE transport, use ngrok. Streamable HTTP works on both.

Free tunnel URLs change on every restart, and Grok has no way to follow that. You remove the connector and add it again with the new URL. For anything you intend to use twice, host the server instead.

Add one in the grok CLI

The CLI is the fastest path, and the only one that does OAuth for you without a browser dialog you have to find:

# Remote server over HTTP, OAuth handled automatically
grok mcp add --transport http plugkit https://api.plugkit.co/mcp

# Or with a static key instead of OAuth
grok mcp add --transport http plugkit https://api.plugkit.co/mcp \
  --header "Authorization: Bearer ${PLUGKIT_API_KEY}"

Tools arrive namespaced as <server>__<tool>, so plugkit__create_post and plugkit__list_accounts. grok mcp list shows what is configured, grok mcp remove <name> deletes one, and grok mcp doctor [name] is the first thing to run when a server will not connect. Both list and doctor take --json.

Servers can also go straight into ~/.grok/config.toml:

[mcp_servers.plugkit]
url = "https://api.plugkit.co/mcp"
headers = { "Authorization" = "Bearer ${PLUGKIT_API_KEY}" }

Grok expands ${VAR} and ${VAR:-default} in url, command, args, env and headers, so the key stays in your environment and never lands in the file. Servers that need OAuth open a browser flow on first use and store tokens in ~/.grok/mcp_credentials.json.

Two details that save time. --scope project writes .grok/config.toml in the current directory, so a server ships with the repo and Grok walks up to the git root collecting them. And Grok reads MCP configuration from ~/.claude.json, .cursor/mcp.json and project .mcp.json files as well, merged below config.toml: if you already configured a server for Claude Code or Cursor, Grok may have it already. grok inspect shows every loaded server and where it came from.

Call one from the Grok API

In the API, a remote MCP server is a tool entry. xAI manages the connection to it on your behalf, in the native SDK, the OpenAI-compatible Responses API and the Speech to Speech API.

from openai import OpenAI

client = OpenAI(api_key=os.getenv("XAI_API_KEY"), base_url="https://api.x.ai/v1")

response = client.responses.create(
    model="grok-4.7",
    input=[{"role": "user", "content": "List my connected social accounts, then draft a post."}],
    tools=[{
        "type": "mcp",
        "server_url": "https://api.plugkit.co/mcp",
        "server_label": "plugkit",
        "authorization": os.environ["PLUGKIT_API_KEY"],
    }],
)

The parameters, from the remote MCP tools doc:

Parameter Required What it does
server_url Yes The server URL. Streaming HTTP and SSE only
server_label Yes Prefix used for tool calls
server_description No Helps the model pick between servers
allowed_tools No Whitelist of tool names. allowed_tool_names in the xAI SDK
authorization No Token set in the Authorization header
headers No Extra headers. extra_headers in the xAI SDK

Two things are not supported in the OpenAI-compatible path: require_approval and connector_id. The first is the one to think about. There is no server-side approval gate, so a write tool the model decides to call gets called. Which brings us to allowed_tools.

Leave it out and every tool definition the server exposes is injected into the model's context. On a social server that is a lot of surface area and a lot of tokens. Pass the three or four you actually want:

"allowed_tools": ["list_accounts", "get_comments", "create_post"]

xAI's own doc gives the same advice for the same two reasons: less context to carry, and a model that cannot reach the tools you did not list. Read-only until you trust it.

What Grok can post once a social server is attached

MCP gives Grok tools, not accounts. To publish to Instagram or LinkedIn, the server behind it has to hold the OAuth tokens, the app review and the per-platform quirks.

PlugKit is one such server: https://api.plugkit.co/mcp, Streamable HTTP, 103 tools on November 25, 2026 per the MCP overview, covering Instagram, Facebook, LinkedIn, TikTok, YouTube, X, WhatsApp and Telegram. The tools Grok would reach for: list_accounts, create_post, get_comments, reply_to_comment, list_conversations, send_message, get_analytics_summary, create_comment_automation.

Worth saying plainly: PlugKit's docs list Grok among the assistants it works with, but ship no Grok setup card, only Claude, ChatGPT, Claude Code, Cursor and VS Code. The commands above are built from xAI's docs, not from a PlugKit walkthrough. They follow the same shape as every other HTTP MCP client, and the server is standards-compliant enough that it advertises its own OAuth metadata. Here is the unauthenticated handshake today:

$ curl -i -X POST https://api.plugkit.co/mcp -d '{"jsonrpc":"2.0","id":1,"method":"initialize",...}'
HTTP/2 401
www-authenticate: Bearer resource_metadata="https://api.plugkit.co/.well-known/oauth-protected-resource",
                  scope="mcp:read mcp:write"
{"error":"Missing credentials. Send `Authorization: Bearer <api key or session token>`.",
 "type":"authentication_error","code":"unauthorized"}

That www-authenticate header is what the CLI's automatic OAuth follows. The API path cannot: it has no OAuth flow, so you pass an API key as authorization and the key has full access with no scopes. If you want Grok reading before it writes, the scope split only exists on the OAuth path, which means the CLI or the app. On the API, allowed_tools is your scope mechanism. The mechanics of that split are in MCP server OAuth authentication.

PlugKit costs $49 a month for 5 connected accounts, cancel anytime, or $97 for 30, with the MCP server, the REST API and the inbox included at both tiers. Seven days free, a card asked at sign-up, nothing charged before day 7, and the plan's full account quota during the trial. Checked on www.plugkit.co and docs.plugkit.co on November 25, 2026. X API calls are passed through at cost, $0.005 to read a post and $0.015 to publish one, which is the one line that moves with usage.

For the same setup on other clients, ChatGPT MCP connectors and Claude as your social media manager cover the two surfaces with setup cards.

Which Grok surface to pick

Surface OAuth Tool whitelist Approval gate
Grok app Yes No No
grok CLI Yes, automatic Via config No
Grok API No allowed_tools Not supported

The CLI is the best of the three, mostly because it reads other clients' config files and does OAuth without being asked. The API is the weakest on safety: no approval gate, no scopes, a full-access key in a request body. It is still the one you build on, so build with allowed_tools and a secondary account.

FAQ

Does Grok support MCP servers?

Yes, in three places. The Grok app takes a custom MCP connector from grok.com/connectors. The grok CLI adds one with grok mcp add --transport http <name> <url> and handles OAuth itself. The API takes an {"type": "mcp", "server_url": ..., "server_label": ...} entry in the tools array, in the native SDK, the Responses API and the Speech to Speech API.

How do I connect a custom MCP server to Grok?

In the app: grok.com/connectors, New Connector, Custom, paste the URL, finish the authentication. In the CLI: grok mcp add --transport http plugkit https://api.plugkit.co/mcp, then grok mcp doctor plugkit to check it. The server must be reachable on the public internet, and only Streamable HTTP and SSE transports are supported.

Can Grok post to Instagram or X?

Not on its own. Grok needs an MCP server that already holds the account tokens. Through a social MCP server such as PlugKit, Grok reaches create_post, get_comments, reply_to_comment and the inbox tools on Instagram, Facebook, LinkedIn, TikTok, YouTube, X, WhatsApp and Telegram. Without one, it can write the caption and nothing else.

Does the Grok API support OAuth for MCP servers?

No. The API passes a token you supply in the authorization parameter, or custom headers. The OAuth flows live in the app dialog and in the CLI, which stores tokens in ~/.grok/mcp_credentials.json. On the API you use an API key, which on most servers means full access, so restrict the tool list with allowed_tools instead.

Why does Grok reject my localhost MCP server?

Because xAI's servers call yours, so a private address is unreachable for them. Grok refuses localhost, 127.0.0.1, 10.x.x.x, 172.16.x.x and 192.168.x.x outright. Expose it with ngrok or cloudflared tunnel --url http://localhost:3001, and note that Cloudflare quick tunnels do not carry SSE.

AB
Antoine BlancoFounder of PlugKit. Runs his own Instagram, YouTube and X accounts through the API and MCP server described here.

One plug for every platform your agent touches

$49 a month for 5 connected accounts, cancel anytime. Every feature in every plan.

Get your API key →
English ▾