fix(mcpserver): handle bare typing.Dict and typing sequence generics in func_metadata
Closed
CH
1mo ago+43+43+01234567890123456789-1-1-0123456789
Fixes #3771
Motivation and Context
In src/mcp/server/mcpserver/utilities/func_metadata.py, return type inspection behaved inconsistently for unsubscripted typing generic counterparts compared to standard built-in types:
typing.Dict:get_origin(typing.Dict)isdictbutget_args(typing.Dict)is(). It fell through thelen(args) == 2check into theelsebranch, mistakenly forcingwrap_output = True(wrapped in{"result": ...}) instead of being treated as a top-level JSON object likedictordict[str, Any].typing.List/typing.Tuple:typing.List in (list, tuple)evaluates toFalse, bypassing the opt-out gate at line 449 and unintentionally producing a wrapped Pydantic output model.
How Has This Been Tested?
- Added unit tests in
tests/server/mcpserver/test_func_metadata.py:func_bare_typing_dictverifyingoutput_schemais a partial object dict andwrap_outputisFalse.test_bare_typing_sequence_opts_out_of_structured_outputverifyingmeta.output_schema is Noneforlist,typing.List,tuple, andtyping.Tuple.
- Ran the test suite with pytest: all 66 tests in
test_func_metadata.pypass.
Breaking Changes
None. This aligns unsubscripted typing generics (typing.Dict, typing.List, typing.Tuple) with standard Python dict, list, tuple behavior.
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
- Documentation update
Checklist
- I am assigned to the linked issue (or it is labeled
help wanted, or I'm a maintainer) - I have disclosed any AI assistance and can explain the change in my own words
- I have read the MCP Documentation
- My code follows the repository's style guidelines
- New and existing tests pass locally
- I have added appropriate error handling
- I have added or updated documentation as needed