Repository navigation
fix: forbid extra arguments in FastMCP tool arg models (#3067) - #3068
elbachir-salik wants to merge 5 commits into
Conversation
…tation in test_unknown_argument_raises_validation_error
|
Reviewed against current `upstream/main`: `ArgModelBase.model_config` is the single Pydantic base every FastMCP-generated tool arg model inherits (`func_metadata.py`), and it's built purely from the function's declared signature params (Context-typed params are already excluded before the model is constructed, confirmed via the existing `test_context.py` snapshot tests) — there's no code path here that legitimately needs to accept an argument name outside the declared schema, and no `**kwargs`-style dynamic-arg support exists in `func_metadata.py` today. So `extra="forbid"` closes a real hole (misspelled/unknown `tools/call` arguments silently vanishing instead of failing) without a regression path for the current codebase. Also checked that the updated `additionalProperties: false` in the JSON Schema output matches the new `extra="forbid"` semantics one-to-one (Pydantic sets that schema keyword automatically for forbid-mode models), so client-side schema validation and server-side runtime validation stay in sync — no silent divergence between what the tool advertises and what it enforces. Tests cover both the schema-shape change (existing snapshot tests updated) and the new runtime behavior (`test_unknown_argument_raises_validation_error`, plus the doc-tutorial test that now asserts rejection instead of silent drop). CI is green across the full Python matrix. Looks correct to me. |
Thanks for the thorough review! Glad the fix holds up across all the edge cases you checked. |
…-sdk into fix/argmodel-forbid-extra-3067
|
Thanks for the PR, and sorry it sat here without a proper review. We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest. If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise. |
Closes #3067
ArgModelBase now uses extra="forbid" so unknown or misspelled tool arguments raise a validation error instead of being silently ignored.
Added a regression test confirming unknown args are rejected.