Grok / xAI
Ask Grok questions and research the web or X with source citations.
For the complete documentation index, see llms.txt. Markdown variants of every page are available by appending .md to the URL.Ask Grok questions and research the web or X with source citations. Start with the Grok Research Assistant template or the runnable example.
Configure access
Create an API key in the xAI console and fund the API account. Set XAI_API_KEY; optionally set XAI_MODEL to a model that supports the requested tools. The default is grok-4.7. xAI API billing is separate from X API access and consumer subscriptions.
The server calls the native Responses API at https://api.x.ai/v1/responses with a Bearer token. Grok's X search does not need an X OAuth token and cannot publish posts. All authorized MCP clients consume the same xAI account's credits.
MCP clients send MCP_API_KEY as x-api-key on every request. Missing or incorrect keys fail before provider calls. The server forwards only the provider credential upstream, disables redirects, and keeps no session state. Follow the template walkthrough for installation, startup, and discovery.
Available tools
| Tool | Purpose |
|---|---|
ask-grok | Answer a single question without search. |
search-web-with-grok | Research the web and return available citations. |
search-x-with-grok | Research X posts and return available citations. |
Ask and research
All three tools accept prompt (1–8,000 characters after trimming) and optional maxOutputTokens (128–4,096, default 1,024). Each call is independent; the server sends no previous response ID or conversation history.
Call search-web-with-grok with:
Or call search-x-with-grok to research public X posts:
The JSON text result contains responseId, model, text, and citations (HTTP(S) source URLs and optional titles). Only completed assistant text is returned. Reasoning and internal tool records are excluded; incomplete responses, refusals, and missing answer text return errors. Citation URLs are deduplicated; offsets are omitted because output text blocks are joined. Citations may be absent; inspect sources before relying on an answer.
Search tools require their corresponding native web search or X search tool, with max_turns: 3 and parallel tool calls disabled. Three turns do not mean three individual searches or a hard spending limit. maxOutputTokens limits visible output only; reasoning and search usage can be billed separately. Set provider-side spending controls appropriate to your account.
Requests use store: false to disable later response retrieval through the Responses API. This does not promise that the provider retains no data under its broader policies. Streaming is disabled, and the server does not store chat history.
Draft an X reply
Use this server to research or draft text, then review it and explicitly publish through the separate X integration. The X server requires its own OAuth user token. Neither Grok research tool posts or automatically triggers publication.
Errors and validation
Missing or incorrect client keys return HTTP 401 before reaching xAI. Provider failures return tool errors with HTTP status and no raw error body. Requests time out after 90 seconds and are never retried automatically. A local timeout does not guarantee that provider processing or billing stopped. Model availability, credits, search access, and real answer quality require a live API account.
Run the example's build, typecheck, unit tests, and compiled HTTP smoke tests as shown in its README. All test provider calls are mocked; no live posts are published and no API credits are consumed.
