fix: show mcp search results in visible text
This commit is contained in:
@@ -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,16 +367,7 @@ async function main() {
|
||||
eventBefore: event_before,
|
||||
});
|
||||
|
||||
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) => ({
|
||||
const mappedNodes = result.nodes.map((node) => ({
|
||||
id: node.id,
|
||||
title: node.title,
|
||||
source: node.source ?? null,
|
||||
@@ -381,8 +376,19 @@ async function main() {
|
||||
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: result.count === 0 ? summary : withVisibleJson(summary, payload) }],
|
||||
structuredContent: payload
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
+21
-10
@@ -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.`;
|
||||
|
||||
return {
|
||||
content: [{ type: 'text', text: summary }],
|
||||
structuredContent: {
|
||||
count: nodes.length,
|
||||
nodes: nodes.map((node) => ({
|
||||
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: 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
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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.`;
|
||||
|
||||
return {
|
||||
content: [{ type: 'text', text: summary }],
|
||||
structuredContent: {
|
||||
count: nodes.length,
|
||||
nodes: nodes.map((node) => ({
|
||||
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: 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
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user