Grok (xAI API)
This page is for developers building on the xAI API, not for the
Grok consumer app on grok.com, X, or the mobile clients. Those don’t
expose a way to add a custom MCP connector. xAI’s API does: you pass
an MCP server config inside the tools array of a Chat, Responses,
or Voice request, and xAI brokers the connection on the server side.
Protocol background lives at MCP. Full xAI reference: docs.x.ai/developers/tools/remote-mcp.
Prerequisites
Section titled “Prerequisites”Before you start, confirm:
- You have an Engram account at app.engram.page.
- At least one vault is synced. Open the Obsidian plugin or the web app and confirm notes have synced within the last day.
- You can sign in via browser. The MCP auth flow opens a browser window.
Plus xAI-specific:
- An xAI API key with model access (Grok 4 family or whichever model you target).
- An Engram API key for the Bearer header. xAI’s Remote MCP Tools
feature passes the
authorizationvalue straight through to the MCP server on every call. Generate one atapp.engram.page/settings/api-keys.
Endpoint
Section titled “Endpoint”https://mcp.engram.page/api/mcpNative xai_sdk
Section titled “Native xai_sdk”from xai_sdk import Client
client = Client(api_key="YOUR_XAI_KEY")
response = client.chat.create( model="grok-4", messages=[{"role": "user", "content": "What did I write about Q3 planning?"}], tools=[ { "type": "mcp", "server_url": "https://mcp.engram.page/api/mcp", "server_label": "engram", "authorization": "Bearer YOUR_ENGRAM_API_KEY", } ],)
print(response.output_text)OpenAI-compatible API
Section titled “OpenAI-compatible API”from openai import OpenAI
client = OpenAI( api_key="YOUR_XAI_KEY", base_url="https://api.x.ai/v1",)
response = client.responses.create( model="grok-4", input="What did I write about Q3 planning?", tools=[ { "type": "mcp", "server_url": "https://mcp.engram.page/api/mcp", "server_label": "engram", "authorization": "Bearer YOUR_ENGRAM_API_KEY", } ],)
print(response.output_text)Optional knobs xAI exposes on the tool object: allowed_tools (list
of MCP tool names to whitelist), headers (extra headers per call).
See the xAI Remote MCP reference
for the full schema.
Transports
Section titled “Transports”xAI’s Remote MCP Tools supports Streamable HTTP and SSE. Engram’s endpoint speaks Streamable HTTP. Pass it directly, no adapter needed.
Why no OAuth flow
Section titled “Why no OAuth flow”The xAI API is a server-to-server surface. There’s no browser to
open and no end-user session to attach a token to. Pass an Engram
API key in the authorization field instead. Treat it like any
service credential: keep it out of source control and rotate it
when teammates rotate off.
The grant is the full mcp scope today.
Granular per-action scopes are on the roadmap.
Troubleshooting
Section titled “Troubleshooting”401from the MCP server. Your Engram API key is wrong or revoked. Generate a fresh key in Engram settings.- Tool calls never fire. Grok decided it didn’t need the tool.
Make the system prompt explicit: “Use the
engramtools to look up the user’s notes before answering.” Invalid transport. Your endpoint URL is wrong or the tool block is malformed. Confirm the URL matches the endpoint above and the tool block hastype: mcpplus the four fields shown above.
For cross-client failures, see Troubleshooting.
Revocation
Section titled “Revocation”Revoke the Engram API key under your account → API Keys & Sessions. Once revoked, xAI calls carrying that key return 401 immediately.