Grok MCP Plugin
通过模型上下文协议,直接从 Cline 无缝访问 Grok AI 的各项功能(聊天补全、图像理解和函数调用)。
README
Grok MCP 插件
一个模型上下文协议 (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(必需): 包含角色和内容的 message 对象数组model(可选): 要使用的 Grok 模型 (默认为 grok-2-latest)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(必需): 包含角色和内容的 message 对象数组tools(必需): 包含类型、函数名称、描述和参数的 tool 对象数组tool_choice(可选): 工具选择模式 (auto, required, none,默认为 auto)model(可选): 要使用的 Grok 模型 (默认为 grok-2-latest)
开发
项目结构
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 文件。
致谢
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。