Skip to content

Commit 2258555

Browse files
author
Lasim
committed
refactor(all): update MCP event schemas for consistency and clarity
1 parent e73e4e2 commit 2258555

File tree

5 files changed

+189
-134
lines changed

5 files changed

+189
-134
lines changed

services/backend/src/events/satellite/mcp-server-crashed.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,63 @@ export const EVENT_TYPE = 'mcp.server.crashed';
1515
export const SCHEMA = {
1616
type: 'object',
1717
properties: {
18-
processId: {
19-
type: 'string',
20-
minLength: 1,
21-
description: 'Process identifier in satelliteProcesses table'
22-
},
23-
serverId: {
18+
server_id: {
2419
type: 'string',
2520
minLength: 1,
2621
description: 'MCP server identifier that crashed'
2722
},
28-
serverName: {
23+
server_slug: {
2924
type: 'string',
3025
minLength: 1,
31-
description: 'Human-readable MCP server name'
26+
description: 'MCP server slug'
3227
},
33-
teamId: {
28+
team_id: {
3429
type: 'string',
3530
minLength: 1,
3631
description: 'Team identifier for the crashed server'
3732
},
38-
exitCode: {
33+
process_id: {
34+
type: 'number',
35+
description: 'Operating system process ID'
36+
},
37+
exit_code: {
3938
type: 'number',
4039
description: 'Process exit code'
4140
},
4241
signal: {
4342
type: 'string',
44-
description: 'Signal that terminated the process (e.g., SIGKILL, SIGSEGV)'
43+
description: 'Signal that terminated the process (e.g., SIGTERM, SIGKILL)'
4544
},
46-
errorMessage: {
47-
type: 'string',
48-
description: 'Error message or crash reason'
45+
uptime_seconds: {
46+
type: 'number',
47+
minimum: 0,
48+
description: 'Process uptime in seconds before crash'
4949
},
50-
stackTrace: {
51-
type: 'string',
52-
description: 'Stack trace if available'
50+
crash_count: {
51+
type: 'number',
52+
minimum: 1,
53+
description: 'Number of crashes for this process'
54+
},
55+
will_restart: {
56+
type: 'boolean',
57+
description: 'Whether the process will be automatically restarted'
5358
}
5459
},
55-
required: ['processId', 'serverId', 'serverName', 'teamId'],
60+
required: ['server_id', 'server_slug', 'team_id', 'process_id', 'exit_code', 'signal', 'uptime_seconds', 'crash_count', 'will_restart'],
5661
additionalProperties: true
5762
} as const;
5863

5964
// TypeScript interface for type safety
6065
interface ServerCrashedData {
61-
processId: string;
62-
serverId: string;
63-
serverName: string;
64-
teamId: string;
65-
exitCode?: number;
66-
signal?: string;
67-
errorMessage?: string;
68-
stackTrace?: string;
66+
server_id: string;
67+
server_slug: string;
68+
team_id: string;
69+
process_id: number;
70+
exit_code: number;
71+
signal: string;
72+
uptime_seconds: number;
73+
crash_count: number;
74+
will_restart: boolean;
6975
}
7076

7177
/**
@@ -83,14 +89,7 @@ export async function handle(
8389
const data = eventData as unknown as ServerCrashedData;
8490

8591
// Build error message from available data
86-
const errorDetails = [];
87-
if (data.exitCode !== undefined) errorDetails.push(`Exit code: ${data.exitCode}`);
88-
if (data.signal) errorDetails.push(`Signal: ${data.signal}`);
89-
if (data.errorMessage) errorDetails.push(data.errorMessage);
90-
91-
const errorMessage = errorDetails.length > 0
92-
? errorDetails.join(' | ')
93-
: 'Process crashed unexpectedly';
92+
const errorMessage = `Process crashed: Exit code ${data.exit_code}, Signal: ${data.signal}, Uptime: ${data.uptime_seconds}s, Crash #${data.crash_count}`;
9493

9594
// Update process status to failed
9695
await db
@@ -102,7 +101,7 @@ export async function handle(
102101
stopped_at: eventTimestamp,
103102
updated_at: new Date()
104103
})
105-
.where(eq(satelliteProcesses.id, data.processId));
104+
.where(eq(satelliteProcesses.id, data.server_id));
106105

107106
// Future enhancement: Trigger alert notifications
108107
// Future enhancement: Create incident tracking record

services/backend/src/events/satellite/mcp-server-started.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,54 @@ export const EVENT_TYPE = 'mcp.server.started';
1515
export const SCHEMA = {
1616
type: 'object',
1717
properties: {
18-
processId: {
18+
server_id: {
1919
type: 'string',
2020
minLength: 1,
21-
description: 'Unique process identifier in satelliteProcesses table'
21+
description: 'MCP server identifier (installation_id)'
2222
},
23-
serverId: {
23+
server_slug: {
2424
type: 'string',
2525
minLength: 1,
26-
description: 'MCP server identifier'
26+
description: 'MCP server slug (installation_name)'
2727
},
28-
serverName: {
29-
type: 'string',
30-
minLength: 1,
31-
description: 'Human-readable MCP server name'
32-
},
33-
teamId: {
28+
team_id: {
3429
type: 'string',
3530
minLength: 1,
3631
description: 'Team identifier'
3732
},
38-
pid: {
33+
process_id: {
3934
type: 'number',
4035
description: 'Operating system process ID'
4136
},
42-
localPort: {
37+
transport: {
38+
type: 'string',
39+
enum: ['stdio', 'http'],
40+
description: 'Transport protocol type'
41+
},
42+
tool_count: {
43+
type: 'number',
44+
minimum: 0,
45+
description: 'Number of tools discovered'
46+
},
47+
spawn_duration_ms: {
4348
type: 'number',
44-
description: 'Local port for HTTP communication'
49+
minimum: 0,
50+
description: 'Time taken to spawn process in milliseconds'
4551
}
4652
},
47-
required: ['processId', 'serverId', 'serverName', 'teamId'],
53+
required: ['server_id', 'server_slug', 'team_id', 'process_id', 'transport', 'tool_count', 'spawn_duration_ms'],
4854
additionalProperties: true
4955
} as const;
5056

5157
// TypeScript interface for type safety
5258
interface ServerStartedData {
53-
processId: string;
54-
serverId: string;
55-
serverName: string;
56-
teamId: string;
57-
pid?: number;
58-
localPort?: number;
59+
server_id: string;
60+
server_slug: string;
61+
team_id: string;
62+
process_id: number;
63+
transport: 'stdio' | 'http';
64+
tool_count: number;
65+
spawn_duration_ms: number;
5966
}
6067

6168
/**
@@ -77,11 +84,10 @@ export async function handle(
7784
.update(satelliteProcesses)
7885
.set({
7986
status: 'running',
80-
process_pid: data.pid || null,
81-
local_port: data.localPort || null,
87+
process_pid: data.process_id,
8288
health_status: 'healthy',
8389
started_at: eventTimestamp,
8490
updated_at: new Date()
8591
})
86-
.where(eq(satelliteProcesses.id, data.processId));
92+
.where(eq(satelliteProcesses.id, data.server_id));
8793
}

services/backend/src/events/satellite/mcp-tool-executed.ts

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,47 @@ export const EVENT_TYPE = 'mcp.tool.executed';
1515
export const SCHEMA = {
1616
type: 'object',
1717
properties: {
18-
processId: {
19-
type: 'string',
20-
description: 'Process identifier in satelliteProcesses table'
21-
},
22-
toolName: {
18+
tool_name: {
2319
type: 'string',
2420
minLength: 1,
25-
description: 'MCP tool name (e.g., filesystem/read_file)'
21+
description: 'MCP tool name (e.g., filesystem-read_file)'
2622
},
27-
serverId: {
23+
server_id: {
2824
type: 'string',
2925
minLength: 1,
3026
description: 'MCP server identifier that executed the tool'
3127
},
32-
teamId: {
28+
team_id: {
3329
type: 'string',
3430
minLength: 1,
3531
description: 'Team identifier for the execution context'
3632
},
37-
userId: {
38-
type: 'string',
39-
description: 'User who triggered the tool execution'
40-
},
41-
durationMs: {
33+
duration_ms: {
4234
type: 'number',
4335
minimum: 0,
4436
description: 'Tool execution duration in milliseconds'
4537
},
46-
statusCode: {
47-
type: 'number',
48-
description: 'Execution status code (200 = success, 4xx/5xx = error)'
38+
success: {
39+
type: 'boolean',
40+
description: 'Whether the tool execution succeeded'
4941
},
50-
errorMessage: {
42+
error_message: {
5143
type: 'string',
5244
description: 'Error message if execution failed'
53-
},
54-
requestSizeBytes: {
55-
type: 'number',
56-
minimum: 0,
57-
description: 'Input payload size in bytes'
58-
},
59-
responseSizeBytes: {
60-
type: 'number',
61-
minimum: 0,
62-
description: 'Output payload size in bytes'
63-
},
64-
userAgent: {
65-
type: 'string',
66-
description: 'Client user agent (e.g., VS Code version)'
67-
},
68-
ipAddress: {
69-
type: 'string',
70-
description: 'Client IP address if available'
7145
}
7246
},
73-
required: ['toolName', 'serverId', 'teamId'],
47+
required: ['tool_name', 'server_id', 'team_id', 'duration_ms', 'success'],
7448
additionalProperties: true
7549
} as const;
7650

7751
// TypeScript interface for type safety
7852
interface ToolExecutedData {
79-
processId?: string;
80-
toolName: string;
81-
serverId: string;
82-
teamId: string;
83-
userId?: string;
84-
durationMs?: number;
85-
statusCode?: number;
86-
errorMessage?: string;
87-
requestSizeBytes?: number;
88-
responseSizeBytes?: number;
89-
userAgent?: string;
90-
ipAddress?: string;
53+
tool_name: string;
54+
server_id: string;
55+
team_id: string;
56+
duration_ms: number;
57+
success: boolean;
58+
error_message?: string;
9159
}
9260

9361
/**
@@ -111,19 +79,19 @@ export async function handle(
11179
await db.insert(satelliteUsageLogs).values({
11280
id: nanoid(),
11381
satellite_id: satelliteId,
114-
user_id: data.userId || null,
115-
team_id: data.teamId,
116-
process_id: data.processId || null,
117-
request_method: 'POST', // MCP tools are typically POST requests
118-
request_path: `/mcp/tool/${data.toolName}`,
119-
tool_name: data.toolName,
120-
duration_ms: data.durationMs || null,
121-
status_code: data.statusCode || (data.errorMessage ? 500 : 200),
122-
error_message: data.errorMessage || null,
123-
request_size_bytes: data.requestSizeBytes || null,
124-
response_size_bytes: data.responseSizeBytes || null,
125-
user_agent: data.userAgent || null,
126-
ip_address: data.ipAddress || null,
82+
user_id: null,
83+
team_id: data.team_id,
84+
process_id: null,
85+
request_method: 'POST',
86+
request_path: `/mcp/tool/${data.tool_name}`,
87+
tool_name: data.tool_name,
88+
duration_ms: data.duration_ms,
89+
status_code: data.success ? 200 : 500,
90+
error_message: data.error_message || null,
91+
request_size_bytes: null,
92+
response_size_bytes: null,
93+
user_agent: null,
94+
ip_address: null,
12795
timestamp: eventTimestamp,
12896
date_partition: datePartition
12997
});

services/satellite/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ export async function createServer() {
368368
}, 'Automatic stdio tool discovery handler registered for process spawn events');
369369

370370

371-
// Initialize MCP Protocol Handler (after HTTP Proxy Manager and Tool Discovery Manager)
372-
const mcpProtocolHandler = new McpProtocolHandler(httpProxyManager, toolDiscoveryManager, server.log);
371+
// Initialize MCP Protocol Handler (after HTTP Proxy Manager, Tool Discovery Manager, and Process Manager)
372+
const mcpProtocolHandler = new McpProtocolHandler(httpProxyManager, toolDiscoveryManager, processManager, server.log);
373373

374374
// Initialize Command Processor with stdio process management dependencies
375375
const commandProcessor = new CommandProcessor(

0 commit comments

Comments
 (0)