From 9ec26db660fa6daa3047b81bfdf3ab7a45c92326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBeeRad=E2=80=9D?= Date: Mon, 27 Apr 2026 15:11:12 +1000 Subject: [PATCH] fix: show mcp search results in visible text --- apps/mcp-server-standalone/index.js | 38 ++++++++++++++++------------ apps/mcp-server/server.js | 39 ++++++++++++++++++----------- apps/mcp-server/stdio-server.js | 39 ++++++++++++++++++----------- 3 files changed, 72 insertions(+), 44 deletions(-) diff --git a/apps/mcp-server-standalone/index.js b/apps/mcp-server-standalone/index.js index b4caa94..8174420 100644 --- a/apps/mcp-server-standalone/index.js +++ b/apps/mcp-server-standalone/index.js @@ -235,6 +235,10 @@ function log(...args) { console.error('[ra-h-standalone]', ...args); } +function withVisibleJson(summary, payload) { + return `${summary}\n\n${JSON.stringify(payload, null, 2)}`; +} + async function main() { // Initialize database try { @@ -307,7 +311,7 @@ async function main() { : result.reason; return { - content: [{ type: 'text', text: summary }], + content: [{ type: 'text', text: result.shouldRetrieve ? withVisibleJson(summary, result) : summary }], structuredContent: result }; } @@ -363,26 +367,28 @@ async function main() { eventBefore: event_before, }); + const mappedNodes = result.nodes.map((node) => ({ + id: node.id, + title: node.title, + source: node.source ?? null, + description: node.description ?? null, + link: node.link ?? null, + created_at: node.created_at, + updated_at: node.updated_at, + event_date: node.event_date ?? null, + })); + const payload = { + count: result.count, + filters_applied: result.filtersApplied, + nodes: mappedNodes + }; const summary = result.count === 0 ? 'No nodes found matching that query.' : `Found ${result.count} node(s).`; return { - content: [{ type: 'text', text: summary }], - structuredContent: { - count: result.count, - filters_applied: result.filtersApplied, - nodes: result.nodes.map((node) => ({ - id: node.id, - title: node.title, - source: node.source ?? null, - description: node.description ?? null, - link: node.link ?? null, - created_at: node.created_at, - updated_at: node.updated_at, - event_date: node.event_date ?? null, - })) - } + content: [{ type: 'text', text: result.count === 0 ? summary : withVisibleJson(summary, payload) }], + structuredContent: payload }; } ); diff --git a/apps/mcp-server/server.js b/apps/mcp-server/server.js index 0e5d7f8..fa81ba0 100644 --- a/apps/mcp-server/server.js +++ b/apps/mcp-server/server.js @@ -370,6 +370,10 @@ async function callRaHApi(pathname, options = {}) { } } +function withVisibleJson(summary, payload) { + return `${summary}\n\n${JSON.stringify(payload, null, 2)}`; +} + mcpServer.registerTool( 'rah_add_node', { @@ -431,20 +435,22 @@ mcpServer.registerTool( const summary = nodes.length === 0 ? 'No existing RA-H nodes mention that topic yet.' : `Found ${nodes.length} node(s) mentioning that topic.`; + const mappedNodes = nodes.map((node) => ({ + id: node.id, + title: node.title, + source: node.source ?? null, + description: node.description ?? null, + link: node.link ?? null, + updated_at: node.updated_at + })); + const payload = { + count: nodes.length, + nodes: mappedNodes + }; return { - content: [{ type: 'text', text: summary }], - structuredContent: { - count: nodes.length, - nodes: nodes.map((node) => ({ - id: node.id, - title: node.title, - source: node.source ?? null, - description: node.description ?? null, - link: node.link ?? null, - updated_at: node.updated_at - })) - } + content: [{ type: 'text', text: nodes.length === 0 ? summary : withVisibleJson(summary, payload) }], + structuredContent: payload }; } ); @@ -467,9 +473,14 @@ mcpServer.registerTool( }) }); + const data = result.data; + const summary = data.shouldRetrieve + ? `Retrieved ${data.nodes.length} node(s) and ${data.chunks.length} chunk(s) for this turn.` + : data.reason; + return { - content: [{ type: 'text', text: result.data.shouldRetrieve ? `Retrieved ${result.data.nodes.length} node(s) and ${result.data.chunks.length} chunk(s) for this turn.` : result.data.reason }], - structuredContent: result.data + content: [{ type: 'text', text: data.shouldRetrieve ? withVisibleJson(summary, data) : summary }], + structuredContent: data }; } ); diff --git a/apps/mcp-server/stdio-server.js b/apps/mcp-server/stdio-server.js index 363b4dd..3b7165a 100644 --- a/apps/mcp-server/stdio-server.js +++ b/apps/mcp-server/stdio-server.js @@ -335,6 +335,10 @@ async function callRaHApi(pathname, options = {}) { return body; } +function withVisibleJson(summary, payload) { + return `${summary}\n\n${JSON.stringify(payload, null, 2)}`; +} + server.registerTool( 'rah_add_node', { @@ -397,20 +401,22 @@ server.registerTool( nodes.length === 0 ? 'No existing RA-H nodes mention that topic yet.' : `Found ${nodes.length} node(s) mentioning that topic.`; + const mappedNodes = nodes.map((node) => ({ + id: node.id, + title: node.title, + source: node.source ?? null, + description: node.description ?? null, + link: node.link ?? null, + updated_at: node.updated_at + })); + const payload = { + count: nodes.length, + nodes: mappedNodes + }; return { - content: [{ type: 'text', text: summary }], - structuredContent: { - count: nodes.length, - nodes: nodes.map((node) => ({ - id: node.id, - title: node.title, - source: node.source ?? null, - description: node.description ?? null, - link: node.link ?? null, - updated_at: node.updated_at - })) - } + content: [{ type: 'text', text: nodes.length === 0 ? summary : withVisibleJson(summary, payload) }], + structuredContent: payload }; } ); @@ -433,9 +439,14 @@ server.registerTool( }) }); + const data = result.data; + const summary = data.shouldRetrieve + ? `Retrieved ${data.nodes.length} node(s) and ${data.chunks.length} chunk(s) for this turn.` + : data.reason; + return { - content: [{ type: 'text', text: result.data.shouldRetrieve ? `Retrieved ${result.data.nodes.length} node(s) and ${result.data.chunks.length} chunk(s) for this turn.` : result.data.reason }], - structuredContent: result.data + content: [{ type: 'text', text: data.shouldRetrieve ? withVisibleJson(summary, data) : summary }], + structuredContent: data }; } );