Skip to content

Commit abf77e7

Browse files
sternbergmJoshMock
andauthored
feat: Add aggregation results to search tool output (#46)
adding aggregationsFragment to the returned content when it is available. Co-authored-by: Josh Mock <[email protected]>
1 parent 02703f1 commit abf77e7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,18 @@ export async function createElasticsearchMcpServer(
388388
: result.hits.total?.value || 0
389389
}, showing ${result.hits.hits.length} from position ${from}`,
390390
};
391+
// Check if there are any aggregations in the result and include them
392+
const aggregationsFragment = result.aggregations
393+
? {
394+
type: "text" as const,
395+
text: `Aggregations: ${JSON.stringify(result.aggregations, null, 2)}`,
396+
}
397+
: null;
391398

392399
return {
393-
content: [metadataFragment, ...contentFragments],
400+
content: aggregationsFragment
401+
? [metadataFragment, aggregationsFragment, ...contentFragments]
402+
: [metadataFragment, ...contentFragments],
394403
};
395404
} catch (error) {
396405
console.error(

0 commit comments

Comments
 (0)