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);
|
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,16 +367,7 @@ async function main() {
|
|||||||
eventBefore: event_before,
|
eventBefore: event_before,
|
||||||
});
|
});
|
||||||
|
|
||||||
const summary = result.count === 0
|
const mappedNodes = result.nodes.map((node) => ({
|
||||||
? '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,
|
id: node.id,
|
||||||
title: node.title,
|
title: node.title,
|
||||||
source: node.source ?? null,
|
source: node.source ?? null,
|
||||||
@@ -381,8 +376,19 @@ async function main() {
|
|||||||
created_at: node.created_at,
|
created_at: node.created_at,
|
||||||
updated_at: node.updated_at,
|
updated_at: node.updated_at,
|
||||||
event_date: node.event_date ?? null,
|
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(
|
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) => ({
|
||||||
return {
|
|
||||||
content: [{ type: 'text', text: summary }],
|
|
||||||
structuredContent: {
|
|
||||||
count: nodes.length,
|
|
||||||
nodes: nodes.map((node) => ({
|
|
||||||
id: node.id,
|
id: node.id,
|
||||||
title: node.title,
|
title: node.title,
|
||||||
source: node.source ?? null,
|
source: node.source ?? null,
|
||||||
description: node.description ?? null,
|
description: node.description ?? null,
|
||||||
link: node.link ?? null,
|
link: node.link ?? null,
|
||||||
updated_at: node.updated_at
|
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 {
|
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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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) => ({
|
||||||
return {
|
|
||||||
content: [{ type: 'text', text: summary }],
|
|
||||||
structuredContent: {
|
|
||||||
count: nodes.length,
|
|
||||||
nodes: nodes.map((node) => ({
|
|
||||||
id: node.id,
|
id: node.id,
|
||||||
title: node.title,
|
title: node.title,
|
||||||
source: node.source ?? null,
|
source: node.source ?? null,
|
||||||
description: node.description ?? null,
|
description: node.description ?? null,
|
||||||
link: node.link ?? null,
|
link: node.link ?? null,
|
||||||
updated_at: node.updated_at
|
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 {
|
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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user