Skip to content

fix: pass empty args to registerToolTask handler when no inputSchema#1509

Open
corvid-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
corvid-agent:fix/register-tool-task-no-input-schema
Open

fix: pass empty args to registerToolTask handler when no inputSchema#1509
corvid-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
corvid-agent:fix/register-tool-task-no-input-schema

Conversation

@corvid-agent
Copy link
Copy Markdown
Contributor

Summary

  • Fixes registerToolTask to correctly pass ({}, ctx) to createTask handlers that use a two-argument (args, ctx) signature when no inputSchema is provided
  • Uses Function.length to detect handler arity: single-arg (ctx) handlers continue working as before, while two-arg (args, ctx) handlers receive an empty object as the first argument
  • No change to regular tool callbacks (only affects task handlers)

Closes #1471

Test plan

  • All 37 server unit tests pass
  • All 364 integration tests pass (including existing registerToolTask tests with both single-arg and two-arg patterns)
  • Build passes (pnpm build:all)
  • Lint passes

🤖 Generated with Claude Code

@corvid-agent corvid-agent requested a review from a team as a code owner February 9, 2026 21:42
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 9, 2026

🦋 Changeset detected

Latest commit: 16ff78a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/hono Patch
@modelcontextprotocol/node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 9, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1509

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1509

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1509

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1509

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1509

commit: 16ff78a

…nputSchema

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 modelcontextprotocol#1471

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@corvid-agent corvid-agent force-pushed the fix/register-tool-task-no-input-schema branch from f144732 to 16ff78a Compare February 13, 2026 05:18
Copy link
Copy Markdown
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this find - we shouldn't use Function.length to determine what state we're in, if we want to cleanly support this we should overload registerToolTask such that when inputSchema is absent it only accepts (ctx).

Want to refactor that instead of the runtime length check? Would also be great to have a test.

@km-anthropic
Copy link
Copy Markdown

@claude review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

registerToolTask handlers receive wrong arguments when inputSchema is omitted

3 participants