Grok MCP server

Provides access to Grok API for chat completions, text completions, embeddings, and model operations with robust request validation and error handling.
Back to servers
Setup instructions
Provider
BrewMyTech
Release date
May 24, 2025
Stats
7 stars

This MCP Server enables integration with the Grok API, allowing you to use Grok AI for chat completions, text completions, embeddings, and model operations. It supports features like streaming responses, multi-modal inputs, and comes with VSCode integration for a seamless development experience.

Getting Started

Prerequisites

Before setting up the server, you'll need to obtain a Grok API key:

  1. Visit x.ai to get your API key
  2. Keep this key secure and don't share it publicly

Installation

To install and set up the Grok MCP Server:

npm install
npm run build

Configuration

VSCode Integration

To integrate with VSCode, add the following configuration to your VSCode settings:

{
  "chat.mcp.enabled": true,
  "mcpServers": {
    "grok": {
      "command": "node-for-claude",
      "args": ["/path/to/grok-mcp/dist/index.js"],
      "env": {
        "GROK_API_KEY": "YOUR_GROK_API_KEY"
      }
    }
  }
}

Make sure to replace:

  • /path/to/grok-mcp/dist/index.js with the actual path to the installed server
  • YOUR_GROK_API_KEY with your actual Grok API key

Usage

Available Operations

The server supports the following operations:

Model Operations

List available models:

list_models

Returns an array of available models with their details.

Get specific model information:

get_model

Input:

  • model_id (string): The ID of the model to retrieve

Returns detailed information about the specified model.

Chat Completions

create_chat_completion

Inputs:

  • model (string): ID of the model to use
  • messages (array): Chat messages, each with role and content
  • temperature (optional number): Controls randomness (0-1)
  • top_p (optional number): Nucleus sampling parameter
  • n (optional number): Number of completions to generate
  • max_tokens (optional number): Maximum tokens to generate
  • stream (optional boolean): Whether to stream responses

Returns a generated chat completion response. Supports both text and image inputs in conversations.

Text Completions

create_completion

Inputs:

  • model (string): ID of the model to use
  • prompt (string): Text prompt to complete
  • temperature (optional number): Controls randomness
  • max_tokens (optional number): Maximum tokens to generate
  • stream (optional boolean): Whether to stream responses

Returns a generated text completion response.

Embeddings

create_embeddings

Inputs:

  • model (string): ID of the model to use
  • input (string or array): Text to embed
  • encoding_format (optional string): Format of the embeddings

Returns vector embeddings of the input text.

Advanced Features

  • Streaming Support: Enable real-time responses by setting the stream parameter to true in completion requests
  • Multi-modal Inputs: Submit both text and images in chat conversations
  • Comprehensive Error Handling: The server provides clear error messages for troubleshooting

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "grok" '{"command":"node","args":["index.js"],"env":{"GROK_API_KEY":"XXXXXXXX"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "grok": {
            "command": "node",
            "args": [
                "index.js"
            ],
            "env": {
                "GROK_API_KEY": "XXXXXXXX"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "grok": {
            "command": "node",
            "args": [
                "index.js"
            ],
            "env": {
                "GROK_API_KEY": "XXXXXXXX"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later