Skip to content

Commit f144732

Browse files
corvid-agentclaude
andcommitted
fix: pass empty args to registerToolTask createTask handler when no inputSchema
When registerToolTask is used without inputSchema, the createTask handler should receive an empty object as its first argument when the handler expects two arguments (args, ctx). This fixes the case where users define a two-argument handler but omit inputSchema - previously the second argument (ctx) would be passed as the first argument instead. Uses Function.length to detect handler arity: single-arg handlers continue to receive just ctx, while two-arg handlers get ({}, ctx). Closes #1471 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65bbcea commit f144732

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
Fix `registerToolTask` to pass empty args object to `createTask` handler when no `inputSchema` is provided, allowing two-argument `(args, ctx)` handler signatures to work correctly.

packages/server/src/server/mcp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,10 @@ function createToolExecutor(inputSchema: AnySchema | undefined, handler: AnyTool
10421042
throw new Error('No task store provided.');
10431043
}
10441044
const taskCtx: CreateTaskServerContext = { ...ctx, task: { store: ctx.task.store, requestedTtl: ctx.task?.requestedTtl } };
1045-
if (inputSchema) {
1046-
return taskHandler.createTask(args, taskCtx);
1045+
if (inputSchema || taskHandler.createTask.length > 1) {
1046+
return taskHandler.createTask(inputSchema ? args : {}, taskCtx);
10471047
}
1048-
// When no inputSchema, call with just ctx (the handler expects (ctx) signature)
1048+
// When no inputSchema and handler expects single arg, call with just ctx
10491049
return (taskHandler.createTask as (ctx: CreateTaskServerContext) => CreateTaskResult | Promise<CreateTaskResult>)(taskCtx);
10501050
};
10511051
}

0 commit comments

Comments
 (0)