modelcontextprotocol / modelcontextprotocol/typescript-sdk

registerToolTask handlers receive wrong arguments when inputSchema is omitted

Open Beginner friendly
#1,471 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P2 ready for work v2
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

  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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.