Skip to content

registerToolTask handlers receive wrong arguments when inputSchema is omitted #1471

@mattzcarey

Description

@mattzcarey

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

  1. Always pass two arguments: Change the executor to always call handler({}, extra) when inputSchema is undefined
  2. TypeScript enforcement: Use function overloads or conditional types to enforce that handlers without inputSchema must use single-argument signature
  3. Documentation: Document that inputSchema must be provided when using two-argument handler signatures

Environment

  • SDK version: v2 (drop-zod-v3-support branch)
  • Affects: registerToolTask in experimental tasks API

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions