Documentation
¶
Overview ¶
Package mcp 实现 PigeonBox 的 Model Context Protocol (MCP) server。
传输:Streamable HTTP(POST 单端点,JSON-RPC 2.0;与 MCP 规范对齐, Claude Desktop / 任意标准 MCP 客户端可直接接入)。legacy 文档中的裸 TCP 方案不符合 MCP 规范,本实现为标准重做。
认证与作用域(2026-10-12 访客快速分享,对标上游 v2.8 MCP quick share 并超出): 默认路由挂 AdminMiddleware(管理员 JWT)全量工具;PB_MCP_ALLOW_GUEST=true 时 改挂可选认证,按调用者身份分三级作用域——游客(未登录)仅 share_text/share_file 快速分享(与网页匿名寄件同链路、同限流、同审核/白名单),登录用户 += create_request_code/preview_share,管理员 = 全量。
工具集(对齐 legacy docs/mcp-server-guide.md + 2026-10-06 上传/下载/联邦扩展 + 2026-10-12 寄件码/预览工具):
share_text / share_file / create_request_code / preview_share / 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 Caller
- type FederationAPI
- type FederationResolve
- type FederationStatus
- type FileShareOpts
- type PreviewAPI
- type PreviewReq
- type PreviewResult
- type RequestAPI
- type RequestCreate
- type Service
- func (s *Service) Handle(ctx context.Context, body []byte, caller Caller) (int, []byte)
- func (s *Service) SetAdminService(svc AdminAPI)
- func (s *Service) SetBaseURL(base string)
- func (s *Service) SetFederationService(svc FederationAPI)
- func (s *Service) SetMaxFileSize(n int64)
- func (s *Service) SetPreviewService(svc PreviewAPI)
- func (s *Service) SetRequestService(svc RequestAPI)
- 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 PreviewAPI ¶ added in v0.17.0
type PreviewAPI interface {
Preview(ctx context.Context, req PreviewReq) (*PreviewResult, error)
}
PreviewAPI 预览工具所需的 preview 域能力(bootstrap 注入域适配器)。
type PreviewReq ¶ added in v0.17.0
PreviewReq 预览请求(preview_share 工具;闸门/密码校验在 preview 域内执行)。
type PreviewResult ¶ added in v0.17.0
type PreviewResult struct {
PreviewType string
MimeType string
TextContent string
FileSize int64
Width int
Height int
PageCount int
Duration int
}
PreviewResult 预览结果(AI 友好的最小事实面)。
type RequestAPI ¶ added in v0.17.0
type RequestAPI interface {
Create(ctx context.Context, userID uint, req RequestCreate) (token string, expiredAt time.Time, err error)
}
RequestAPI 寄件码工具所需的 request 域能力(bootstrap 注入域适配器)。
type RequestCreate ¶ added in v0.17.0
type RequestCreate struct {
Title string
MaxFiles int
MaxBytes int64
ExpireValue int
ExpireStyle string
}
RequestCreate 寄件码(反向收件投递链接)创建参数。
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, "")。 caller 为 transport 层提取的调用者身份(游客=零值),驱动工具作用域过滤。
func (*Service) SetAdminService ¶
SetAdminService 注入 admin 域能力适配器(统计/用户/维护)
func (*Service) SetBaseURL ¶ added in v0.17.0
SetBaseURL 注入对外 base(server.base_url;空=按请求来源动态推断)
func (*Service) SetFederationService ¶
func (s *Service) SetFederationService(svc FederationAPI)
SetFederationService 注入 P2P 联邦适配器(未启用传 nil 实例适配器)
func (*Service) SetMaxFileSize ¶
SetMaxFileSize 配置 MCP 单文件上限(字节;非正值回退默认)
func (*Service) SetPreviewService ¶ added in v0.17.0
func (s *Service) SetPreviewService(svc PreviewAPI)
SetPreviewService 注入 preview 域能力适配器(preview_share)
func (*Service) SetRequestService ¶ added in v0.17.0
func (s *Service) SetRequestService(svc RequestAPI)
SetRequestService 注入 request 域能力适配器(create_request_code)
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, userID *uint, 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 存储状态工具所需事实。