跳到主内容

MCP工具参考

Casdoor MCP 服务器提供了管理 Casdoor 对象的工具。本页介绍如何列出这些工具、如何调用它们以及它们的返回值。

列出工具​

调用 tools/list:

POST /api/mcp
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}

响应中包含哪些工具取决于请求的身份验证方式:

AuthenticationTools in the response
NoneAll tools, so that clients can discover them. Calling a tool still requires authentication
Session cookieAll tools
Access tokenThe tools that the scopes of the token allow

每个工具都带有描述和输入模式:

{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "get_applications",
"description": "Get all applications for a specific owner",
"inputSchema": {
"type": "object",
"properties": {
"owner": {
"type": "string",
"description": "The owner of applications"
}
},
"required": ["owner"]
}
}
]
}
}

应用工具​

ToolDescription
get_applicationsGets all applications of an organization
get_applicationGets one application
add_applicationCreates an application
update_applicationChanges an application
delete_applicationDeletes an application

使用 tools/call、工具名称及其参数来调用工具。

get_applications:

{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get_applications",
"arguments": {
"owner": "my-org"
}
}
}

get_application:

{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "get_application",
"arguments": {
"id": "my-org/my-app"
}
}
}

add_application:

{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "add_application",
"arguments": {
"application": {
"owner": "my-org",
"name": "new-app",
"displayName": "New Application",
"organization": "my-org"
}
}
}
}

update_application:

{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "update_application",
"arguments": {
"id": "my-org/my-app",
"application": {
"owner": "my-org",
"name": "my-app",
"displayName": "Updated Name"
}
}
}
}

delete_application:

{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "delete_application",
"arguments": {
"application": {
"owner": "my-org",
"name": "old-app"
}
}
}
}

用户工具​

用户工具的工作方式与应用工具相同。

ToolArgumentsDescription
get_usersownerLists all users of an organization
get_userid, or owner and email, or owner and phoneGets one user
add_useruser objectCreates a user
update_userid and user objectChanges a user
delete_useruser objectDeletes a user

其他工具​

使用商业或企业许可证时,服务器还提供用于组织、提供商、角色、权限、群组、证书和令牌的工具,用于为应用配置应用并连接第三方登录的工具,每项更改的试运行功能,记录智能体所做更改的功能,以及更改的批准和回滚功能。请参阅 让 AI 智能体管理 Casdoor。有关每个工具所需的范围,请参阅 范围参考。

结果格式​

成功的调用会将结果作为内容返回:

{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "[{\"name\":\"app1\",\"displayName\":\"App 1\"}]"
}
]
}
}

当工具执行失败时,结果包含 isError 标志:

{
"jsonrpc": "2.0",
"id": 5,
"result": {
"content": [
{
"type": "text",
"text": "application quota is exceeded"
}
],
"isError": true
}
}

协议本身的错误(例如缺少作用域)是 JSON-RPC 错误。请参阅 MCP 错误处理。

另请参阅​