Repository navigation
registerToolTask handlers receive wrong arguments when inputSchema is omitted #1471
Copy link
Copy link
Closed
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingfix proposedBot has a verified fix diff in the commentBot has a verified fix diff in the commentready for workEnough information for someone to start working onEnough information for someone to start working onv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixesIdeas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Description
Summary
When using registerToolTask without providing an inputSchema, handlers that expect two arguments (args, extra) receive extra as undefined because the executor only passes one argument.
Reproduction
server.experimental.tasks.registerToolTask(
'test-tool',
{
description: 'A test tool'
// Note: no inputSchema provided
},
{
async createTask(_args, extra) {
// extra is undefined here!
const task = await extra.taskStore.createTask({ ttl: extra.taskRequestedTtl });
// TypeError: Cannot read properties of undefined (reading 'taskStore')
return { task };
},
// ...
}
);Root Cause
In createToolExecutor (packages/server/src/server/mcp.ts), when inputSchema is undefined, the executor calls the handler with only one argument:
if (!inputSchema) {
return handler(extra); // Only passes extra as first argument
}
// vs when inputSchema is defined:
return handler(parsedArgs, extra); // Passes both args and extraWhen a handler is defined as async createTask(_args, extra), JavaScript will:
- With
handler(extra):_args = extra,extra = undefined - With
handler(parsedArgs, extra):_args = parsedArgs,extra = extra✓
Workaround
Always provide inputSchema: z.object({}) even for tools that don't require arguments:
server.experimental.tasks.registerToolTask(
'test-tool',
{
description: 'A test tool',
inputSchema: z.object({}) // Required for two-argument handlers
},
// ...
);Potential Solutions
- Always pass two arguments: Change the executor to always call
handler({}, extra)when inputSchema is undefined - TypeScript enforcement: Use function overloads or conditional types to enforce that handlers without inputSchema must use single-argument signature
- Documentation: Document that
inputSchemamust be provided when using two-argument handler signatures
Environment
- SDK version: v2 (drop-zod-v3-support branch)
- Affects:
registerToolTaskin experimental tasks API
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingfix proposedBot has a verified fix diff in the commentBot has a verified fix diff in the commentready for workEnough information for someone to start working onEnough information for someone to start working onv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixesIdeas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Activity
fix: pass empty args to registerToolTask createTask handler when no i…
fix: pass empty args to registerToolTask createTask handler when no i…
fix: pass both args when inputSchema omitted in task handler executor
hugosmoreira commentedon Jul 30, 2026
I'm working on this now. I'll keep the change limited to the no-inputSchema task handler argument fix plus focused regression coverage, and I'll validate the server package checks before opening a PR.
hugosmoreira commentedon Jul 30, 2026
Update after checking current main (cc4b416): the 2026-07-28 protocol rewrite removed registerToolTask and the associated task handler types, so the #1471 code path no longer exists. I won't submit a patch for deleted behavior; this issue appears obsolete on current main and may be closable.
felixweinberger commentedon Oct 7, 2026
v2 removed
registerToolTaskwith the experimental tasks API (#2128, 2.0.0). On v1 a task handler registered withoutinputSchematakes one argument,createTask(extra), and the types reject the two-argument form. Closing.