MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / makeClient

Function makeClient

scripts/agent-eval/repro-daemon-clients.mjs:39–70  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

37];
38
39function makeClient(id) {
40 const child = spawn('node', [CLI, 'serve', '--mcp', '--path', repo], {
41 env: { ...process.env, CODEGRAPH_TELEMETRY: '0', DO_NOT_TRACK: '1', CODEGRAPH_MCP_LOG_ATTACH: '0' },
42 stdio: ['pipe', 'pipe', 'inherit'],
43 });
44 let buf = '';
45 const waiters = new Map(); // id -> resolve
46 child.stdout.setEncoding('utf8');
47 child.stdout.on('data', (chunk) => {
48 buf += chunk;
49 let idx;
50 while ((idx = buf.indexOf('\n')) !== -1) {
51 const line = buf.slice(0, idx).trim();
52 buf = buf.slice(idx + 1);
53 if (!line) continue;
54 let msg; try { msg = JSON.parse(line); } catch { continue; }
55 if (msg.id !== undefined && waiters.has(msg.id)) {
56 waiters.get(msg.id)(msg);
57 waiters.delete(msg.id);
58 }
59 }
60 });
61 const send = (obj) => child.stdin.write(JSON.stringify(obj) + '\n');
62 const request = (method, params, rpcId, timeoutMs) =>
63 new Promise((res) => {
64 let timer;
65 if (timeoutMs) timer = setTimeout(() => { waiters.delete(rpcId); res({ __timeout: true }); }, timeoutMs);
66 waiters.set(rpcId, (m) => { if (timer) clearTimeout(timer); res(m); });
67 send({ jsonrpc: '2.0', id: rpcId, method, params });
68 });
69 return { id, child, send, request };
70}
71
72const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
73

Callers 1

Calls 3

hasMethod · 0.80
onMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected