Skip to content

fix(fetch): accept null for optional parameters#3982

Open
rohitg00 wants to merge 1 commit intomodelcontextprotocol:mainfrom
rohitg00:fix/fetch-null-optional-params
Open

fix(fetch): accept null for optional parameters#3982
rohitg00 wants to merge 1 commit intomodelcontextprotocol:mainfrom
rohitg00:fix/fetch-null-optional-params

Conversation

@rohitg00
Copy link
Copy Markdown

Closes #2035.

Clients like LibreChat send explicit null for optional Pydantic parameters. The Fetch model typed them as int/bool, so Pydantic rejected null at type coercion before field defaults could apply.

Fix

Adds a mode="before" field_validator on max_length, start_index, and raw that maps None to the field's declared default. Fields keep their int/bool types, validators (gt=0, lt=1_000_000, ge=0) continue to enforce on resolved values, and falsy-coalescing is avoided so valid start_index=0 and explicit raw=false pass through unchanged.

Tests

9 new tests covering:

  • Null handling per field and all-null together
  • Omitted fields use defaults
  • Explicit values preserved (including start_index=0, raw=false)
  • Validators still reject invalid values

Full suite: 29 passed, ruff clean, pyright 0 errors.

AI disclosure

Human-led, drafted with Claude Code assistance. I chose the validator pattern after reviewing closed PR #2631 (which used or coalescing that silently discards valid falsy values like start_index=0). The fix was tested locally before opening the PR.

Closes modelcontextprotocol#2035.

Clients like LibreChat send explicit `null` for optional params instead
of omitting them. The Fetch model declared `max_length: int`,
`start_index: int`, and `raw: bool`, so Pydantic rejected `null` at the
type-coercion step before field defaults could apply.

Adds a `mode="before"` field_validator that maps `None` back to the
field's declared default. Keeps field types as `int`/`bool`, preserves
the `gt=0`/`lt=1_000_000`/`ge=0` validators on resolved values, and
does not rely on falsy-coalescing (which would have replaced valid
`start_index=0` or explicit `raw=false`).

Adds 9 tests covering null handling, default preservation, explicit
zero/false preservation, and validator behavior.
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.

fetch fails without optional settings

1 participant