modelcontextprotocol/servers · error · ValueError

Missing required argument: timezone

Error message

Missing required argument: timezone

What it means

The get_current_time branch (server.py:189-192) reads arguments.get('timezone') and raises ValueError('Missing required argument: timezone') when it is falsy (missing key, None, or empty string). NOTE: because the whole call_tool body is wrapped in except Exception (error 49), the specific message is masked and the client sees error 49's generic wrapper text instead.

Source

Thrown at src/time/src/mcp_server_time/server.py:192

                    readOnlyHint=True,
                    destructiveHint=False,
                    idempotentHint=True,
                    openWorldHint=False,
                ),
            ),
        ]

    @server.call_tool()
    async def call_tool(
        name: str, arguments: dict
    ) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
        """Handle tool calls for time queries."""
        try:
            match name:
                case TimeTools.GET_CURRENT_TIME.value:
                    timezone = arguments.get("timezone")
                    if not timezone:
                        raise ValueError("Missing required argument: timezone")

                    result = time_server.get_current_time(timezone)

                case TimeTools.CONVERT_TIME.value:
                    if not all(
                        k in arguments
                        for k in ["source_timezone", "time", "target_timezone"]
                    ):
                        raise ValueError("Missing required arguments")

                    result = time_server.convert_time(
                        arguments["source_timezone"],
                        arguments["time"],
                        arguments["target_timezone"],
                    )
                case _:
                    raise ValueError(f"Unknown tool: {name}")

View on GitHub (pinned to 76d64c822f)

Solutions

  1. Always include a non-empty IANA timezone string in the arguments.
  2. Validate against the tool's input schema before calling.
  3. If you own the server, fix the outer except (error 49) so this real message survives to the client.

Example fix

// before
//   arguments: {}                       -> Missing required argument
// after
//   arguments: {"timezone": "UTC"}
Defensive patterns

Strategy: validation

Validate before calling

tz = arguments.get("timezone")
if not isinstance(tz, str) or not tz.strip():
    raise ValueError("'timezone' is required and must be a non-empty IANA name")

Type guard

def has_timezone_arg(args: object) -> bool:
    return (
        isinstance(args, dict)
        and isinstance(args.get("timezone"), str)
        and args["timezone"].strip() != ""
    )

Prevention

When it happens

Trigger: Calling get_current_time with no 'timezone' key, timezone: null, or timezone: ''.

Common situations: Client omits the key; an LLM emits null; the input schema is not enforced before dispatch; a UI sends an empty field.

Related errors


AI-assisted analysis of modelcontextprotocol/servers@76d64c822f (2026-08-12). Data as JSON: /api/errors/243f57acf23e8920. Report an issue: GitHub.