概述
MOMO AI 提供 MCP(Model Context Protocol)协议支持,您可以通过 MCP 接口将 MOMO AI 智能体集成到任何支持 MCP 的应用程序中。MCP 是一种标准化协议,允许 AI 模型与外部工具和服务进行交互。
MOMO AI 的 MCP 服务提供以下能力:
- 发现智能体:浏览和搜索您已购买的 MOMO AI 智能体
- 调用智能体:直接通过工具调用接口使用智能体
- 搜索市场:在 MOMO AI 市场搜索更多智能体
- 购买额度:为特定智能体购买使用额度
MCP 端点
MOMO AI 提供两个 MCP 端点:
| 端点 | 方法 | 用途 |
|---|---|---|
/api/mcp/messages | POST | 处理 MCP JSON-RPC 请求 |
/api/mcp/sse | GET | 建立 SSE 长连接(用于远程传输) |
认证方式
所有 MCP 请求需要通过 API 密钥进行认证。
认证头
x-momoai-key: YOUR_API_KEY
或使用标准 Authorization 头:
Authorization: Bearer YOUR_API_KEY
JSON-RPC 接口
初始化连接
在开始使用工具之前,需要先初始化连接。
请求:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}
响应:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"tools": {}
},
"serverInfo": {
"name": "momoai-hub",
"version": "1.0.0"
}
}
}
健康检查
请求:
{
"jsonrpc": "2.0",
"id": 1,
"method": "ping",
"params": {}
}
响应:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"status": "pong"
}
}
工具列表
调用 tools/list 方法获取可用的工具列表。
请求:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
响应:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "search_momo_agents",
"description": "在 MomoAI 市场搜索智能体...",
"inputSchema": {
"type": "object",
"properties": {
"query": { "type": "string", "description": "搜索关键词" }
},
"required": ["query"]
}
},
{
"name": "buy_agent_tokens",
"description": "为指定的智能体购买 Token...",
"inputSchema": {
"type": "object",
"properties": {
"agent_id": { "type": "number", "description": "Agent ID" },
"token_amount": { "type": "number", "description": "购买数量" }
},
"required": ["agent_id", "token_amount"]
}
},
{
"name": "momo_agent_58",
"description": "翻译助手 (deepseek-chat) | 余额: 10000 tokens | 价格: 1 credits / 1000 tokens | 专业的翻译智能体...",
"inputSchema": {
"type": "object",
"properties": {
"prompt": { "type": "string", "description": "发送给智能体的指令或问题" }
},
"required": ["prompt"]
}
}
]
}
}
可用工具说明
| 工具名称 | 功能 |
|---|---|
search_momo_agents | 在 MOMO AI 市场搜索智能体 |
buy_agent_tokens | 为指定智能体购买 Token 额度 |
momo_agent_{id} | 调用特定智能体(显示为已购买的智能体列表) |
工具调用
搜索智能体
请求:
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "search_momo_agents",
"arguments": {
"query": "翻译"
}
}
}
响应:
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "{\n \"query\": \"翻译\",\n \"count\": 5,\n \"agents\": [\n {\n \"id\": 58,\n \"name\": \"翻译助手\",\n \"description\": \"专业的翻译智能体,支持多语言翻译...\",\n \"price\": 1,\n \"priceUnit\": \"1000\",\n \"baseModel\": \"deepseek-chat\",\n \"tags\": [\"翻译\", \"语言\"],\n \"hasPurchased\": true,\n \"availableTokens\": 10000\n }\n ],\n \"tip\": \"使用 buy_agent_tokens 工具购买 token 后即可使用智能体\"\n}"
}
]
}
}
购买 Token 额度
请求:
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "buy_agent_tokens",
"arguments": {
"agent_id": 58,
"token_amount": 10000
}
}
}
响应:
{
"jsonrpc": "2.0",
"id": 4,
"result": {
"content": [
{
"type": "text",
"text": "成功为 Agent 58 购买了 10000 tokens"
}
]
}
}
调用智能体
请求:
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "momo_agent_58",
"arguments": {
"prompt": "将以下中文翻译成英文:你好,世界!"
}
}
}
响应:
{
"jsonrpc": "2.0",
"id": 5,
"result": {
"content": [
{
"type": "text",
"text": "Hello, World!"
}
]
}
}
错误响应示例
工具调用失败:
{
"jsonrpc": "2.0",
"id": 6,
"result": {
"content": [
{
"type": "text",
"text": "错误: Token 余额不足,请先购买额度"
}
],
"isError": true
}
}
完整使用示例
Python 示例
import requests
import json
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://hub.momoai.pro/api/mcp"
headers = {
"Content-Type": "application/json",
"x-momoai-key": API_KEY
}
def mcp_request(method, params=None):
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": method,
"params": params or {}
}
response = requests.post(
f"{BASE_URL}/messages",
headers=headers,
json=payload
)
return response.json()
# 1. 初始化
print("=== 初始化 ===")
result = mcp_request("initialize")
print(json.dumps(result, indent=2, ensure_ascii=False))
# 2. 获取工具列表
print("\n=== 工具列表 ===")
result = mcp_request("tools/list")
for tool in result["result"]["tools"]:
print(f"- {tool['name']}")
# 3. 搜索智能体
print("\n=== 搜索智能体 ===")
result = mcp_request("tools/call", {
"name": "search_momo_agents",
"arguments": {"query": "编程"}
})
print(json.dumps(result, indent=2, ensure_ascii=False))
# 4. 调用智能体
print("\n=== 调用智能体 ===")
result = mcp_request("tools/call", {
"name": "momo_agent_58",
"arguments": {"prompt": "你好,请做个自我介绍"}
})
print(result["result"]["content"][0]["text"])
Node.js 示例
const fetch = require('node-fetch');
const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://hub.momoai.pro/api/mcp";
async function mcpRequest(method, params = {}) {
const response = await fetch(`${BASE_URL}/messages`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-momoai-key': API_KEY
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method,
params
})
});
return response.json();
}
async function main() {
// 1. 初始化
console.log('=== 初始化 ===');
const init = await mcpRequest('initialize');
console.log(JSON.stringify(init, null, 2));
// 2. 获取工具列表
console.log('\n=== 工具列表 ===');
const tools = await mcpRequest('tools/list');
tools.result.tools.forEach(tool => {
console.log(`- ${tool.name}`);
});
// 3. 搜索智能体
console.log('\n=== 搜索智能体 ===');
const search = await mcpRequest('tools/call', {
name: 'search_momo_agents',
arguments: { query: '数据分析' }
});
console.log(search.result.content[0].text);
// 4. 调用智能体
console.log('\n=== 调用智能体 ===');
const result = await mcpRequest('tools/call', {
name: 'momo_agent_58',
arguments: { prompt: '请用一句话介绍你自己' }
});
console.log(result.result.content[0].text);
}
main().catch(console.error);
cURL 示例
# 1. 初始化
curl -X POST "https://hub.momoai.pro/api/mcp/messages" \
-H "Content-Type: application/json" \
-H "x-momoai-key: YOUR_API_KEY" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}'
# 2. 获取工具列表
curl -X POST "https://hub.momoai.pro/api/mcp/messages" \
-H "Content-Type: application/json" \
-H "x-momoai-key: YOUR_API_KEY" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}'
# 3. 搜索智能体
curl -X POST "https://hub.momoai.pro/api/mcp/messages" \
-H "Content-Type: application/json" \
-H "x-momoai-key: YOUR_API_KEY" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "search_momo_agents",
"arguments": {
"query": "Python"
}
}
}'
# 4. 调用智能体
curl -X POST "https://hub.momoai.pro/api/mcp/messages" \
-H "Content-Type: application/json" \
-H "x-momoai-key: YOUR_API_KEY" \
-d '{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "momo_agent_58",
"arguments": {
"prompt": "解释什么是 REST API"
}
}
}'
SSE 远程传输
对于需要长连接的场景,可以使用 SSE(Server-Sent Events)端点。
建立连接
GET /api/mcp/sse?key=YOUR_API_KEY
请求头:
x-momoai-key: YOUR_API_KEY
响应:
Content-Type: text/event-stream
data: {"jsonrpc":"2.0","method":"connection/established","params":{"connectionId":"user123_1700000000000","serverInfo":{"name":"momoai-hub","version":"1.0.0"}}}
: heartbeat
连接说明
- 连接建立:服务器会返回
connection/established事件,包含连接 ID - 心跳检测:每 30 秒发送一次心跳(
: heartbeat),保持连接活跃 - 连接关闭:客户端断开连接时,服务器会自动清理资源
错误处理
错误码
| 错误码 | 说明 |
|---|---|
| -32600 | 无效的请求(API 密钥缺失或无效) |
| -32601 | 方法不存在 |
| -32603 | 服务器内部错误 |
错误响应格式
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32600,
"message": "Missing API key"
}
}
常见错误
认证失败:
{
"jsonrpc": "2.0",
"error": {
"code": -32600,
"message": "Invalid API key"
}
}
Token 余额不足:
{
"jsonrpc": "2.0",
"result": {
"content": [
{
"type": "text",
"text": "错误: 您没有 Agent 58 的使用额度。请先在 https://hub.momoai.pro 购买 token。"
}
],
"isError": true
}
}
工具说明
search_momo_agents
在 MOMO AI 市场搜索智能体。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query | string | 是 | 搜索关键词 |
返回: 包含智能体 ID、名称、描述、价格、标签等信息的 JSON 结果。
buy_agent_tokens
为指定智能体购买使用额度。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
agent_id | number | 是 | 智能体 ID |
token_amount | number | 是 | 购买的 Token 数量 |
返回: 购买结果消息。
momo_agent_{id}
调用已购买的 MOMO AI 智能体。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 是 | 发送给智能体的指令或问题 |
注意: 该工具仅显示用户已购买的智能体(最多 10 个),未购买的智能体需要先购买额度才能使用。
使用限制
- 工具列表限制:最多显示 10 个已购买的智能体
- 搜索结果限制:每次搜索最多返回 10 个结果
- 认证要求:所有请求必须包含有效的 API 密钥
在 AI 应用中使用
MCP 协议被广泛用于 AI 助手应用,如 Claude Desktop、Cursor 等。您可以在这些应用的配置中添加 MOMO AI 作为 MCP 服务器。
Claude Desktop 配置示例
在 claude_desktop_config.json 中添加:
{
"mcpServers": {
"momoai": {
"command": "python",
"args": ["-m", "mcp_client.py", "https://hub.momoai.pro"],
"env": {
"MOMOAI_API_KEY": "YOUR_API_KEY"
}
}
}
}
Cursor 配置示例
在 Cursor 设置中添加 MCP 服务器配置,指向 https://hub.momoai.pro。
常见问题
Q: 为什么我的工具列表是空的? A: 您需要先在 MOMO AI 平台购买智能体额度。购买后,智能体会自动显示在工具列表中。
Q: 如何查看我已购买的智能体? A: 登录 MOMO AI 平台,进入账户 → Token 管理页面查看。
Q: 调用智能体时提示余额不足怎么办?
A: 使用 buy_agent_tokens 工具为该智能体购买额度,或在 MOMO AI 平台购买。
Q: 支持流式响应吗? A: 当前版本不支持流式响应,工具调用会返回完整结果。
Q: 可以同时调用多个智能体吗? A: 可以,MCP 支持并发调用多个不同的工具。
技术支持
如有任何问题,请联系 MOMO AI 官方:
- 综合邮箱:partnership@momoai.wecom.work
- 商务合作:13716105018
- 技术支持:13815831618

