Skip to content

Commit 5e2dbcd

Browse files
author
Adam Bloomston
committed
test: add failing test showing unknown parameters are silently ignored
This test demonstrates the current issue where tools accept unknown parameters (e.g. incorrect capitalization) without validation errors. The test uses 'username' and 'itemcount' instead of the expected 'userName' and 'itemCount' parameters, which should be rejected but currently aren't. This test is expected to fail until strict validation is implemented.
1 parent 59cb504 commit 5e2dbcd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/server/mcp.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,4 +4085,44 @@ describe('elicitInput()', () => {
40854085
}
40864086
]);
40874087
});
4088+
4089+
test('should fail: tool with incorrect parameter capitalization is not rejected', async () => {
4090+
const mcpServer = new McpServer({
4091+
name: 'test server',
4092+
version: '1.0'
4093+
});
4094+
4095+
const client = new Client({
4096+
name: 'test client',
4097+
version: '1.0'
4098+
});
4099+
4100+
mcpServer.registerTool(
4101+
'test-strict',
4102+
{
4103+
inputSchema: { userName: z.string().optional(), itemCount: z.number().optional() }
4104+
},
4105+
async ({ userName, itemCount }) => ({
4106+
content: [{ type: 'text', text: `${userName || 'none'}: ${itemCount || 0}` }]
4107+
})
4108+
);
4109+
4110+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
4111+
4112+
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
4113+
4114+
const result = await client.request(
4115+
{
4116+
method: 'tools/call',
4117+
params: {
4118+
name: 'test-strict',
4119+
arguments: { username: 'test', itemcount: 42 }
4120+
}
4121+
},
4122+
CallToolResultSchema
4123+
);
4124+
4125+
expect(result.isError).toBe(true);
4126+
expect(result.content[0].text).toContain('Invalid arguments');
4127+
});
40884128
});

0 commit comments

Comments
 (0)