Grok MCP server

Provides direct integration with Grok AI's language and vision capabilities, exposing chat completion, image understanding, and function calling tools for developers to interact with Grok's latest models.
Back to servers
Setup instructions
Provider
Braden Olmstead
Release date
Mar 09, 2025
Language
TypeScript
Package
Stats
1.7K downloads
13 stars

The Grok MCP Plugin integrates Grok AI's capabilities directly with Cline, providing seamless access to chat completion, image understanding, and function calling tools through the Model Context Protocol (MCP) interface.

Installation

Prerequisites

  • Node.js (v16 or higher)
  • A Grok AI API key (obtain from console.x.ai)
  • Cline with MCP support

Setup Steps

  1. Clone the repository:

    git clone https://github.com/Bob-lance/grok-mcp.git
    cd grok-mcp
    
  2. Install dependencies:

    npm install
    
  3. Build the project:

    npm run build
    
  4. Configure in Cline MCP settings:

    For VSCode Cline extension, edit the settings file at:

    ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
    

    Add this configuration:

    {
      "mcpServers": {
        "grok-mcp": {
          "command": "node",
          "args": ["/path/to/grok-mcp/build/index.js"],
          "env": {
            "XAI_API_KEY": "your-grok-api-key"
          },
          "disabled": false,
          "autoApprove": []
        }
      }
    }
    

    Make sure to:

    • Replace /path/to/grok-mcp with your actual installation path
    • Set your-grok-api-key to your actual Grok AI API key

Usage

The Grok MCP plugin provides three main tools that can be used in Cline:

Chat Completion

Generate text responses using Grok's language models:

<use_mcp_tool>
<server_name>grok-mcp</server_name>
<tool_name>chat_completion</tool_name>
<arguments>
{
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello, what can you tell me about Grok AI?"
    }
  ],
  "temperature": 0.7
}
</arguments>
</use_mcp_tool>

Image Understanding

Analyze images with Grok's vision capabilities:

<use_mcp_tool>
<server_name>grok-mcp</server_name>
<tool_name>image_understanding</tool_name>
<arguments>
{
  "image_url": "https://example.com/image.jpg",
  "prompt": "What is shown in this image?"
}
</arguments>
</use_mcp_tool>

You can also use base64-encoded images:

<use_mcp_tool>
<server_name>grok-mcp</server_name>
<tool_name>image_understanding</tool_name>
<arguments>
{
  "base64_image": "base64-encoded-image-data",
  "prompt": "What is shown in this image?"
}
</arguments>
</use_mcp_tool>

Function Calling

Use Grok to call functions based on user input:

<use_mcp_tool>
<server_name>grok-mcp</server_name>
<tool_name>function_calling</tool_name>
<arguments>
{
  "messages": [
    {
      "role": "user",
      "content": "What's the weather like in San Francisco?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"],
              "description": "The unit of temperature to use"
            }
          },
          "required": ["location"]
        }
      }
    }
  ]
}
</arguments>
</use_mcp_tool>

API Reference

Chat Completion Parameters

  • messages (required): Array of message objects with role and content
  • model (optional): Grok model to use (defaults to grok-3-mini-beta)
  • temperature (optional): Sampling temperature (0-2, defaults to 1)
  • max_tokens (optional): Maximum number of tokens to generate (defaults to 16384)

Image Understanding Parameters

  • prompt (required): Text prompt to accompany the image
  • image_url (optional): URL of the image to analyze
  • base64_image (optional): Base64-encoded image data (without the data:image prefix)
  • model (optional): Grok vision model to use (defaults to grok-2-vision-latest)

Note: Either image_url or base64_image must be provided.

Function Calling Parameters

  • messages (required): Array of message objects with role and content
  • tools (required): Array of tool objects with type, function name, description, and parameters
  • tool_choice (optional): Tool choice mode (auto, required, none, defaults to auto)
  • model (optional): Grok model to use (defaults to grok-3-mini-beta)

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-mcp" '{"command":"node","args":["/path/to/grok-mcp/build/index.js"],"env":{"XAI_API_KEY":"your-grok-api-key"},"disabled":false,"autoApprove":[]}'

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-mcp": {
            "command": "node",
            "args": [
                "/path/to/grok-mcp/build/index.js"
            ],
            "env": {
                "XAI_API_KEY": "your-grok-api-key"
            },
            "disabled": false,
            "autoApprove": []
        }
    }
}

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-mcp": {
            "command": "node",
            "args": [
                "/path/to/grok-mcp/build/index.js"
            ],
            "env": {
                "XAI_API_KEY": "your-grok-api-key"
            },
            "disabled": false,
            "autoApprove": []
        }
    }
}

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