mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-10-31 20:55:35 +08:00
- docs/dev/plugins.md 改为总览与导航,旧内容拆入 docs/dev/plugins/ - 新增核心概念、配置表单、事件、前端挂载点、命令行、签名与分发、内置插件、示例页 - 每个扩展点一页,侧边栏由页面表生成 - 改正旧文档中下载器配置、hardlink path_map 与补链按钮的过时描述
36 lines
1.7 KiB
Markdown
36 lines
1.7 KiB
Markdown
# MCP Tools and Resources (mcp_tool / mcp_resource)
|
|
|
|
Exposes plugin abilities to MCP clients.
|
|
|
|
```python
|
|
from ab_sdk import points, provider
|
|
from ab_sdk.mcp import McpResource, McpTool
|
|
|
|
@provider(points.MCP_TOOL, id="search")
|
|
def search_tool(self):
|
|
async def handler(args: dict):
|
|
return {"results": [...], "keyword": args["keyword"]}
|
|
|
|
return McpTool(
|
|
description="Search a private site",
|
|
handler=handler,
|
|
input_schema={
|
|
"type": "object",
|
|
"properties": {"keyword": {"type": "string"}},
|
|
"required": ["keyword"],
|
|
},
|
|
)
|
|
|
|
@provider(points.MCP_RESOURCE, id="stats")
|
|
def stats_resource(self):
|
|
async def handler():
|
|
return {"count": 3}
|
|
|
|
return McpResource(name="Statistics", handler=handler)
|
|
```
|
|
|
|
- AB adds the plugin id to the public name: the tool name is `<plugin id>__<id>` (double underscore) and the resource URI is `autobangumi://plugins/<plugin id>/<id>`. AB does not use `.` as a separator. Many MCP clients give the tool name unchanged to the LLM API, and that API usually accepts only `^[a-zA-Z0-9_-]{1,64}$`. AB skips a tool name that does not match and writes a log line.
|
|
- A tool handler receives the argument dict that AB validated against `input_schema`. It returns a JSON-serializable object. A resource handler returns a string (sent as it is) or a JSON-serializable object.
|
|
- AB returns a raised exception to the client as `{"error": "..."}`, and it counts toward the breaker. The default tool timeout is 60 seconds (`McpTool(timeout=...)`).
|
|
- The MCP endpoint uses the access control of AB (IP allowlist or a token with `scope=mcp`). A plugin does not need its own authentication.
|