Skip to content

feat: enforce greet(name) input bounds via pydantic.Field#19

Merged
heznpc merged 1 commit intomainfrom
feat/pydantic-input-constraints
May 2, 2026
Merged

feat: enforce greet(name) input bounds via pydantic.Field#19
heznpc merged 1 commit intomainfrom
feat/pydantic-input-constraints

Conversation

@heznpc
Copy link
Copy Markdown
Member

@heznpc heznpc commented May 2, 2026

From the 2026-05-01 audit (P2.16). Restores parity with the TS sibling's Zod constraint.

Switch from bare name: str to:

name: Annotated[
    str,
    Field(min_length=1, max_length=200, description=...),
],

FastMCP propagates the Field metadata into the JSON schema; protocol layer rejects empty / oversized inputs before the handler runs.

Test plan

  • mypy strict clean (9 files)
  • pytest 14 passing
  • CI green

Audit (2026-05-01, P2.16): the TS sibling validates greet's name with
Zod (1–200 chars). Python equivalent was untyped — empty strings and
megastring inputs reached the handler.

Switch the parameter annotation from `name: str` to
`name: Annotated[str, Field(min_length=1, max_length=200, description=...)]`.
FastMCP picks up the Annotated metadata and emits the constraint into
the tool's JSON schema, so violations are rejected at protocol level.

Tests pass; mypy strict still clean.
@heznpc heznpc merged commit c8804cd into main May 2, 2026
7 checks passed
@heznpc heznpc deleted the feat/pydantic-input-constraints branch May 2, 2026 01:48
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.

1 participant