-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-mcp-server.mjs
More file actions
72 lines (58 loc) · 1.73 KB
/
check-mcp-server.mjs
File metadata and controls
72 lines (58 loc) · 1.73 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
import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs';
const serverPath = 'dist/mcp/server.js';
if (!existsSync(serverPath)) {
console.error(`${serverPath} is missing. Run pnpm build first.`);
process.exit(1);
}
const child = spawn(process.execPath, [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
});
let stdout = '';
let stderr = '';
child.stdout.on('data', chunk => {
stdout += chunk;
});
child.stderr.on('data', chunk => {
stderr += chunk;
});
child.stdin.end(
[
JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize', params: {} }),
JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'resources/list', params: {} }),
JSON.stringify({
jsonrpc: '2.0',
id: 3,
method: 'resources/read',
params: { uri: 'react-timer-hook://api' },
}),
'',
].join('\n'),
);
const timeout = setTimeout(() => {
child.kill('SIGTERM');
console.error('MCP server check timed out.');
process.exit(1);
}, 2000);
child.on('close', code => {
clearTimeout(timeout);
if (code !== 0) {
console.error(stderr || `MCP server exited with code ${code}.`);
process.exit(1);
}
const responses = stdout
.trim()
.split('\n')
.filter(Boolean)
.map(line => JSON.parse(line));
const list = responses.find(response => response.id === 2)?.result?.resources ?? [];
const api = responses.find(response => response.id === 3)?.result?.contents?.[0]?.text ?? '';
if (list.length !== 3) {
console.error(`Expected 3 MCP resources, received ${list.length}.`);
process.exit(1);
}
if (!api.includes('@crup/react-timer-hook') || !api.includes('useTimerGroup')) {
console.error('MCP API resource is missing expected package context.');
process.exit(1);
}
});