grok-mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
grok-mcp
Grok as a tool for every agent. An MCP server for the xAI API — live X and web search with citations, schema-locked extraction, image generation, and a token/cost ledger that keeps autonomous agents from quietly burning a budget.
Any MCP client — Claude Code, Cursor, Codex, Zed, your own agent loop — gets seven tools: grok_ask, grok_web_search, grok_x_search, grok_structured, grok_imagine, grok_models, grok_usage.
┌──────────────────────┐ MCP (stdio / HTTP) ┌───────────────────────┐
│ Claude Code │ ───────────────────────────────▶ │ grok-mcp │
│ Cursor · Codex │ tools · resources · JSON Schema │ ┌─────────────────┐ │
│ your agent │ ◀─────────────────────────────── │ │ validation │ │
└──────────────────────┘ results + usage + citations │ │ retry/backoff │ │
│ │ cost ledger │ │
│ └────────┬────────┘ │
└───────────┼───────────┘
▼
api.x.ai/v1 · responses
x_search · web_searchWhy another Grok wrapper
Because an agent needs four things a raw API call does not give it:
Problem | What this server does |
"Which endpoint do I hit?" | One tool per capability. No URLs, no payload assembly, no guessing. |
"Where did that answer come from?" | Citations are parsed from all three places Grok puts them (inline |
"What will this cost?" | Every result carries token counts and an estimated |
"Why did my agent tool call fail mysteriously?" | Validation errors are anticipated failures: the model receives the actual message ("from_date must look like YYYY-MM-DD") instead of |
Plus the boring things that make it usable: retries with Retry-After handling, a concurrency cap, typed results (outputSchema for every tool), structured logs on stderr only, and an offline mock backend so the whole thing runs without an API key.
Related MCP server: grok-mcp-server
Quick start
# try it with zero credentials — deterministic fixtures, no network
GROK_MCP_MOCK=1 uvx --from git+https://github.com/ruji9527/grok-mcp grok-mcpReal usage:
export GROK_API_KEY="xai-..." # https://console.grok.com
uvx --from git+https://github.com/ruji9527/grok-mcp grok-mcp # stdio
# or, from a clone: pip install -e . && grok-mcp --transport streamable-http --port 8765Claude Code
claude mcp add grok \
--env GROK_API_KEY=xai-... \
-- uvx --from git+https://github.com/ruji9527/grok-mcp grok-mcpCursor / Claude Desktop / any JSON config
{
"mcpServers": {
"grok": {
"command": "uvx",
"args": ["--from", "git+https://github.com/ruji9527/grok-mcp", "grok-mcp"],
"env": { "GROK_API_KEY": "xai-..." }
}
}
}Typical session:
You: What are people on X saying about the new Grok release since Monday? Cite the posts.
Agent: (calls
grok_x_searchwithfrom_date, thengrok_structuredto normalize the sentiment into a table) → answer withx.comlinks, pluscost_usdfor both calls.
Tools
Tool | Use it when | Notes |
| reasoning, writing, code, explanations | no network; |
| anything after the training cutoff |
|
| sentiment, breaking discussion, what specific accounts said |
|
| any output you intend to parse | JSON Schema string; the API enforces it, result arrives in |
| image generation | 1–4 images, |
| picking a model on price, not vibes | context window + per-MTok prices per model |
| before/after a batch | calls, tokens, estimated spend, by model and tool; |
Resources: grok://models (price table) and grok://usage (session totals) — cacheable context instead of a tool round-trip.
Full argument reference: docs/TOOLS.md. Cost model and how to cap spend: docs/COST.md.
Offline demo

Real output from python scripts/demo.py --mock (fixtures, no API key):
grok-mcp demo · backend=mock · model=grok-4.7 · base_url=https://api.x.ai/v1
2. grok_web_search
The Responses API is the recommended surface: it takes `tools` (`web_search`, `x_search`,
`code_execution`), returns `citations` at the top level, and accepts `text.format` for
schema-locked JSON. [[1]](https://docs.grok.com/…)
citations: 2 · cost: $0.005836
3. grok_x_search
Sentiment around the launch splits in two. Builders are enthusiastic about live search with
inline citations, and pragmatic about cost: per-post billing shows up in every comparison
thread. [[1]](https://x.com/example/st…)
[1] https://x.com/example/status/1000000000000000001
[2] https://x.com/example/status/1000000000000000002
cost: $0.010840
6. grok_models
grok-4.7 context 500,000 $2.00/M in, $6.00/M out
grok-4.3 context 1,000,000 $1.25/M in, $2.50/M out
7. grok_usage
5 calls · 532 in / 265 out tokens · estimated $0.057654
cost_is_estimate=TrueThe answers above are fixtures; the envelope, usage accounting, citation parsing, and cost math are the same code paths a live call takes.
Configuration
Env var | Default | Meaning |
| — | xAI API key ( |
|
| Default model for every tool |
|
| Point at a proxy or regional endpoint |
|
| Per-request timeout, seconds |
|
| Retries for 429/5xx/network errors |
|
| Base backoff, seconds (doubles per attempt, plus jitter) |
|
| In-flight request cap |
| — | Global output cap |
|
| Truncate long answers (flagged via |
| — | Append every call to a JSONL file |
|
|
|
|
| Logs go to stderr |
.env is read from the working directory; real environment variables win. See .env.example.
CLI flags: --transport stdio|sse|streamable-http, --host, --port, --model, --mock, --log-level, --print-config, --version.
Design notes
Capability tools, not a passthrough. A generic
grok(payload)tool pushes the API surface into the model's context and invites malformed calls. Each tool here validates its arguments before a request is spent.Errors as data. Validation problems and API failures are re-raised as anticipated tool errors, so the calling model gets a message it can act on and the server logs one line instead of a traceback.
Everything is metered.
GrokClientowns aUsageLedger; no call path can skip accounting. Costs are estimates by construction (see docs/COST.md) and labelled as such rather than presented as invoices.Stdout is sacred. On stdio transports stdout is the protocol channel. Logging is configured to stderr and the end-to-end test would catch a stray
print.Mock backend, not mock tests. CI runs the real process over real MCP, so a broken handshake or a renamed field fails the build.
More in docs/ARCHITECTURE.md.
Development
git clone https://github.com/ruji9527/grok-mcp && cd grok-mcp
uv venv && uv pip install -e ".[dev]"
make check # ruff + mypy + pytest
make demo # offline end-to-end run69 tests, including one that spawns the server over stdio and speaks MCP to it. No API key required for the suite.
Roadmap
Streaming results (
stream=true) with progress notificationsgrok_deep_search— multi-step research loop with a token budgetVision input: pass an image URL to
grok_askCollections/RAG tools (
collections_search)Price-table auto-refresh from
/v1/modelsmetadataDocker image for
--transport streamable-http
Issues and PRs welcome — see CONTRIBUTING.md. If a tool surprises you, that is a bug report I want.
License
MIT. Not affiliated with xAI; "Grok" is their trademark, used here to describe what the code talks to.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Live AI-native web search with citations. One tool for every MCP client. Flat per-request pricing.
Official Exa MCP for web search, content fetching, and multi-step research.
Hosted MCP server from TwitterAPI.io that gives AI agents read-only access to Twitter/X data. 12 tools: tweet search with X operators, user profiles, a user's latest tweets, followers and followings, replies, quotes, retweeters, mentions and trends. Connect at https://mcp.twitterapi.io/mcp with a TwitterAPI.io API key or account sign-in; usage is paid per result returned. Separately, TwitterAPI.io also offers x402 pay-per-call HTTP endpoints (tweet search, user info, a user's latest tweets) paid in USDC on Base or Solana with no account or API key; see https://docs.twitterapi.io/x402-pay-per-call. The MCP server itself uses an API key or sign-in.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceLive X (Twitter) and web search for any coding agent through your existing Grok subscription. Exposes a grok_search MCP tool, so no X API key or X developer account is needed.111 npm29Apache 2.0
- AlicenseNot gradedqualityNot gradedmaintenanceEnables any MCP-compatible AI to use xAI Grok's full toolset, including live X/Twitter search, web search, chat, image generation and editing, vision, video generation, structured outputs, and reasoning, all from a remotely hosted Cloudflare Worker.MIT
- AlicenseAqualityBmaintenanceEnables MCP agents to perform native X (Twitter) searches with original-post citations and transparent usage tracking. Supports existing Grok login sessions or explicit xAI API billing without runtime dependencies.158 npm1MIT
- AlicenseNot gradedqualityBmaintenanceEnables MCP clients to run text chat, deep reasoning, vision analysis, and image generation through the xAI Grok API, alongside workspace file read/write/shell tools, web search, speech-to-text and text-to-speech, and background jobs with persistent conversation history in PostgreSQL. Supports both HTTP and stdio transports with per-tool model selection from the live xAI catalog.3MIT