Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/null-tool-call-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@modelcontextprotocol/core": patch
"@modelcontextprotocol/server": patch
---

Accept `null` tool call arguments as omitted.
6 changes: 5 additions & 1 deletion packages/core/src/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,11 @@ export const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.exte
/**
* Arguments to pass to the tool.
*/
arguments: z.record(z.string(), z.unknown()).optional()
arguments: z
.record(z.string(), z.unknown())
.nullable()
.transform(args => args ?? undefined)
.optional()
});

/**
Expand Down
20 changes: 20 additions & 0 deletions packages/core/test/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CallToolRequestSchema,
CallToolResultSchema,
ClientCapabilitiesSchema,
CompleteRequestSchema,
Expand Down Expand Up @@ -33,6 +34,25 @@ describe('Types', () => {
expect(SUPPORTED_PROTOCOL_VERSIONS).toContain('2024-10-07');
});

describe('CallToolRequest', () => {
test('should treat null arguments as omitted', () => {
const request = {
method: 'tools/call',
params: {
name: 'echo',
arguments: null
}
};

const result = CallToolRequestSchema.safeParse(request);

expect(result.success).toBe(true);
if (result.success) {
expect(result.data.params.arguments).toBeUndefined();
}
});
});

describe('ResourceLink', () => {
test('should validate a minimal ResourceLink', () => {
const resourceLink = {
Expand Down
43 changes: 43 additions & 0 deletions packages/server/test/server/mcp.compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,49 @@ describe('registerTool/registerPrompt accept raw Zod shape (auto-wrapped)', () =

await server.close();
});

it('treats null tools/call arguments as omitted', async () => {
const server = new McpServer({ name: 't', version: '1.0.0' });

let received: unknown;
server.registerTool('empty', { inputSchema: {} }, async args => {
received = args;
return { content: [{ type: 'text' as const, text: 'ok' }] };
});

const [client, srv] = InMemoryTransport.createLinkedPair();
await server.connect(srv);
await client.start();

const responses: JSONRPCMessage[] = [];
client.onmessage = m => responses.push(m);

await client.send({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: LATEST_PROTOCOL_VERSION,
capabilities: {},
clientInfo: { name: 'c', version: '1.0.0' }
}
} as JSONRPCMessage);
await client.send({ jsonrpc: '2.0', method: 'notifications/initialized' } as JSONRPCMessage);
await client.send({
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: { name: 'empty', arguments: null }
} as JSONRPCMessage);

await vi.waitFor(() => expect(responses.some(r => 'id' in r && r.id === 2)).toBe(true));

expect(received).toEqual({});
const result = responses.find(r => 'id' in r && r.id === 2) as { result?: { content: Array<{ text: string }> } };
expect(result.result?.content[0]?.text).toBe('ok');

await server.close();
});
});

describe('InferRawShape', () => {
Expand Down
Loading