fix: show mcp search results in visible text

This commit is contained in:
“BeeRad”
2026-04-27 15:11:12 +10:00
parent ceaace1f4a
commit 9ec26db660
3 changed files with 72 additions and 44 deletions
+22 -16
View File
@@ -235,6 +235,10 @@ function log(...args) {
console.error('[ra-h-standalone]', ...args); console.error('[ra-h-standalone]', ...args);
} }
function withVisibleJson(summary, payload) {
return `${summary}\n\n${JSON.stringify(payload, null, 2)}`;
}
async function main() { async function main() {
// Initialize database // Initialize database
try { try {
@@ -307,7 +311,7 @@ async function main() {
: result.reason; : result.reason;
return { return {
content: [{ type: 'text', text: summary }], content: [{ type: 'text', text: result.shouldRetrieve ? withVisibleJson(summary, result) : summary }],
structuredContent: result structuredContent: result
}; };
} }
@@ -363,26 +367,28 @@ async function main() {
eventBefore: event_before, 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 const summary = result.count === 0
? 'No nodes found matching that query.' ? 'No nodes found matching that query.'
: `Found ${result.count} node(s).`; : `Found ${result.count} node(s).`;
return { return {
content: [{ type: 'text', text: summary }], content: [{ type: 'text', text: result.count === 0 ? summary : withVisibleJson(summary, payload) }],
structuredContent: { structuredContent: payload
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,
}))
}
}; };
} }
); );
+25 -14
View File
@@ -370,6 +370,10 @@ async function callRaHApi(pathname, options = {}) {
} }
} }
function withVisibleJson(summary, payload) {
return `${summary}\n\n${JSON.stringify(payload, null, 2)}`;
}
mcpServer.registerTool( mcpServer.registerTool(
'rah_add_node', 'rah_add_node',
{ {
@@ -431,20 +435,22 @@ mcpServer.registerTool(
const summary = nodes.length === 0 const summary = nodes.length === 0
? 'No existing RA-H nodes mention that topic yet.' ? 'No existing RA-H nodes mention that topic yet.'
: `Found ${nodes.length} node(s) mentioning that topic.`; : `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 { return {
content: [{ type: 'text', text: summary }], content: [{ type: 'text', text: nodes.length === 0 ? summary : withVisibleJson(summary, payload) }],
structuredContent: { structuredContent: payload
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
}))
}
}; };
} }
); );
@@ -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 { 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 }], content: [{ type: 'text', text: data.shouldRetrieve ? withVisibleJson(summary, data) : summary }],
structuredContent: result.data structuredContent: data
}; };
} }
); );
+25 -14
View File
@@ -335,6 +335,10 @@ async function callRaHApi(pathname, options = {}) {
return body; return body;
} }
function withVisibleJson(summary, payload) {
return `${summary}\n\n${JSON.stringify(payload, null, 2)}`;
}
server.registerTool( server.registerTool(
'rah_add_node', 'rah_add_node',
{ {
@@ -397,20 +401,22 @@ server.registerTool(
nodes.length === 0 nodes.length === 0
? 'No existing RA-H nodes mention that topic yet.' ? 'No existing RA-H nodes mention that topic yet.'
: `Found ${nodes.length} node(s) mentioning that topic.`; : `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 { return {
content: [{ type: 'text', text: summary }], content: [{ type: 'text', text: nodes.length === 0 ? summary : withVisibleJson(summary, payload) }],
structuredContent: { structuredContent: payload
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
}))
}
}; };
} }
); );
@@ -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 { 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 }], content: [{ type: 'text', text: data.shouldRetrieve ? withVisibleJson(summary, data) : summary }],
structuredContent: result.data structuredContent: data
}; };
} }
); );