-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
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
Metadata
Metadata
Assignees
Labels
No labels