Skip to content

registerToolTask handlers receive wrong arguments when inputSchema is omitted #1471

Closed

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

Activity

  1. added 2 commits that reference this issue on Feb 9, 2026
    f144732
    16ff78a
  2. ghost added
    bugSomething isn't working
    on Apr 16, 2026
  3. ghost added
    ready for workEnough information for someone to start working on
    on Apr 16, 2026
  4. ghost added
    v2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
    on Apr 16, 2026
  5. ghost added
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    on Apr 16, 2026
  6. ghost added
    fix proposedBot has a verified fix diff in the comment
    on Apr 16, 2026
  7. added a commit that references this issue on Jun 19, 2026
    44fe2d7
  8. hugosmoreira commented on Jul 30, 2026

    @hugosmoreira
    Contributor

    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.

  9. hugosmoreira commented on Jul 30, 2026

    @hugosmoreira
    Contributor

    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.

  10. felixweinberger commented on Oct 7, 2026

    @felixweinberger
    Contributor

    v2 removed registerToolTask with the experimental tasks API (#2128, 2.0.0). On v1 a task handler registered without inputSchema takes one argument, createTask(extra), and the types reject the two-argument form. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingfix proposedBot has a verified fix diff in the commentready for workEnough information for someone to start working onv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions