完善 MCP 工具

This commit is contained in:
2026-06-11 08:21:09 +08:00
parent c0f15050d0
commit 1415d3b43b
20 changed files with 3722 additions and 61 deletions
+27 -18
View File
@@ -251,30 +251,15 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) {
chat.NewHandler(chatConvSvc, chatMsgSvc, chatTplSvc, chatEpSvc, chatUsageSvc,
chatUploader, userSvc, userAdminAdapter{svc: userSvc}).Mount(r)
// ===== MCP 模块装配 =====
// ===== MCP 模块装配(第一段:token/限流)=====
// Server 本体的装配在 ACP / run 模块之后(ServerDeps 依赖 acp bridge 与 runSvc),
// 这里只构造 ACP reaper / supervisor 需要的 token service。
mcpRepo := mcp.NewPostgresRepository(pool)
mcpTokenSvc := mcp.NewTokenService(mcpRepo, auditRec, nil) // mcp 自身 audit 不需要 via_mcp 标记
mcpRateLimiter := mcp.NewRateLimiter(mcp.RateLimitConfig{
PerTokenPerMinute: cfg.MCP.RateLimit.PerTokenPerMinute,
GlobalPerMinute: cfg.MCP.RateLimit.GlobalPerMinute,
}, nil)
mcpDeps := mcp.ServerDeps{
Caller: mcp.NewCallerResolver(userSvc),
Projects: projectSvc,
Reqs: requirementSvc,
Issues: issueSvc,
Artifacts: artifactSvc,
Workspaces: wsSvc,
Templates: chatTplSvc,
Messages: chatMsgSvc,
Conversations: chatConvSvc,
}
mcpServer := mcp.NewMCPServer(mcpDeps)
mcp.MountTransports(r, mcpServer, mcpTokenSvc, mcpRateLimiter)
mcp.MountAdmin(r, mcp.AdminHandlerDeps{
Tokens: mcpTokenSvc,
Users: userSvc,
})
// ===== ACP module wiring (Part 2: full SessionService + Supervisor) =====
acpRepo := acp.NewPostgresRepository(pool)
@@ -420,6 +405,30 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) {
}).Mount(r)
}
// ===== MCP 模块装配(第二段:Server 本体 + transports + admin CRUD)=====
mcpDeps := mcp.ServerDeps{
Caller: mcp.NewCallerResolver(userSvc),
Projects: projectSvc,
Reqs: requirementSvc,
Issues: issueSvc,
Artifacts: artifactSvc,
Workspaces: wsSvc,
Worktrees: wtSvc,
GitOps: gopSvc,
Templates: chatTplSvc,
Messages: chatMsgSvc,
Conversations: chatConvSvc,
Endpoints: chatEpSvc,
ACP: acp.NewMCPBridge(akSvc, sessSvc, acpPermSvc),
Runs: runSvc,
}
mcpServer := mcp.NewMCPServer(mcpDeps)
mcp.MountTransports(r, mcpServer, mcpTokenSvc, mcpRateLimiter)
mcp.MountAdmin(r, mcp.AdminHandlerDeps{
Tokens: mcpTokenSvc,
Users: userSvc,
})
// ===== jobs module wiring =====
jobsRepo := jobs.NewPostgresRepository(pool)