Skip to content

InvalidParams error when all fields in the tool schema are optional #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nirinchev opened this issue Apr 24, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@nirinchev
Copy link

Describe the bug
When registering a tool with a schema, consisting of all optional fields, some models will try calling the tool without supplying arguments in the request. This, however, fails validation because the zod object being created is non-optional:

paramsSchema === undefined ? undefined : z.object(paramsSchema),
.

Not sure if this is an issue with the server itself or the agent calling it, but would be nice if there was a way to give a hint to the model that the argument field is required for that particular tool.

To Reproduce
Unfortunately, this doesn't reproduce with all models/agents, but we've seen it happen somewhat consistently with Windsurf.

Steps to reproduce the behavior:

  1. Register a tool with an all-optional schema:
    server.tool(
        "fetch-records",
        "Fetches database records",
        { limit: z.number().optional().describe("The number of records to fetch. Default is 20.") },
        ({ limit }) => {
            return {
                content: [{ type: "text", text: `Fetched ${limit ?? 20} records` }],
            };
        }
    );
  2. Ask the agent to call the tool.
  3. Observe the agent receiving MCP error -32602: Invalid arguments for tool [...] "expected": "object", "received": "undefined", "path": []

Expected behavior
I guess I would expect the protocol to be more explicit about when fields are required vs when they're not, or alternatively, we could fallback to an empty object when arguments is not provided in the request, but expected due to the tool schema.

@nirinchev nirinchev added the bug Something isn't working label Apr 24, 2025
@mxcl
Copy link

mxcl commented Apr 25, 2025

I found .nullable() works but it’s certainly less idiomatic.

@Hendler
Copy link

Hendler commented May 17, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants