Documentation
¶
Overview ¶
Package mcp 实现 PigeonBox 的 Model Context Protocol (MCP) server。
传输:Streamable HTTP(POST 单端点,JSON-RPC 2.0;与 MCP 规范对齐, Claude Desktop / 任意标准 MCP 客户端可直接接入)。legacy 文档中的裸 TCP 方案不符合 MCP 规范,本实现为标准重做。
认证:路由挂 AdminMiddleware(管理员 JWT),AI 客户端以 Authorization: Bearer <admin token> 接入。
工具集(对齐 legacy docs/mcp-server-guide.md + 2026-10-06 上传/下载/联邦扩展):
share_text / share_file / get_share / get_share_content / download_share_file / list_shares / delete_share / get_system_status / get_storage_info / list_users / cleanup_expired / federation_status / federation_resolve
Index ¶
- type AdminAPI
- type FederationAPI
- type FederationResolve
- type FederationStatus
- type FileShareOpts
- type Service
- func (s *Service) Handle(ctx context.Context, body []byte) (int, []byte)
- func (s *Service) SetAdminService(svc AdminAPI)
- func (s *Service) SetFederationService(svc FederationAPI)
- func (s *Service) SetMaxFileSize(n int64)
- func (s *Service) SetShareService(svc ShareAPI)
- func (s *Service) SetStorageService(svc StorageAPI)
- func (s *Service) ToolNames() []string
- type ShareAPI
- type ShareFileInfo
- type StorageAPI
- type StorageStatusInfo
- type SystemStats
- type UserRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminAPI ¶
type AdminAPI interface {
SystemStats(ctx context.Context) (*SystemStats, error)
StorageStatus(ctx context.Context) (*StorageStatusInfo, error)
Users(ctx context.Context, page, pageSize int) ([]UserRow, int64, error)
CleanExpired(ctx context.Context) (count, freed int64, err error)
}
AdminAPI 系统维护类工具所需的 admin 域能力(bootstrap 注入全站唯一实例适配器)。
type FederationAPI ¶
type FederationAPI interface {
Status() FederationStatus
Resolve(code string) (*FederationResolve, error)
}
FederationAPI P2P 联邦工具所需事实(未启用时 bootstrap 传 nil 实例适配器)。
type FederationResolve ¶
type FederationResolve struct {
NodeID string
URL string
Name string
ExpiresAt time.Time
SizeHint int64
}
FederationResolve 联邦路由解析结果。
type FederationStatus ¶
FederationStatus 联邦状态工具所需事实。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service MCP server。adminSvc 提供统计/维护能力,shareSvc 提供分享创建, storageSvc 提供文件下载事实,fedSvc 提供联邦状态/路由(未启用时为 nil 适配器); storage/DAO 直查用于 get_share/get_share_content/list_shares 展示。
func NewService ¶
NewService 创建 MCP service。依赖经 Set*Service 注入(bootstrap 装配; 未注入时对应工具返回明确错误而非静默降级)。
func (*Service) Handle ¶
Handle 处理一次 JSON-RPC POST。 返回 (httpStatus, responseBody);通知类请求返回 (202, "")。
func (*Service) SetAdminService ¶
SetAdminService 注入 admin 域能力适配器(统计/用户/维护)
func (*Service) SetFederationService ¶
func (s *Service) SetFederationService(svc FederationAPI)
SetFederationService 注入 P2P 联邦适配器(未启用传 nil 实例适配器)
func (*Service) SetMaxFileSize ¶
SetMaxFileSize 配置 MCP 单文件上限(字节;非正值回退默认)
func (*Service) SetShareService ¶
SetShareService 注入 share 域能力适配器(创建分享)
func (*Service) SetStorageService ¶
func (s *Service) SetStorageService(svc StorageAPI)
SetStorageService 注入存储能力(download_share_file)
type ShareAPI ¶
type ShareAPI interface {
CreateTextShare(ctx context.Context, text string, expireValue int, expireStyle string,
requireAuth bool, passwordHash string, ownerIP, customCode string) (code, fullURL string, err error)
ShareBytes(ctx context.Context, opts FileShareOpts) (code, fullURL string, err error)
ShareFiles(ctx context.Context, code string) ([]ShareFileInfo, error)
}
ShareAPI 分享创建/查询工具所需的 share 域能力。
type StorageAPI ¶
type StorageAPI interface {
GetFileSize(ctx context.Context, filePath string) (int64, error)
GetFile(ctx context.Context, filePath string) ([]byte, error)
}
StorageAPI 下载工具所需存储事实(bootstrap 注入全站唯一实例)。
type StorageStatusInfo ¶
type StorageStatusInfo struct {
StorageType string
TotalSpace int64
UsedSpace int64
UsagePercent float64
FileCount int64
}
StorageStatusInfo 存储状态工具所需事实。