summaryrefslogtreecommitdiff
path: root/packages/core/src/tools
diff options
context:
space:
mode:
authorN. Taylor Mullen <[email protected]>2025-06-04 00:24:25 -0700
committerGitHub <[email protected]>2025-06-04 07:24:25 +0000
commitd179b3aae41b466a5e75ac4392d5a5ad88ffffb0 (patch)
tree1e72ecd6126c13b9b14801dcda64e7c1b1cb9911 /packages/core/src/tools
parent4b2af10b0478fc8f92fe848019a0bc2d8943ed88 (diff)
refactor(core): Centralize tool response formatting (#743)
Diffstat (limited to 'packages/core/src/tools')
-rw-r--r--packages/core/src/tools/mcp-tool.test.ts7
-rw-r--r--packages/core/src/tools/mcp-tool.ts9
2 files changed, 9 insertions, 7 deletions
diff --git a/packages/core/src/tools/mcp-tool.test.ts b/packages/core/src/tools/mcp-tool.test.ts
index 86968b3d..fc6ce6be 100644
--- a/packages/core/src/tools/mcp-tool.test.ts
+++ b/packages/core/src/tools/mcp-tool.test.ts
@@ -138,12 +138,7 @@ describe('DiscoveredMCPTool', () => {
const stringifiedResponseContent = JSON.stringify(
mockToolSuccessResultObject,
);
- // getStringifiedResultForDisplay joins text parts, then wraps the array of processed parts in JSON
- const expectedDisplayOutput =
- '```json\n' +
- JSON.stringify([stringifiedResponseContent], null, 2) +
- '\n```';
- expect(toolResult.returnDisplay).toBe(expectedDisplayOutput);
+ expect(toolResult.returnDisplay).toBe(stringifiedResponseContent);
});
it('should handle empty result from getStringifiedResultForDisplay', async () => {
diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts
index 65c0cae8..8a7694d8 100644
--- a/packages/core/src/tools/mcp-tool.ts
+++ b/packages/core/src/tools/mcp-tool.ts
@@ -149,6 +149,13 @@ function getStringifiedResultForDisplay(result: Part[]) {
return part; // Fallback for unexpected structure or non-FunctionResponsePart
};
- const processedResults = result.map(processFunctionResponse);
+ const processedResults =
+ result.length === 1
+ ? processFunctionResponse(result[0])
+ : result.map(processFunctionResponse);
+ if (typeof processedResults === 'string') {
+ return processedResults;
+ }
+
return '```json\n' + JSON.stringify(processedResults, null, 2) + '\n```';
}