Skip to content

fix: pass both args when inputSchema omitted in task handler executor#1975

Open
nanookclaw wants to merge 1 commit intomodelcontextprotocol:mainfrom
nanookclaw:fix/tool-executor-args-no-inputschema
Open

fix: pass both args when inputSchema omitted in task handler executor#1975
nanookclaw wants to merge 1 commit intomodelcontextprotocol:mainfrom
nanookclaw:fix/tool-executor-args-no-inputschema

Conversation

@nanookclaw
Copy link
Copy Markdown

Problem

When registerToolTask is called without inputSchema, two-argument handlers (args, extra) receive incorrect argument positions: args gets the context object and extra is undefined.

This causes a runtime TypeError when the handler tries to access properties like extra.taskStore:

TypeError: Cannot read properties of undefined (reading 'taskStore')

Closes #1471

Root Cause

In createToolExecutor (packages/server/src/server/mcp.ts), when inputSchema is undefined, the task handler path casts createTask to a single-argument signature and calls it with only taskCtx. Any handler written as (args, extra) gets the arguments shifted.

Fix

Changed the task handler path to always call taskHandler.createTask({}, taskCtx) when inputSchema is undefined, passing an empty object as the first argument so two-argument handlers receive correct positions.

Regular tool callbacks are unchanged — their single-arg (ctx) => Result signature matches the TypeScript types and existing behavior.

Testing

  • Server unit tests: 55/55 passing
  • Integration tests: 422/423 passing (1 pre-existing Cloudflare Workers failure unrelated to this change)
  • Updated two existing tests to use two-arg createTask signatures consistent with the fix

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 modelcontextprotocol#1471
@nanookclaw nanookclaw requested a review from a team as a code owner April 28, 2026 18:16
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

⚠️ No Changeset found

Latest commit: cc070b2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 28, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1975

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1975

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1975

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1975

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1975

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1975

commit: cc070b2

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

1 participant