Skip to content

Invalid boolean query parameter values silently coerced to False #3424

@jlowin

Description

@jlowin

In `src/fastmcp/resources/template.py` line 412, boolean query parameter parsing treats any value not in `("true", "1", "yes")` as `False`:

```python
elif annotation is bool:
kwargs[param_name] = param_value.lower() in ("true", "1", "yes")
```

So `?flag=banana` silently becomes `False` instead of raising a validation error.

Interestingly, the CLI version at `src/fastmcp/cli/client.py:281-284` does this correctly — it checks both true and false sets and raises `ValueError` for unrecognized values:

```python
if raw.lower() in ("true", "1", "yes"):
return True
if raw.lower() in ("false", "0", "no"):
return False
raise ValueError(...)
```

Fix: Apply the same pattern from `client.py` to `template.py`:

```python
elif annotation is bool:
lower = param_value.lower()
if lower in ("true", "1", "yes"):
kwargs[param_name] = True
elif lower in ("false", "0", "no"):
kwargs[param_name] = False
else:
raise ValueError(f"Invalid boolean value for {param_name}: {param_value!r}")
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.httpRelated to HTTP transport, networking, or web server functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions