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

Function onData

src/mcp/proxy.ts:665–693  ·  view source on GitHub ↗
(chunk: string | Buffer)

Source from the content-addressed store, hash-verified

663 clearTimeout(timer);
664 };
665 const onData = (chunk: string | Buffer) => {
666 buffer += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
667 const idx = buffer.indexOf('\n');
668 if (idx === -1) {
669 if (buffer.length > MAX_HELLO_LINE_BYTES) {
670 cleanup();
671 reject(new Error('daemon hello line exceeded size limit'));
672 }
673 return;
674 }
675 const line = buffer.slice(0, idx);
676 // Re-emit anything past the newline so the pipe-stage sees it.
677 const tail = buffer.slice(idx + 1);
678 cleanup();
679 if (tail.length > 0) {
680 // Push back via unshift — Node's net.Socket supports it on readable streams.
681 socket.unshift(tail);
682 }
683 try {
684 const parsed = JSON.parse(line) as DaemonHello;
685 if (typeof parsed.codegraph !== 'string' || typeof parsed.pid !== 'number') {
686 reject(new Error('daemon hello missing required fields'));
687 return;
688 }
689 resolve(parsed);
690 } catch (err) {
691 reject(new Error(`daemon hello not JSON: ${err instanceof Error ? err.message : String(err)}`));
692 }
693 };
694 const onError = (err: Error) => { cleanup(); reject(err); };
695 const onClose = () => { cleanup(); reject(new Error('daemon closed connection before hello')); };
696 const timer = setTimeout(() => {

Callers

nothing calls this directly

Calls 3

parseMethod · 0.80
cleanupFunction · 0.70
resolveFunction · 0.50

Tested by

no test coverage detected