Skip to content

Conversation

@su-ram
Copy link

@su-ram su-ram commented Jan 19, 2026

Fixes #400

Motivation and Context

When a tool has all optional parameters, some LLM models call the tool without providing an
arguments field. This causes Zod validation to fail with:

MCP error -32602: Invalid arguments for tool [name]: Invalid input: expected object, received
undefined

Even though the schema allows all fields to be optional, Zod's z.object() expects the input
itself to be an object, not undefined or null.

How Has This Been Tested?

  • Added unit test: should accept undefined arguments when all tool params are optional
  • Verified Zod behavior with direct testing:
    • undefined → fails with "expected object, received undefined"
    • null → fails with "expected object, received null"
    • {} → passes validation
  • All existing tests pass (1,392 tests)

Breaking Changes

None. This is a backward-compatible fix that only affects edge cases where arguments is
omitted.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The fix is a single line change in packages/server/src/server/mcp.ts:

// Before                                                                                       
const parseResult = await safeParseAsync(schemaToParse, args);                                  
                                                                                                
// After                                                                                        
const parseResult = await safeParseAsync(schemaToParse, args ?? {});                            
                                                                                                
Using ?? handles both undefined and null cases.                                                 

@su-ram su-ram requested a review from a team as a code owner January 19, 2026 12:31
@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2026

⚠️ No Changeset found

Latest commit: 2586801

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 19, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1404

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1404

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1404

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1404

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1404

commit: 2586801

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidParams error when all fields in the tool schema are optional

1 participant