Documentation
¶
Overview ¶
Package mcp 是 pt-tools 的 MCP(Model Context Protocol)服务(路线图 M14):工具定义、权限检查与写操作的审计。
工具本身不碰数据库与下载器:经 Backend 在进程内调用 App API v1(web 实现),所以返回的字段、脱敏与 App API 完全一样。 传输在别处接:主端口的 streamable HTTP(/mcp,web 包)与 stdio 桥(pt-tools mcp,cmd 包)。
权限分两层:HTTP 层只放行有 mcp:read 或 mcp:write 的 API 令牌;工具分派时只读工具要 mcp:read,写工具要 mcp:write, 写工具还要 confirm=true。写工具的每次调用(包括被拒的)记操作审计,通道是 mcp,命令是工具名。
Index ¶
Constants ¶
View Source
const ChannelType = "mcp"
ChannelType 是 MCP 写工具在操作审计里的通道。
Variables ¶
View Source
var ToolNames = []string{
"list_tasks", "list_downloader_torrents", "get_downloader_stats", "search_torrents",
"pause_torrent", "resume_torrent", "delete_torrent", "push_torrent",
"get_site_userinfo", "check_updates",
"explore_media", "list_subscriptions", "add_subscription",
}
ToolNames 是全部工具的名字(文档与测试用)。
Functions ¶
Types ¶
type Auditor ¶
type Auditor interface {
Record(ctx context.Context, e app.AuditEntry) error
}
Auditor 记操作审计(app.AuditService 实现了它)。
type Caller ¶
Caller 是调用工具的 API 令牌。
func CallerFromRequest ¶
func CallerFromRequest(req *sdk.CallToolRequest) (Caller, bool)
CallerFromRequest 从工具请求里取调用的令牌(HTTP 层放进去的 TokenInfo);没有时 ok 为假。
type Deps ¶
type Deps struct {
Backend Backend
Audit Auditor
// ResolveURL 把种子下载地址解析成已知站点与种子编号(push_torrent 的 torrent_url);不认识时 ok 为假
ResolveURL func(rawURL string) (site, torrentID string, ok bool)
// Version 是 pt-tools 的版本(initialize 时报给客户端)
Version string
// Caller 从工具请求里取令牌,默认 CallerFromRequest(测试里换掉)
Caller func(req *sdk.CallToolRequest) (Caller, bool)
}
Deps 是 MCP 服务的依赖。
Click to show internal directories.
Click to hide internal directories.