-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathserver_initialize.ts
More file actions
82 lines (74 loc) · 3.24 KB
/
server_initialize.ts
File metadata and controls
82 lines (74 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { ClientScenario, ConformanceCheck } from '../../types.js';
import { serverChecks } from '../../checks/index.js';
export class ServerInitializeClientScenario implements ClientScenario {
name = 'server-initialize';
description = 'Acts as MCP client to test external server initialization';
async run(serverUrl: string): Promise<ConformanceCheck[]> {
const checks: ConformanceCheck[] = [];
try {
const response = await fetch(serverUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2025-06-18',
capabilities: {},
clientInfo: {
name: 'conformance-test-client',
version: '1.0.0'
}
}
})
});
if (!response.ok) {
const responseBody = await response.text();
throw new Error(`HTTP ${response.status}: ${response.statusText}. Response body: ${responseBody}`);
}
const responseText = await response.text();
// Handle SSE format
let result;
if (responseText.startsWith('event:') || responseText.includes('\ndata:')) {
// Parse SSE format - extract JSON from data: lines
const lines = responseText.split('\n');
const dataLines = lines.filter(line => line.startsWith('data: '));
if (dataLines.length > 0) {
const jsonData = dataLines[0].substring(6); // Remove 'data: ' prefix
result = JSON.parse(jsonData);
} else {
throw new Error(`SSE response without data line: ${responseText}`);
}
} else {
// Regular JSON response
result = JSON.parse(responseText);
}
const check = serverChecks.createServerInitializationCheck(result);
checks.push(check);
} catch (error) {
checks.push({
id: 'server-initialize-request',
name: 'ServerInitializeRequest',
description: 'Tests server response to initialize request',
status: 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage: `Failed to send initialize request: ${error instanceof Error ? error.message : String(error)}`,
details: {
error: error instanceof Error ? error.message : String(error),
serverUrl
},
specReferences: [
{
id: 'MCP-Initialize',
url: 'https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#initialization'
}
]
});
}
return checks;
}
}