modelcontextprotocol / modelcontextprotocol/typescript-sdk
registerToolTask handlers receive wrong arguments when inputSchema is omitted
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
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 extra
When 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/server/src/server/mcp.ts at createToolExecutor and trace the registerToolTask path when inputSchema is omitted. Reproduce the two-argument handler case described in the issue and compare it with the inputSchema-present path. Done means handlers without an inputSchema receive the expected arguments and the reported TypeError no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100