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

Function collectMessages

__tests__/mcp-roots.test.ts:36–50  ·  view source on GitHub ↗

Parse every JSON-RPC message the server writes to stdout into an array.

(child: ChildProcessWithoutNullStreams)

Source from the content-addressed store, hash-verified

34
35/** Parse every JSON-RPC message the server writes to stdout into an array. */
36function collectMessages(child: ChildProcessWithoutNullStreams): Array<Record<string, any>> {
37 const messages: Array<Record<string, any>> = [];
38 let buf = '';
39 child.stdout.on('data', (chunk) => {
40 buf += chunk.toString('utf8');
41 let idx;
42 while ((idx = buf.indexOf('\n')) !== -1) {
43 const line = buf.slice(0, idx).trim();
44 buf = buf.slice(idx + 1);
45 if (!line) continue;
46 try { messages.push(JSON.parse(line)); } catch { /* ignore non-JSON */ }
47 }
48 });
49 return messages;
50}
51
52function waitForMessage(
53 messages: ReadonlyArray<Record<string, any>>,

Callers 1

mcp-roots.test.tsFile · 0.85

Calls 1

onMethod · 0.65

Tested by

no test coverage detected