Skip to content

Wrong or extra prompt arguments return an internal error instead of -32602 #3974

Backlog

Description

@Faisalhassan903

Initial Checks

Release line

2.x (current stable)

Description

I found an issue while testing prompt arguments.

If a prompt expects an integer, such as max_words: int, but the client sends "ten", the server returns an internal error. The same happens when the client sends an extra argument.

Results on main:

Arguments 2025-11-25 2026-07-28
{} -32602 -32602
{"max_words": "ten"} 0 -32603
{"max_words": "10", "tone": "formal"} 0 -32603

The server also logs these errors with a full traceback.

I expected -32602 because this is an invalid argument from the client, not an internal server error.

The client also does not know the expected argument type because prompts/list does not provide type information.

The prompts documentation says clients can tell missing arguments from internal errors by the error code, but that doesn't work for wrong types or extra arguments.

Why this happens

From what I found, the prompt function uses validate_call to validate the arguments (base.py#L146).

However, render catches the exception and converts it into a ValueError (base.py#L212-L215).

The dispatcher already handles ValidationError and returns -32602, but it does not receive the original error (jsonrpc_dispatcher.py#L92-L105).

Possible solution

I think we can validate the arguments before calling the prompt function, similar to how tools handle arguments.

I tested this approach using a monkeypatch. Invalid argument types returned -32602, while errors inside the prompt function still returned an internal error.

I did not simply re-raise ValidationError because the prompt function itself could also raise this error.

My question is, should we ignore extra arguments like tools do, or should we return -32602?

Related issues: #3696, #3837 and #3342.

I would be happy to work on a PR if this approach makes sense.

I used Claude Code to help investigate and reproduce the issue. I also checked the results myself.

Example Code

import anyio

from mcp import Client
from mcp.server import MCPServer
from mcp.shared.exceptions import MCPError

mcp = MCPServer("demo")


@mcp.prompt()
def summarize(max_words: int) -> str:
    return f"Summarize in {max_words} words."


async def main() -> None:
    for mode in ("legacy", "auto"):
        async with Client(mcp, mode=mode) as client:
            for args in ({}, {"max_words": "ten"}, {"max_words": "10", "tone": "formal"}):
                try:
                    await client.get_prompt("summarize", args)
                except MCPError as e:
                    print(client.protocol_version, args, e.error.code, e.error.message)


anyio.run(main)

Python & MCP Python SDK

Python 3.11, 3.12 and 3.15 on macOS
MCP 2.3.0 and main @ 77001c9
The missing-argument case was fixed on main in #3696, but that fix is not in 2.3.0 yet.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions