Skip to main content
Glama

grok-mcp-server

Give any MCP-compatible agent access to Grok.

CI License: MIT Node.js MCP Dependencies Powered by Grok

Tools · Setup · Protocol support · Development · Contributing


A tiny Model Context Protocol (MCP) server that brings Grok (xAI) into any MCP-compatible agent, IDE or desktop client.

Highlights

  • Zero dependencies. About 200 lines of plain Node.js that speak JSON-RPC 2.0 over stdio.

  • 4 focused tools. Ask, code review, error explanation and summarization.

  • Safe failures. API errors come back as tool errors, so your agent keeps running.

  • Uses the xAI Responses API (POST /v1/responses) with store: false.

Related MCP server: grok-build-mcp

Tools

Tool

What it does

Required args

ask_grok

Ask Grok anything: second opinions, research, brainstorming

prompt

grok_review_code

Review a snippet for bugs, security, performance and readability

code

grok_explain_error

Root cause, fix and verification steps for an error or stack trace

error

grok_summarize

Summarize long text as bullets, paragraph or tldr

text

Every tool also accepts optional arguments (system, model, language, focus, context, style).

Setup

  1. Get an API key from the xAI console.

  2. Add the server to your MCP client configuration. Most clients use this shape:

{
  "mcpServers": {
    "grok": {
      "command": "npx",
      "args": ["-y", "github:myn4ki/grok-mcp-server"],
      "env": {
        "XAI_API_KEY": "xai-...",
        "GROK_MODEL": "grok-4.7"
      }
    }
  }
}

Or clone it and point to the file directly:

git clone https://github.com/myn4ki/grok-mcp-server
{
  "mcpServers": {
    "grok": {
      "command": "node",
      "args": ["/path/to/grok-mcp-server/bin/grok-mcp-server.js"],
      "env": { "XAI_API_KEY": "xai-..." }
    }
  }
}

Environment variables

Variable

Default

Purpose

XAI_API_KEY

(required)

xAI API key

GROK_MODEL

grok-4.7

Default model for all tools

XAI_BASE_URL

https://api.x.ai/v1

Override for proxies or gateways

Try it by hand

The server reads newline-delimited JSON-RPC on stdin:

printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
  '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"ask_grok","arguments":{"prompt":"Explain MCP in one sentence"}}}' \
  | XAI_API_KEY=xai-... node bin/grok-mcp-server.js

Protocol support

  • initialize, which negotiates 2025-11-25, 2025-06-18, 2025-03-26 and 2024-11-05

  • ping

  • tools/list

  • tools/call

  • Notifications such as notifications/initialized are accepted silently.

Development

npm test     # node --test, no install required
npm start    # run the server on stdio

Add a tool by appending an entry to src/tools.js with a name, description, JSON inputSchema and a build(args) function that returns { prompt, system }.

Project layout:

bin/grok-mcp-server.js   Executable entry point
src/server.js            JSON-RPC 2.0 / MCP message handling over stdio
src/tools.js             Tool definitions and prompt builders
src/grok.js              Minimal xAI Responses API client
test/                    node:test suites

Contributing

Contributions are welcome, and new tools especially. Please read CONTRIBUTING.md and our Code of Conduct. To report a vulnerability, see SECURITY.md.

License

Released under the MIT License.

Available Tools

4 tools
ask_grokB

Ask Grok (xAI) any question and get its answer. Useful for a second opinion, research or brainstorming.

Inputs: prompt (required), model, system.

grok_explain_errorA

Explain an error message or stack trace with Grok: likely root cause and step-by-step fix.

Inputs: error (required), context.

grok_review_codeA

Have Grok review a code snippet for bugs, security issues, performance and readability.

Inputs: code (required), focus, language.

grok_summarizeC

Summarize long text (docs, logs, discussions) with Grok.

Inputs: text (required), style, language.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 4 tools

    Disambiguation4/5

    The specialized tools for code review, error explanation, and summarization are clearly distinct from each other. However, ask_grok is a general-purpose tool that overlaps with all three specialized tools, so an agent may sometimes be unsure whether to use the general or specialized variant.

    Naming Consistency3/5

    All names are snake_case and include the provider name, but the pattern is mixed: ask_grok starts with the action verb, while grok_review_code, grok_explain_error, and grok_summarize use a provider prefix followed by the action. The naming remains readable but is not fully consistent.

    Tool Count5/5

    Four tools is a well-scoped size for an LLM-provider wrapper. Each tool has a clear, non-redundant purpose and the count avoids both thinness and bloat.

    Completeness4/5

    The surface covers common Grok use cases: general Q&A, code review, error explanation, and summarization. Minor gaps exist around multi-turn conversation, custom system prompts, or file-based input, but the core workflows are represented.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      MCP server that wraps the xAI Grok API, allowing Claude and other AI agents to delegate thinking, planning, and real-time search tasks to Grok. It provides a single tool with options for different use cases including web search, Twitter/X search, and multi-agent reasoning.
      2
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables 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