Skip to content

Commit 33019b1

Browse files
refactor: move issue modelcontextprotocol#400 test to issues directory
1 parent a3f17fe commit 33019b1

2 files changed

Lines changed: 70 additions & 57 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Regression test for https://github.com/modelcontextprotocol/typescript-sdk/issues/400
3+
*
4+
* When a tool has all optional parameters, some LLM models call the tool without
5+
* providing an `arguments` field. This test verifies that undefined arguments are
6+
* handled correctly by defaulting to an empty object.
7+
*/
8+
9+
import { Client } from '@modelcontextprotocol/client';
10+
import { CallToolResultSchema, InMemoryTransport } from '@modelcontextprotocol/core';
11+
import { McpServer } from '@modelcontextprotocol/server';
12+
import type { ZodMatrixEntry } from '@modelcontextprotocol/test-helpers';
13+
import { zodTestMatrix } from '@modelcontextprotocol/test-helpers';
14+
15+
describe.each(zodTestMatrix)('Issue #400: $zodVersionLabel', (entry: ZodMatrixEntry) => {
16+
const { z } = entry;
17+
18+
test('should accept undefined arguments when all tool params are optional', async () => {
19+
const mcpServer = new McpServer({
20+
name: 'test server',
21+
version: '1.0'
22+
});
23+
const client = new Client({
24+
name: 'test client',
25+
version: '1.0'
26+
});
27+
28+
mcpServer.registerTool(
29+
'optional-params-tool',
30+
{
31+
inputSchema: {
32+
limit: z.number().optional(),
33+
offset: z.number().optional()
34+
}
35+
},
36+
async ({ limit, offset }) => ({
37+
content: [
38+
{
39+
type: 'text',
40+
text: `limit: ${limit ?? 'default'}, offset: ${offset ?? 'default'}`
41+
}
42+
]
43+
})
44+
);
45+
46+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
47+
48+
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
49+
50+
// Call tool without arguments (arguments is undefined)
51+
const result = await client.request(
52+
{
53+
method: 'tools/call',
54+
params: {
55+
name: 'optional-params-tool'
56+
// arguments is intentionally omitted (undefined)
57+
}
58+
},
59+
CallToolResultSchema
60+
);
61+
62+
expect(result.isError).toBeUndefined();
63+
expect(result.content).toEqual([
64+
{
65+
type: 'text',
66+
text: 'limit: default, offset: default'
67+
}
68+
]);
69+
});
70+
});

‎test/integration/test/server/mcp.test.ts‎

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -981,63 +981,6 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
981981
);
982982
});
983983

984-
/***
985-
* Test: Tool with all optional parameters called without arguments (Issue #400)
986-
* @see https://github.com/modelcontextprotocol/typescript-sdk/issues/400
987-
*/
988-
test('should accept undefined arguments when all tool params are optional', async () => {
989-
const mcpServer = new McpServer({
990-
name: 'test server',
991-
version: '1.0'
992-
});
993-
const client = new Client({
994-
name: 'test client',
995-
version: '1.0'
996-
});
997-
998-
mcpServer.registerTool(
999-
'optional-params-tool',
1000-
{
1001-
inputSchema: {
1002-
limit: z.number().optional(),
1003-
offset: z.number().optional()
1004-
}
1005-
},
1006-
async ({ limit, offset }) => ({
1007-
content: [
1008-
{
1009-
type: 'text',
1010-
text: `limit: ${limit ?? 'default'}, offset: ${offset ?? 'default'}`
1011-
}
1012-
]
1013-
})
1014-
);
1015-
1016-
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1017-
1018-
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
1019-
1020-
// Call tool without arguments (arguments is undefined)
1021-
const result = await client.request(
1022-
{
1023-
method: 'tools/call',
1024-
params: {
1025-
name: 'optional-params-tool'
1026-
// arguments is intentionally omitted (undefined)
1027-
}
1028-
},
1029-
CallToolResultSchema
1030-
);
1031-
1032-
expect(result.isError).toBeUndefined();
1033-
expect(result.content).toEqual([
1034-
{
1035-
type: 'text',
1036-
text: 'limit: default, offset: default'
1037-
}
1038-
]);
1039-
});
1040-
1041984
/***
1042985
* Test: Preventing Duplicate Tool Registration
1043986
*/

0 commit comments

Comments
 (0)