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

Function connect

__tests__/security.test.ts:704–736  ·  view source on GitHub ↗

An MCP client in this process, on a new session of `engine`; roots/list answers `roots`.

(engine: Engine, roots: string[] = [])

Source from the content-addressed store, hash-verified

702
703 /** An MCP client in this process, on a new session of `engine`; roots/list answers `roots`. */
704 function connect(engine: Engine, roots: string[] = []) {
705 let deliver: ((message: object) => Promise<void>) | null = null;
706 const replies = new Map<number, Reply>();
707 const asked: string[] = [];
708 const transport = {
709 start: (handler: (message: object) => Promise<void>) => { deliver = handler; },
710 stop: () => {},
711 send: () => {},
712 notify: () => {},
713 request: async (method: string) => {
714 asked.push(method);
715 return method === 'roots/list'
716 ? { roots: roots.map((root) => ({ uri: pathToFileURL(root).href, name: path.basename(root) })) }
717 : {};
718 },
719 sendResult: (id: number, result: Reply) => { replies.set(id, result); },
720 sendError: (id: number, _code: number, message: string) => {
721 replies.set(id, { isError: true, content: [{ text: message }] });
722 },
723 };
724 new MCPSession(transport as never, engine).start();
725 let nextId = 0;
726 const call = async (method: string, params: object): Promise<Reply> => {
727 const id = nextId++;
728 await deliver!({ jsonrpc: '2.0', id, method, params });
729 return replies.get(id)!;
730 };
731 const initialize = (params: object = {}) =>
732 call('initialize', { protocolVersion: '2025-11-25', capabilities: {}, clientInfo: { name: 'test', version: '0' }, ...params });
733 const node = (symbol: string) =>
734 call('tools/call', { name: 'codegraph_node', arguments: { symbol, includeCode: true } });
735 return { call, initialize, node, asked };
736 }
737
738 it('does not open, watch or sync a sensitive folder as the default project', async () => {
739 const viaLink = link(config, path.join(state.tmp, 'elsewhere', 'config'));

Callers 2

security.test.tsFile · 0.70

Calls 4

pushMethod · 0.80
mapMethod · 0.80
startMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected