|
1 | 1 | import { ConformanceCheck, CheckStatus } from '../types.js'; |
2 | | - |
3 | | -export function createServerInitializationCheck(initializeResponse: any, expectedSpecVersion: string = '2025-06-18'): ConformanceCheck { |
4 | | - const result = initializeResponse?.result; |
5 | | - const protocolVersion = result?.protocolVersion; |
6 | | - const serverInfo = result?.serverInfo; |
7 | | - const capabilities = result?.capabilities; |
8 | | - |
9 | | - const errors: string[] = []; |
10 | | - if (!initializeResponse?.jsonrpc) errors.push('Missing jsonrpc field'); |
11 | | - if (!initializeResponse?.id) errors.push('Missing id field'); |
12 | | - if (!result) errors.push('Missing result field'); |
13 | | - if (!protocolVersion) errors.push('Missing protocolVersion in result'); |
14 | | - if (protocolVersion !== expectedSpecVersion) |
15 | | - errors.push(`Protocol version mismatch: expected ${expectedSpecVersion}, got ${protocolVersion}`); |
16 | | - if (!serverInfo) errors.push('Missing serverInfo in result'); |
17 | | - if (!serverInfo?.name) errors.push('Missing server name in serverInfo'); |
18 | | - if (!serverInfo?.version) errors.push('Missing server version in serverInfo'); |
19 | | - if (capabilities === undefined) errors.push('Missing capabilities in result'); |
20 | | - |
21 | | - const status: CheckStatus = errors.length === 0 ? 'SUCCESS' : 'FAILURE'; |
22 | | - |
23 | | - return { |
24 | | - id: 'mcp-server-initialization', |
25 | | - name: 'MCPServerInitialization', |
26 | | - description: 'Validates that MCP server properly responds to initialize request', |
27 | | - status, |
28 | | - timestamp: new Date().toISOString(), |
29 | | - specReferences: [{ id: 'MCP-Lifecycle', url: 'https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle' }], |
30 | | - details: { |
31 | | - expectedSpecVersion, |
32 | | - response: initializeResponse |
33 | | - }, |
34 | | - errorMessage: errors.length > 0 ? errors.join('; ') : undefined, |
35 | | - logs: errors.length > 0 ? errors : undefined |
36 | | - }; |
37 | | -} |
0 commit comments