From 1738d407456aec9ab7733374a4709cff6d59d12d Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Wed, 20 Aug 2025 13:10:02 -0700 Subject: [PATCH] return the JSON stringified parameters from getDescription for MCP tools and Discovered tools (#6655) --- packages/core/src/tools/mcp-tool.test.ts | 9 +++++++++ packages/core/src/tools/mcp-tool.ts | 3 ++- packages/core/src/tools/tool-registry.test.ts | 10 ++++++++++ packages/core/src/tools/tool-registry.ts | 3 ++- packages/core/src/tools/tools.ts | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/core/src/tools/mcp-tool.test.ts b/packages/core/src/tools/mcp-tool.test.ts index 3a8c10c4..d5e4eee8 100644 --- a/packages/core/src/tools/mcp-tool.test.ts +++ b/packages/core/src/tools/mcp-tool.test.ts @@ -743,4 +743,13 @@ describe('DiscoveredMCPTool', () => { } }); }); + + describe('DiscoveredMCPToolInvocation', () => { + it('should return the stringified params from getDescription', () => { + const params = { param: 'testValue', param2: 'anotherOne' }; + const invocation = tool.build(params); + const description = invocation.getDescription(); + expect(description).toBe('{"param":"testValue","param2":"anotherOne"}'); + }); + }); }); diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts index 64952dd1..baa517f6 100644 --- a/packages/core/src/tools/mcp-tool.ts +++ b/packages/core/src/tools/mcp-tool.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { safeJsonStringify } from '../utils/safeJsonStringify.js'; import { BaseDeclarativeTool, BaseToolInvocation, @@ -152,7 +153,7 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation< } getDescription(): string { - return this.displayName; + return safeJsonStringify(this.params); } } diff --git a/packages/core/src/tools/tool-registry.test.ts b/packages/core/src/tools/tool-registry.test.ts index cccf011f..6db60377 100644 --- a/packages/core/src/tools/tool-registry.test.ts +++ b/packages/core/src/tools/tool-registry.test.ts @@ -332,4 +332,14 @@ describe('ToolRegistry', () => { expect(discoverSpy).toHaveBeenCalled(); }); }); + + describe('DiscoveredToolInvocation', () => { + it('should return the stringified params from getDescription', () => { + const tool = new DiscoveredTool(config, 'test-tool', 'A test tool', {}); + const params = { param: 'testValue' }; + const invocation = tool.build(params); + const description = invocation.getDescription(); + expect(description).toBe(JSON.stringify(params)); + }); + }); }); diff --git a/packages/core/src/tools/tool-registry.ts b/packages/core/src/tools/tool-registry.ts index 90531742..7acd778d 100644 --- a/packages/core/src/tools/tool-registry.ts +++ b/packages/core/src/tools/tool-registry.ts @@ -20,6 +20,7 @@ import { connectAndDiscover } from './mcp-client.js'; import { McpClientManager } from './mcp-client-manager.js'; import { DiscoveredMCPTool } from './mcp-tool.js'; import { parse } from 'shell-quote'; +import { safeJsonStringify } from '../utils/safeJsonStringify.js'; type ToolParams = Record; @@ -36,7 +37,7 @@ class DiscoveredToolInvocation extends BaseToolInvocation< } getDescription(): string { - return `Calling discovered tool: ${this.toolName}`; + return safeJsonStringify(this.params); } async execute( diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index 761b670a..64a2e83a 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -24,6 +24,7 @@ export interface ToolInvocation< /** * Gets a pre-execution description of the tool operation. + * * @returns A markdown string describing what the tool will do. */ getDescription(): string;