From aa12d1750455b3f4e3837feff419b9fcc8da7eab Mon Sep 17 00:00:00 2001 From: Paul Robello Date: Mon, 23 Feb 2026 07:23:46 -0800 Subject: [PATCH] refactor(api): use executeCypher directly in buildGraph Add public executeCypher(repoName, query) method to LocalBackend, bypassing the callTool string dispatch and resolving the repo handle directly. Update buildGraph in api.ts to call it instead of going through callTool('cypher', ...) on every query. --- gitnexus/src/mcp/local/local-backend.ts | 5 +++++ gitnexus/src/server/api.ts | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gitnexus/src/mcp/local/local-backend.ts b/gitnexus/src/mcp/local/local-backend.ts index b0beff286..9ae45ee6a 100644 --- a/gitnexus/src/mcp/local/local-backend.ts +++ b/gitnexus/src/mcp/local/local-backend.ts @@ -636,6 +636,11 @@ export class LocalBackend { } } + async executeCypher(repoName: string, query: string): Promise { + const repo = await this.resolveRepo(repoName); + return this.cypher(repo, { query }); + } + private async cypher(repo: RepoHandle, params: { query: string }): Promise { await this.ensureInitialized(repo.id); diff --git a/gitnexus/src/server/api.ts b/gitnexus/src/server/api.ts index 374c66b10..fbe0ebcd6 100644 --- a/gitnexus/src/server/api.ts +++ b/gitnexus/src/server/api.ts @@ -39,7 +39,7 @@ const buildGraph = async ( query = `MATCH (n:${table}) RETURN n.id AS id, n.name AS name, n.filePath AS filePath, n.startLine AS startLine, n.endLine AS endLine, n.content AS content`; } - const result = await backend.callTool('cypher', { repo: repoName, query }); + const result = await backend.executeCypher(repoName, query); // cypher returns the rows directly (array), or { error } on failure const rows = Array.isArray(result) ? result : []; @@ -71,10 +71,10 @@ const buildGraph = async ( const relationships: GraphRelationship[] = []; try { - const relResult = await backend.callTool('cypher', { - repo: repoName, - query: `MATCH (a)-[r:CodeRelation]->(b) RETURN a.id AS sourceId, b.id AS targetId, r.type AS type, r.confidence AS confidence, r.reason AS reason, r.step AS step`, - }); + const relResult = await backend.executeCypher( + repoName, + `MATCH (a)-[r:CodeRelation]->(b) RETURN a.id AS sourceId, b.id AS targetId, r.type AS type, r.confidence AS confidence, r.reason AS reason, r.step AS step`, + ); const relRows = Array.isArray(relResult) ? relResult : []; for (const row of relRows) {