return the JSON stringified parameters from getDescription for MCP tools and Discovered tools (#6655)

This commit is contained in:
Jacob MacDonald 2025-08-20 13:10:02 -07:00 committed by GitHub
parent 4642de2a5c
commit 1738d40745
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 2 deletions

View File

@ -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"}');
});
});
}); });

View File

@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { safeJsonStringify } from '../utils/safeJsonStringify.js';
import { import {
BaseDeclarativeTool, BaseDeclarativeTool,
BaseToolInvocation, BaseToolInvocation,
@ -152,7 +153,7 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
} }
getDescription(): string { getDescription(): string {
return this.displayName; return safeJsonStringify(this.params);
} }
} }

View File

@ -332,4 +332,14 @@ describe('ToolRegistry', () => {
expect(discoverSpy).toHaveBeenCalled(); 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));
});
});
}); });

View File

@ -20,6 +20,7 @@ import { connectAndDiscover } from './mcp-client.js';
import { McpClientManager } from './mcp-client-manager.js'; import { McpClientManager } from './mcp-client-manager.js';
import { DiscoveredMCPTool } from './mcp-tool.js'; import { DiscoveredMCPTool } from './mcp-tool.js';
import { parse } from 'shell-quote'; import { parse } from 'shell-quote';
import { safeJsonStringify } from '../utils/safeJsonStringify.js';
type ToolParams = Record<string, unknown>; type ToolParams = Record<string, unknown>;
@ -36,7 +37,7 @@ class DiscoveredToolInvocation extends BaseToolInvocation<
} }
getDescription(): string { getDescription(): string {
return `Calling discovered tool: ${this.toolName}`; return safeJsonStringify(this.params);
} }
async execute( async execute(

View File

@ -24,6 +24,7 @@ export interface ToolInvocation<
/** /**
* Gets a pre-execution description of the tool operation. * Gets a pre-execution description of the tool operation.
*
* @returns A markdown string describing what the tool will do. * @returns A markdown string describing what the tool will do.
*/ */
getDescription(): string; getDescription(): string;