From c81148a0cc8489f657901c2cc7247c0834075e1a Mon Sep 17 00:00:00 2001 From: Olcan Date: Fri, 30 May 2025 15:59:23 -0700 Subject: [PATCH] use json block for mcp tool output (and re-enable markdown rendering) (#635) --- packages/server/src/tools/mcp-tool.test.ts | 3 ++- packages/server/src/tools/mcp-tool.ts | 7 ++++--- packages/server/src/tools/tool-registry.test.ts | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/server/src/tools/mcp-tool.test.ts b/packages/server/src/tools/mcp-tool.test.ts index 331696f7..5c784c5d 100644 --- a/packages/server/src/tools/mcp-tool.test.ts +++ b/packages/server/src/tools/mcp-tool.test.ts @@ -116,7 +116,8 @@ describe('DiscoveredMCPTool', () => { timeout: MCP_TOOL_DEFAULT_TIMEOUT_MSEC, }, ); - const expectedOutput = JSON.stringify(expectedMcpResult, null, 2); + const expectedOutput = + '```json\n' + JSON.stringify(expectedMcpResult, null, 2) + '\n```'; expect(result.llmContent).toBe(expectedOutput); expect(result.returnDisplay).toBe(expectedOutput); }); diff --git a/packages/server/src/tools/mcp-tool.ts b/packages/server/src/tools/mcp-tool.ts index 80e6bbde..d02b8632 100644 --- a/packages/server/src/tools/mcp-tool.ts +++ b/packages/server/src/tools/mcp-tool.ts @@ -42,7 +42,7 @@ Returns the MCP server response as a json string. name, description, parameterSchema, - false, // isOutputMarkdown + true, // isOutputMarkdown false, // canUpdateOutput ); } @@ -93,9 +93,10 @@ Returns the MCP server response as a json string. timeout: this.timeout ?? MCP_TOOL_DEFAULT_TIMEOUT_MSEC, }, ); + const output = '```json\n' + JSON.stringify(result, null, 2) + '\n```'; return { - llmContent: JSON.stringify(result, null, 2), - returnDisplay: JSON.stringify(result, null, 2), + llmContent: output, + returnDisplay: output, }; } } diff --git a/packages/server/src/tools/tool-registry.test.ts b/packages/server/src/tools/tool-registry.test.ts index c93109ae..121e91c8 100644 --- a/packages/server/src/tools/tool-registry.test.ts +++ b/packages/server/src/tools/tool-registry.test.ts @@ -768,7 +768,8 @@ describe('DiscoveredMCPTool', () => { timeout: 10 * 60 * 1000, }, ); - const expectedOutput = JSON.stringify(mcpResult, null, 2); + const expectedOutput = + '```json\n' + JSON.stringify(mcpResult, null, 2) + '\n```'; expect(result.llmContent).toBe(expectedOutput); expect(result.returnDisplay).toBe(expectedOutput); });