| 34 | } |
| 35 | |
| 36 | async function extractToolsFromServer() { |
| 37 | return new Promise((resolve, reject) => { |
| 38 | // Start the MCP server |
| 39 | const serverPath = join(rootDir, 'dist', 'index.js'); |
| 40 | const server = spawn('node', [serverPath], { |
| 41 | stdio: ['pipe', 'pipe', 'pipe'] |
| 42 | }); |
| 43 | |
| 44 | let output = ''; |
| 45 | let errorOutput = ''; |
| 46 | const messages = []; |
| 47 | |
| 48 | server.stdout.on('data', (data) => { |
| 49 | output += data.toString(); |
| 50 | |
| 51 | // Try to parse each line as JSON-RPC message |
| 52 | const lines = output.split('\n'); |
| 53 | output = lines.pop() || ''; // Keep incomplete line |
| 54 | |
| 55 | for (const line of lines) { |
| 56 | if (line.trim()) { |
| 57 | try { |
| 58 | messages.push(JSON.parse(line)); |
| 59 | } catch (e) { |
| 60 | // Not JSON, might be debug output |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | server.stderr.on('data', (data) => { |
| 67 | errorOutput += data.toString(); |
| 68 | }); |
| 69 | |
| 70 | // Step 1: Send initialize request |
| 71 | const initRequest = { |
| 72 | jsonrpc: '2.0', |
| 73 | id: 1, |
| 74 | method: 'initialize', |
| 75 | params: { |
| 76 | protocolVersion: '2024-11-05', |
| 77 | capabilities: {}, |
| 78 | clientInfo: { |
| 79 | name: 'validate-tools-sync', |
| 80 | version: '1.0.0' |
| 81 | } |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | server.stdin.write(JSON.stringify(initRequest) + '\n'); |
| 86 | |
| 87 | // Wait for initialize response, then send tools/list |
| 88 | setTimeout(() => { |
| 89 | // Step 2: Send tools/list request |
| 90 | const toolsRequest = { |
| 91 | jsonrpc: '2.0', |
| 92 | id: 2, |
| 93 | method: 'tools/list', |