MCP 管理 API
@grant CAT.agent.mcp
MCP(Model Context Protocol)管理 API 允许脚本管理 MCP 服务器连接,MCP 服务器提供的工具会自动 注册到 Agent,供 AI 对话调用。
MCP 服务器
ScriptCat 的 MCP Client 使用 Streamable HTTP 传输协议(JSON-RPC 2.0 POST),支持 MCP 协议版本 2025-03-26。
MCP 服务器可以提供三种能力:
| 能力 | 说明 |
|---|---|
| Tools | 工具函数,自动注册为 Agent 可调用的工具 |
| Resources | 可读取的资源(文本/二进制) |
| Prompts | 提示词模板,支持参数化 |
listServers — 列出服务器
const servers = await CAT.agent.mcp.listServers();
返回值 MCPServerConfig[]:
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 服务器 ID |
name | string | 显示名称 |
url | string | HTTP 端点地址 |
apiKey | string | API Key(可选) |
headers | Record<string, string> | 自定义请求头(可选) |
enabled | boolean | 是否启用 |
createtime | number | 创建时间戳 |
updatetime | number | 更新时间戳 |
getServer — 获取服务器详情
const server = await CAT.agent.mcp.getServer(serverId);
addServer — 添加服务器
const server = await CAT.agent.mcp.addServer({
name: "My MCP Server",
url: "https://mcp.example.com/api",
apiKey: "sk-xxx", // 可选
headers: { // 可选自定义头
"X-Custom": "value"
},
enabled: true
});
updateServer — 更新服务器
await CAT.agent.mcp.updateServer(serverId, {
name: "新名称",
enabled: false
});
removeServer — 删除服务器
await CAT.agent.mcp.removeServer(serverId);