From 7311a0187459e7a9f7de567ce917ed01578feb5b Mon Sep 17 00:00:00 2001 From: "mingholy.lmh" Date: Mon, 9 Feb 2026 11:54:20 +0800 Subject: [PATCH] fix: sdk mcp tests --- .../sdk-typescript/mcp-server.test.ts | 26 +++++++++++-------- .../sdk-typescript/sdk-mcp-server.test.ts | 23 +++++++++++----- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/integration-tests/sdk-typescript/mcp-server.test.ts b/integration-tests/sdk-typescript/mcp-server.test.ts index cf1de26d4e..3728124389 100644 --- a/integration-tests/sdk-typescript/mcp-server.test.ts +++ b/integration-tests/sdk-typescript/mcp-server.test.ts @@ -35,6 +35,10 @@ const SHARED_TEST_OPTIONS = { permissionMode: 'yolo' as const, }; +// MCP tool names are generated with the pattern: mcp____ +const MCP_ADD_TOOL = 'mcp__test-math-server__add'; +const MCP_MULTIPLY_TOOL = 'mcp__test-math-server__multiply'; + describe('MCP Server Integration (E2E)', () => { let helper: SDKTestHelper; let serverScriptPath: string; @@ -82,7 +86,7 @@ describe('MCP Server Integration (E2E)', () => { messages.push(message); if (isSDKAssistantMessage(message)) { - const toolUseBlocks = findToolUseBlocks(message, 'add'); + const toolUseBlocks = findToolUseBlocks(message, MCP_ADD_TOOL); if (toolUseBlocks.length > 0) { foundToolUse = true; } @@ -133,7 +137,7 @@ describe('MCP Server Integration (E2E)', () => { messages.push(message); if (isSDKAssistantMessage(message)) { - const toolUseBlocks = findToolUseBlocks(message, 'multiply'); + const toolUseBlocks = findToolUseBlocks(message, MCP_MULTIPLY_TOOL); if (toolUseBlocks.length > 0) { foundToolUse = true; } @@ -238,8 +242,8 @@ describe('MCP Server Integration (E2E)', () => { } // Validate both tools were called - expect(toolCalls).toContain('add'); - expect(toolCalls).toContain('multiply'); + expect(toolCalls).toContain(MCP_ADD_TOOL); + expect(toolCalls).toContain(MCP_MULTIPLY_TOOL); // Validate result: (10 + 5) * 2 = 30 expect(assistantText).toMatch(/30/); @@ -278,7 +282,7 @@ describe('MCP Server Integration (E2E)', () => { messages.push(message); if (isSDKAssistantMessage(message)) { - const toolUseBlocks = findToolUseBlocks(message, 'add'); + const toolUseBlocks = findToolUseBlocks(message, MCP_ADD_TOOL); addToolCalls.push(...toolUseBlocks); assistantText += extractText(message.message.content); } @@ -366,8 +370,8 @@ describe('MCP Server Integration (E2E)', () => { } } - expect(toolCalls).toContain('add'); - expect(toolCalls).toContain('multiply'); + expect(toolCalls).toContain(MCP_ADD_TOOL); + expect(toolCalls).toContain(MCP_MULTIPLY_TOOL); expect(assistantText).toMatch(/5/); expect(assistantText).toMatch(/20/); @@ -454,10 +458,10 @@ describe('MCP Server Integration (E2E)', () => { } } - expect(toolCalls).toContain('add'); - expect(toolCalls).toContain('multiply'); + expect(toolCalls).toContain(MCP_ADD_TOOL); + expect(toolCalls).toContain(MCP_MULTIPLY_TOOL); expect(canUseToolCalls.map((call) => call.toolName)).toEqual( - expect.arrayContaining(['add', 'multiply']), + expect.arrayContaining([MCP_ADD_TOOL, MCP_MULTIPLY_TOOL]), ); expect(assistantText).toMatch(/10/); expect(assistantText).toMatch(/12/); @@ -499,7 +503,7 @@ describe('MCP Server Integration (E2E)', () => { const toolUseBlocks = findToolUseBlocks(message); if (toolUseBlocks.length > 0) { foundToolUse = true; - expect(toolUseBlocks[0].name).toBe('add'); + expect(toolUseBlocks[0].name).toBe(MCP_ADD_TOOL); expect(toolUseBlocks[0].input).toBeDefined(); } } diff --git a/integration-tests/sdk-typescript/sdk-mcp-server.test.ts b/integration-tests/sdk-typescript/sdk-mcp-server.test.ts index 1ce8658e0e..a12c885bf5 100644 --- a/integration-tests/sdk-typescript/sdk-mcp-server.test.ts +++ b/integration-tests/sdk-typescript/sdk-mcp-server.test.ts @@ -35,6 +35,14 @@ const SHARED_TEST_OPTIONS = { permissionMode: 'yolo' as const, }; +// MCP tool names are generated with the pattern: mcp____ +const MCP_CALCULATE_SUM = 'mcp__sdk-calculator__calculate_sum'; +const MCP_REVERSE_STRING = 'mcp__sdk-string-utils__reverse_string'; +const MCP_SDK_ADD = 'mcp__sdk-math__sdk_add'; +const MCP_SDK_MULTIPLY = 'mcp__sdk-math__sdk_multiply'; +const MCP_MAYBE_FAIL = 'mcp__sdk-error-test__maybe_fail'; +const MCP_DELAYED_RESPONSE = 'mcp__sdk-async__delayed_response'; + describe('SDK MCP Server Integration (E2E)', () => { let helper: SDKTestHelper; let testDir: string; @@ -91,7 +99,7 @@ describe('SDK MCP Server Integration (E2E)', () => { messages.push(message); if (isSDKAssistantMessage(message)) { - const toolUseBlocks = findToolUseBlocks(message, 'calculate_sum'); + const toolUseBlocks = findToolUseBlocks(message, MCP_CALCULATE_SUM); if (toolUseBlocks.length > 0) { foundToolUse = true; } @@ -157,7 +165,10 @@ describe('SDK MCP Server Integration (E2E)', () => { messages.push(message); if (isSDKAssistantMessage(message)) { - const toolUseBlocks = findToolUseBlocks(message, 'reverse_string'); + const toolUseBlocks = findToolUseBlocks( + message, + MCP_REVERSE_STRING, + ); if (toolUseBlocks.length > 0) { foundToolUse = true; } @@ -244,8 +255,8 @@ describe('SDK MCP Server Integration (E2E)', () => { } // Validate both tools were called - expect(toolCalls).toContain('sdk_add'); - expect(toolCalls).toContain('sdk_multiply'); + expect(toolCalls).toContain(MCP_SDK_ADD); + expect(toolCalls).toContain(MCP_SDK_MULTIPLY); // Validate result: (10 + 5) * 3 = 45 expect(assistantText).toMatch(/45/); @@ -361,7 +372,7 @@ describe('SDK MCP Server Integration (E2E)', () => { messages.push(message); if (isSDKAssistantMessage(message)) { - const toolUseBlocks = findToolUseBlocks(message, 'maybe_fail'); + const toolUseBlocks = findToolUseBlocks(message, MCP_MAYBE_FAIL); if (toolUseBlocks.length > 0) { foundToolUse = true; } @@ -430,7 +441,7 @@ describe('SDK MCP Server Integration (E2E)', () => { if (isSDKAssistantMessage(message)) { const toolUseBlocks = findToolUseBlocks( message, - 'delayed_response', + MCP_DELAYED_RESPONSE, ); if (toolUseBlocks.length > 0) { foundToolUse = true;