Skip to content

Commit c292d86

Browse files
author
Lasim
committed
feat(satellite): add authentication middleware to MCP routes for stats
1 parent ec92ba4 commit c292d86

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

services/satellite/src/core/mcp-server-wrapper.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,21 @@ export class McpServerWrapper {
306306
* Setup Fastify routes for MCP transport
307307
*/
308308
setupRoutes(fastify: FastifyInstance): void {
309+
// Get authentication middleware from server instance
310+
const tokenIntrospectionService = (fastify as any).tokenIntrospectionService;
311+
const activityTracker = (fastify as any).activityTracker;
312+
309313
// Handle POST requests for client-to-server communication
310-
fastify.post('/mcp', async (request: FastifyRequest, reply: FastifyReply) => {
314+
fastify.post('/mcp', {
315+
preValidation: async (request: FastifyRequest, reply: FastifyReply) => {
316+
// Apply authentication middleware
317+
if (tokenIntrospectionService && activityTracker) {
318+
const { requireAuthentication } = await import('../middleware/auth-middleware');
319+
const authMiddleware = requireAuthentication(tokenIntrospectionService, activityTracker);
320+
await authMiddleware(request, reply);
321+
}
322+
}
323+
}, async (request: FastifyRequest, reply: FastifyReply) => {
311324
const sessionId = request.headers['mcp-session-id'] as string | undefined;
312325
let transport: StreamableHTTPServerTransport;
313326
let server: Server;
@@ -374,6 +387,11 @@ export class McpServerWrapper {
374387
return;
375388
}
376389

390+
// Track activity before handling request (redundant now - auth middleware does this)
391+
// const requestBody = request.body as any;
392+
// const isToolCall = requestBody?.method === 'tools/call';
393+
// await this.trackActivity(request, sessionId, isToolCall);
394+
377395
// Handle the request
378396
await transport.handleRequest(request.raw, reply.raw, request.body);
379397
});

services/satellite/src/server.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,9 @@ export async function createServer() {
626626

627627
server.log.info({
628628
operation: 'oauth_services_initialized',
629-
satellite_id: satelliteId
630-
}, 'OAuth authentication and team-aware MCP services initialized');
629+
satellite_id: satelliteId,
630+
activity_tracking_enabled: true
631+
}, 'OAuth authentication, team-aware MCP services, and activity tracking initialized');
631632
} else {
632633
server.log.error({
633634
operation: 'satellite_registration_failed',
@@ -707,8 +708,9 @@ export async function createServer() {
707708

708709
server.log.info({
709710
operation: 'oauth_services_initialized',
710-
satellite_id: satelliteId
711-
}, 'OAuth authentication and team-aware MCP services initialized');
711+
satellite_id: satelliteId,
712+
activity_tracking_enabled: true
713+
}, 'OAuth authentication, team-aware MCP services, and activity tracking initialized');
712714
}
713715

714716
// Initialize heartbeat service

0 commit comments

Comments
 (0)