Skip to main content
Glama
README.md
<div align="center">

# grok-mcp-server

**Give any MCP-compatible agent access to Grok.**

[![CI](https://github.com/myn4ki/grok-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/myn4ki/grok-mcp-server/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-black.svg)](LICENSE)
[![Node.js](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org)
[![MCP](https://img.shields.io/badge/MCP-2025--11--25-purple.svg)](https://modelcontextprotocol.io)
[![Dependencies](https://img.shields.io/badge/dependencies-0-blue.svg)](package.json)
[![Powered by Grok](https://img.shields.io/badge/powered%20by-Grok-000000.svg)](https://x.ai/api)

[Tools](#tools) ·
[Setup](#setup) ·
[Protocol support](#protocol-support) ·
[Development](#development) ·
[Contributing](#contributing)

</div>

---

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`.

## 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](https://console.x.ai).
2. Add the server to your MCP client configuration. Most clients use this shape:

```json
{
  "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:

```bash
git clone https://github.com/myn4ki/grok-mcp-server
```

```json
{
  "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:

```bash
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

```bash
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`](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](CONTRIBUTING.md)
and our [Code of Conduct](CODE_OF_CONDUCT.md). To report a vulnerability, see [SECURITY.md](SECURITY.md).

## License

Released under the [MIT License](LICENSE).

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