跳到主内容

MCP错误处理

Casdoor MCP 服务器将协议错误报告为 JSON-RPC 2.0 错误。本页列出这些代码并展示示例响应。

错误代码​

CodeNameCause
-32700Parse errorThe request isn't valid JSON
-32600Invalid RequestA required field is missing
-32601Method not foundThe method name is unknown
-32602Invalid paramsThe parameters are malformed
-32001未授权或 scope 不足请求没有有效的凭据,或者令牌缺少该工具的 scope

示例响应​

缺少 scope。错误信息会指出该工具所需的 scope 以及当前令牌的 scopes:

{
"jsonrpc": "2.0",
"id": 5,
"error": {
"code": -32001,
"message": "insufficient_scope",
"data": {
"tool": "add_application",
"granted_scopes": ["read:application"],
"required_scope": "write:application"
}
}
}

无效的 JSON:

{
"jsonrpc": "2.0",
"id": null,
"error": {
"code": -32700,
"message": "Parse error",
"data": "unexpected character at position 12"
}
}

未知的方法:

{
"jsonrpc": "2.0",
"id": 8,
"error": {
"code": -32601,
"message": "Method not found",
"data": "Method 'unknown_method' not found"
}
}

工具运行期间发生的错误并非 JSON-RPC 错误。工具返回带有 isError 标志的结果。参见 Result format。

其他协议特性​

  • 通知:服务器接受不带 id 字段的请求且不作出响应。

  • 批量请求:服务器接受请求数组。

  • 健康检查:ping 方法返回空结果:

    {
    "jsonrpc": "2.0",
    "id": 9,
    "method": "ping"
    }
  • 演示模式:当 Casdoor 以演示模式运行时,服务器拒绝写操作,但允许读操作和身份验证。

另请参阅​