Skip to content

fix(mcpserver): handle bare typing.Dict and typing sequence generics in func_metadata - #3772

Closed
chauvuusvn wants to merge 1 commit into
modelcontextprotocol:mainfrom
chauvuusvn:fix/typing-generics-structured-output
Closed

chauvuusvn wants to merge 1 commit into
modelcontextprotocol:mainfrom
chauvuusvn:fix/typing-generics-structured-output

Conversation

@chauvuusvn

Copy link
Copy Markdown

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:

  1. typing.Dict: get_origin(typing.Dict) is dict but get_args(typing.Dict) is (). It fell through the len(args) == 2 check into the else branch, mistakenly forcing wrap_output = True (wrapped in {"result": ...}) instead of being treated as a top-level JSON object like dict or dict[str, Any].
  2. typing.List / typing.Tuple: typing.List in (list, tuple) evaluates to False, 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_dict verifying output_schema is a partial object dict and wrap_output is False.
    • test_bare_typing_sequence_opts_out_of_structured_output verifying meta.output_schema is None for list, typing.List, tuple, and typing.Tuple.
  • Ran the test suite with pytest: all 66 tests in test_func_metadata.py pass.

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

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3771.

If a maintainer assigns you to #3771, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Inconsistent structured output wrapping and opt-out for typing.Dict and typing sequence generics in func_metadata

1 participant