feat: McpToken — HTTP-mode mcplocal, CLI verbs, audit plumbing #50

Merged
michal merged 12 commits from feat/mcptoken into main 2026-04-18 16:37:53 +00:00
Showing only changes of commit dfc53cd15e - Show all commits

View File

@@ -315,10 +315,13 @@ async function main(): Promise<void> {
const backupService = new BackupService(serverRepo, projectRepo, secretRepo, userRepo, groupRepo, rbacDefinitionRepo, promptRepo, templateRepo); const backupService = new BackupService(serverRepo, projectRepo, secretRepo, userRepo, groupRepo, rbacDefinitionRepo, promptRepo, templateRepo);
const restoreService = new RestoreService(serverRepo, projectRepo, secretRepo, userRepo, groupRepo, rbacDefinitionRepo, promptRepo, templateRepo); const restoreService = new RestoreService(serverRepo, projectRepo, secretRepo, userRepo, groupRepo, rbacDefinitionRepo, promptRepo, templateRepo);
// Auth middleware for global hooks // Shared auth dependencies. Both the global auth hook and the per-route
const authMiddleware = createAuthMiddleware({ // preHandler on /api/v1/mcp/proxy must know how to resolve both session
findSession: (token) => authService.findSession(token), // bearers AND mcpctl_pat_ bearers, or mcplocal→mcpd proxy calls with a
findMcpToken: async (tokenHash) => { // McpToken will 401 at the route layer even though the global hook accepts them.
const authDeps = {
findSession: (token: string) => authService.findSession(token),
findMcpToken: async (tokenHash: string) => {
const row = await mcpTokenRepo.findByHash(tokenHash); const row = await mcpTokenRepo.findByHash(tokenHash);
if (row === null) return null; if (row === null) return null;
return { return {
@@ -332,7 +335,8 @@ async function main(): Promise<void> {
revokedAt: row.revokedAt, revokedAt: row.revokedAt,
}; };
}, },
}); };
const authMiddleware = createAuthMiddleware(authDeps);
// Server // Server
const app = await createServer(config, { const app = await createServer(config, {
@@ -436,7 +440,7 @@ async function main(): Promise<void> {
registerMcpProxyRoutes(app, { registerMcpProxyRoutes(app, {
mcpProxyService, mcpProxyService,
auditLogService, auditLogService,
authDeps: { findSession: (token) => authService.findSession(token) }, authDeps,
}); });
registerRbacRoutes(app, rbacDefinitionService); registerRbacRoutes(app, rbacDefinitionService);
registerUserRoutes(app, userService); registerUserRoutes(app, userService);