Skip to content

The exclude_args parameter in fastmcp is not working. #2431

@lixingbu-tal

Description

@lixingbu-tal

Description

The processing order of fastmcp is incorrect:
Line 52: First, get_cached_typeadapter(fn) is called, which will parse all parameter type annotations of the function, including session: Optional[Session].
Pydantic attempts to generate a schema for Optional[Session], but the Session cannot be serialized, resulting in an error.
Lines 54-55: Although compress_schema will be used later to exclude the parameters in exclude_args, the error has already occurred in step 52.
root cause:
The exclude_args option only takes effect during the schema compression phase, while Pydantic's type resolution occurs in the earlier get_cached_typeadapter phase.

Example Code

# Line 52: First create the TypeAdapter (which will parse all parameter types).
input_type_adapter = get_cached_typeadapter(fn)

# Lines 54-55: Then exclude the parameters.
input_schema = compress_schema(
    input_schema, prune_params=prune_params, prune_titles=True
)

Version Information

FastMCP version:                                                                   2.13.0.2
MCP version:                                                                         1.21.0
Python version:                                                                      3.13.5
Platform:                                              macOS-10.16-x86_64-i386-64bit-Mach-O
FastMCP root path: /Users/xiangchu/miniconda3/envs/tta-resource/lib/python3.13/site-packages

Metadata

Metadata

Assignees

Labels

bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions