Grok_MCP

R1ver2014/Grok_MCP
0 Stars 67 次浏览 更新于 2026-08-23

一种模型上下文协议(MCP)插件,它提供了从Cline直接无缝访问Grok AI强大功能的能力。此插件通过MCP接口暴露了三个强大的工具:1.

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

Grok MCP 插件

npm 版本
Smithery 构建状态

这是一个 Model Context Protocol (MCP) 插件,它提供了从 Cline 直接无缝访问 Grok AI 强大功能的能力。

功能

此插件通过 MCP 接口暴露了三个强大的工具:

  1. 聊天完成 - 使用 Grok 的语言模型生成文本响应
  2. 图像理解 - 使用 Grok 的视觉能力分析图像
  3. 函数调用 - 根据用户输入使用 Grok 调用函数

前提条件

  • Node.js (v16 或更高版本)
  • Grok AI API 密钥(从 console.x.ai 获取)
  • 支持 MCP 的 Cline

安装

  1. 克隆此仓库:

    git clone https://github.com/Bob-lance/grok-mcp.git
    cd grok-mcp
    
  2. 安装依赖项:

    npm install
    
  3. 构建项目:

    npm run build
    
  4. 将 MCP 服务器添加到您的 Cline MCP 设置中:

    对于 VSCode Cline 扩展,编辑以下文件:

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

    添加以下配置:

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

    /path/to/grok-mcp 替换为您安装的实际路径,并将 your-grok-api-key 替换为您的 Grok AI API 密钥。

使用方法

安装并配置完成后,Grok MCP 插件在 Cline 中提供了三个可以使用的工具:

聊天完成

使用 Grok 的语言模型生成文本响应:


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

图像理解

使用 Grok 的视觉能力分析图像:


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

您也可以使用 base64 编码的图像:


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

函数调用

根据用户输入使用 Grok 调用函数:


<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 参考

聊天完成

使用 Grok AI 聊天完成生成响应。

参数:

  • messages (必需): 包含角色和内容的消息对象数组
  • model (可选): 使用的 Grok 模型 (默认为 grok-3-mini-beta)
  • temperature (可选): 采样温度 (0-2, 默认为 1)
  • max_tokens (可选): 生成的最大令牌数 (默认为 16384)

图像理解

使用 Grok AI 视觉能力分析图像。

参数:

  • prompt (必需): 伴随图像的文本提示
  • image_url (可选): 要分析的图像 URL
  • base64_image (可选): Base64 编码的图像数据 (不包括 data:image 前缀)
  • model (可选): 使用的 Grok 视觉模型 (默认为 grok-2-vision-latest)

注意: 必须提供 image_urlbase64_image 中的一个。

函数调用

使用 Grok AI 根据用户输入调用函数。

参数:

  • messages (必需): 包含角色和内容的消息对象数组
  • tools (必需): 工具对象数组,包含类型、函数名称、描述和参数
  • tool_choice (可选): 工具选择模式 (auto, required, none, 默认为 auto)
  • model (可选): 使用的 Grok 模型 (默认为 grok-3-mini-beta)

开发

项目结构

  • src/index.ts - 主服务器实现
  • src/grok-api-client.ts - Grok API 客户端实现

构建


npm run build

运行


XAI_API_KEY="your-grok-api-key" node build/index.js

许可证

此项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。

致谢

相关 MCP 服务