Skip to content

Commit cc070b2

Browse files
committed
fix: pass both args when inputSchema omitted in task handler executor
When inputSchema is undefined, createToolExecutor now calls taskHandler.createTask({}, taskCtx) instead of casting to a single-arg signature. This ensures two-argument handlers receive correct argument positions: (args, ctx) rather than having ctx shifted to the first parameter. Regular tool callbacks remain unchanged — their single-arg signature matches the TypeScript types. Fixes #1471
1 parent 7cccc2a commit cc070b2

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

packages/server/src/server/mcp.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,9 @@ export type RegisteredTool = {
11201120
/**
11211121
* Creates an executor that invokes the handler with the appropriate arguments.
11221122
* When `inputSchema` is defined, the handler is called with `(args, ctx)`.
1123-
* When `inputSchema` is undefined, the handler is called with just `(ctx)`.
1123+
* When `inputSchema` is undefined, regular tool callbacks are called with `(ctx)`.
1124+
* Task handlers are always called with `(args, ctx)`, passing `{}` when inputSchema is undefined,
1125+
* to match the two-argument handler signature.
11241126
*/
11251127
function createToolExecutor(
11261128
inputSchema: StandardSchemaWithJSON | undefined,
@@ -1138,8 +1140,8 @@ function createToolExecutor(
11381140
if (inputSchema) {
11391141
return taskHandler.createTask(args, taskCtx);
11401142
}
1141-
// When no inputSchema, call with just ctx (the handler expects (ctx) signature)
1142-
return (taskHandler.createTask as (ctx: CreateTaskServerContext) => CreateTaskResult | Promise<CreateTaskResult>)(taskCtx);
1143+
// When no inputSchema, pass empty object as args so two-argument handlers receive correct positions
1144+
return taskHandler.createTask({}, taskCtx);
11431145
};
11441146
}
11451147

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6828,7 +6828,7 @@ describe('Zod v4', () => {
68286828
}
68296829
},
68306830
{
6831-
createTask: async ctx => {
6831+
createTask: async (_args, ctx) => {
68326832
const task = await ctx.task.store.createTask({ ttl: 60_000, pollInterval: 100 });
68336833

68346834
// Capture taskStore for use in setTimeout
@@ -6932,7 +6932,7 @@ describe('Zod v4', () => {
69326932
}
69336933
},
69346934
{
6935-
createTask: async ctx => {
6935+
createTask: async (_args, ctx) => {
69366936
const task = await ctx.task.store.createTask({ ttl: 60_000, pollInterval: 100 });
69376937

69386938
// Capture taskStore for use in setTimeout

0 commit comments

Comments
 (0)