关于 Grok MCP Plugin
这是一个用于接入 Grok AI API 的 MCP 插件,可在 Cline 中直接调用 Grok 的文本生成、图像理解和函数调用能力。适合希望在编辑器内使用 Grok 模型的开发者。
主要功能
- 01文本对话补全
- 02图像理解,支持 URL 或 base64 输入
- 03基于用户输入的函数调用
- 04可配置模型、温度和最大 token 数
适用场景
- 01在 Cline 中调用 Grok 生成文本回复
- 02让 Grok 分析图片内容
- 03借助 Grok 根据请求选择并调用函数
MCP 相关
该项目是一个 MCP 服务,向 Cline 等 MCP 客户端暴露 chat_completion、image_understanding 和 function_calling 三个工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Grok MCP 插件
一个 Model Context Protocol (MCP) 插件,可直接从 Cline 无缝访问 Grok AI 的强大能力。
功能
该插件通过 MCP 接口提供三个强大的工具:
- 聊天补全 - 使用 Grok 的语言模型生成文本回复
- 图像理解 - 使用 Grok 的视觉能力分析图像
- 函数调用 - 使用 Grok 根据用户输入调用函数
前置要求
- Node.js(v16 或更高版本)
- Grok AI API 密钥(从 console.x.ai 获取)
- 支持 MCP 的 Cline
安装
-
克隆此仓库:
git clone https://github.com/Bob-lance/grok-mcp.git cd grok-mcp -
安装依赖:
npm install -
构建项目:
npm run build -
将 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(必需):包含 role 和 content 的消息对象数组model(可选):要使用的 Grok 模型(默认为 grok-3-mini-beta)temperature(可选):采样温度(0-2,默认为 1)max_tokens(可选):要生成的最大 token 数(默认为 16384)
图像理解
使用 Grok AI 视觉能力分析图像。
参数:
prompt(必需):随图像一起提供的文本提示词image_url(可选):要分析的图像 URLbase64_image(可选):base64 编码的图像数据(不包含 data:image 前缀)model(可选):要使用的 Grok 视觉模型(默认为 grok-2-vision-latest)
注意:必须提供 image_url 或 base64_image 之一。
函数调用
使用 Grok AI 根据用户输入调用函数。
参数:
messages(必需):包含 role 和 content 的消息对象数组tools(必需):包含 type、function name、description 和 parameters 的工具对象数组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 文件。
致谢
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。