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
8 changes: 8 additions & 0 deletions packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,14 @@ function createToolExecutor(
return async (args, ctx) => callback(args, ctx);
}

if (handler.length > 1) {
throw new Error(
`Tool handler accepts ${handler.length} parameters but no inputSchema was provided. ` +
'Add inputSchema to the tool definition to enable the (args, ctx) two-parameter signature, ' +
'or change the handler to accept only one parameter (ctx).'
);
}

// When no inputSchema, call with just ctx (the handler expects (ctx) signature)
const callback = handler as (ctx: ServerContext) => CallToolResult | Promise<CallToolResult>;
return async (_args, ctx) => callback(ctx);
Expand Down
11 changes: 11 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,17 @@ describe('registerTool/registerPrompt accept raw Zod shape (auto-wrapped)', () =

await server.close();
});

it('rejects a two-argument handler when inputSchema is omitted', () => {
const server = new McpServer({ name: 't', version: '1.0.0' });
const handler = ((_args: unknown, _ctx: unknown) => ({
content: [{ type: 'text' as const, text: 'ok' }]
})) as never;

expect(() => server.registerTool('no-schema', {}, handler)).toThrow(
/no inputSchema.*two-parameter signature|inputSchema.*two-parameter signature/
);
});
});

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