Skip to content

Commit d5df257

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 f657ead commit d5df257

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/server/mcp.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,4 +4290,58 @@ describe("elicitInput()", () => {
42904290
text: "No booking made. Original date not available."
42914291
}]);
42924292
});
4293+
4294+
/**
4295+
* Test: Tool parameter validation with incorrect capitalization
4296+
* This test demonstrates that tools currently silently ignore unknown parameters,
4297+
* including those with incorrect capitalization. This should fail to show the issue exists.
4298+
*/
4299+
test("should fail: tool with incorrect parameter capitalization is not rejected", async () => {
4300+
const mcpServer = new McpServer({
4301+
name: "test server",
4302+
version: "1.0",
4303+
});
4304+
4305+
const client = new Client({
4306+
name: "test client",
4307+
version: "1.0",
4308+
});
4309+
4310+
// Register a tool that expects optional 'userName' and 'itemCount'
4311+
mcpServer.registerTool(
4312+
"test-strict",
4313+
{
4314+
inputSchema: { userName: z.string().optional(), itemCount: z.number().optional() },
4315+
},
4316+
async ({ userName, itemCount }) => ({
4317+
content: [{ type: "text", text: `${userName || 'none'}: ${itemCount || 0}` }],
4318+
})
4319+
);
4320+
4321+
const [clientTransport, serverTransport] =
4322+
InMemoryTransport.createLinkedPair();
4323+
4324+
await Promise.all([
4325+
client.connect(clientTransport),
4326+
mcpServer.server.connect(serverTransport),
4327+
]);
4328+
4329+
// Call the tool with unknown parameters (incorrect capitalization)
4330+
// These should be rejected but currently aren't - they're silently ignored
4331+
const result = await client.request(
4332+
{
4333+
method: "tools/call",
4334+
params: {
4335+
name: "test-strict",
4336+
arguments: { username: "test", itemcount: 42 }, // Should be rejected as unknown parameters
4337+
},
4338+
},
4339+
CallToolResultSchema,
4340+
);
4341+
4342+
// This expectation should fail because the tool currently accepts the call
4343+
// and silently ignores unknown parameters, returning success instead of error
4344+
expect(result.isError).toBe(true);
4345+
expect(result.content[0].text).toContain("Invalid arguments");
4346+
});
42934347
});

0 commit comments

Comments
 (0)