diff --git a/.changeset/fix-register-tool-task-args.md b/.changeset/fix-register-tool-task-args.md new file mode 100644 index 000000000..40d05e654 --- /dev/null +++ b/.changeset/fix-register-tool-task-args.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/server': patch +--- + +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. diff --git a/packages/server/src/server/mcp.ts b/packages/server/src/server/mcp.ts index e35871096..1d1533008 100644 --- a/packages/server/src/server/mcp.ts +++ b/packages/server/src/server/mcp.ts @@ -1042,10 +1042,10 @@ function createToolExecutor(inputSchema: AnySchema | undefined, handler: AnyTool throw new Error('No task store provided.'); } const taskCtx: CreateTaskServerContext = { ...ctx, task: { store: ctx.task.store, requestedTtl: ctx.task?.requestedTtl } }; - if (inputSchema) { - return taskHandler.createTask(args, taskCtx); + if (inputSchema || taskHandler.createTask.length > 1) { + return taskHandler.createTask(inputSchema ? args : {}, taskCtx); } - // When no inputSchema, call with just ctx (the handler expects (ctx) signature) + // When no inputSchema and handler expects single arg, call with just ctx return (taskHandler.createTask as (ctx: CreateTaskServerContext) => CreateTaskResult | Promise)(taskCtx); }; }