fix(MCP Client Tool Node): Stringify tool result (#14554)

This commit is contained in:
Elias Meire
2025-04-14 21:22:07 +02:00
committed by GitHub
parent 7723a138a1
commit 390c508946
3 changed files with 7 additions and 4 deletions

View File

@@ -57,7 +57,7 @@ describe('McpClientTool', () => {
jest.resetAllMocks(); jest.resetAllMocks();
}); });
it('should return a valid toolkit with usable tools', async () => { it('should return a valid toolkit with usable tools (that returns a string)', async () => {
jest.spyOn(Client.prototype, 'connect').mockResolvedValue(); jest.spyOn(Client.prototype, 'connect').mockResolvedValue();
jest jest
.spyOn(Client.prototype, 'callTool') .spyOn(Client.prototype, 'callTool')
@@ -93,7 +93,7 @@ describe('McpClientTool', () => {
expect(tools).toHaveLength(2); expect(tools).toHaveLength(2);
const toolCallResult = await tools[0].invoke({ input: 'foo' }); const toolCallResult = await tools[0].invoke({ input: 'foo' });
expect(toolCallResult).toEqual([{ type: 'text', text: 'result from tool' }]); expect(toolCallResult).toEqual(JSON.stringify([{ type: 'text', text: 'result from tool' }]));
}); });
it('should support selecting tools to expose', async () => { it('should support selecting tools to expose', async () => {

View File

@@ -120,7 +120,8 @@ export class McpServer {
return { return {
name: tool.name, name: tool.name,
description: tool.description, description: tool.description,
inputSchema: zodToJsonSchema(tool.schema), // Allow additional properties on tool call input
inputSchema: zodToJsonSchema(tool.schema, { removeAdditionalStrategy: 'strict' }),
}; };
}), }),
}; };

View File

@@ -395,7 +395,9 @@ export function logWrapper<
logAiEvent(executeFunctions, 'ai-tool-called', { ...inputData, response }); logAiEvent(executeFunctions, 'ai-tool-called', { ...inputData, response });
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
return response;
if (typeof response === 'string') return response;
return JSON.stringify(response);
}; };
} }
} }