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

Function connect

__tests__/mcp-opencode-tool-names.test.ts:86–105  ·  view source on GitHub ↗

A session on `engine`, driven the way a transport drives it.

(engine: MCPEngine)

Source from the content-addressed store, hash-verified

84
85/** A session on `engine`, driven the way a transport drives it. */
86function connect(engine: MCPEngine) {
87 let handle: ((m: JsonRpcRequest | JsonRpcNotification) => Promise<void>) | null = null;
88 const replies = new Map<unknown, any>();
89 const transport: JsonRpcTransport = {
90 start(h) { handle = h as typeof handle; },
91 stop() { /* nothing to tear down */ },
92 send() { /* unused */ },
93 notify() { /* unused */ },
94 async request() { return {}; },
95 sendResult(id, result) { replies.set(id, result); },
96 sendError(id, code, message) { replies.set(id, { error: { code, message } }); },
97 };
98 new MCPSession(transport, engine).start();
99 let nextId = 1;
100 return async (method: string, params?: unknown): Promise<any> => {
101 const id = nextId++;
102 await handle!({ jsonrpc: '2.0', id, method, params } as JsonRpcRequest);
103 return replies.get(id);
104 };
105}
106
107function initializeParams(clientInfo: object | undefined, root: string): object {
108 return {

Callers 1

Calls 2

startMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected