Skip to content

Preserve dict output Field metadata#3042

Open
Whning0513 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Whning0513:preserve-dict-output-metadata-2935
Open

Preserve dict output Field metadata#3042
Whning0513 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Whning0513:preserve-dict-output-metadata-2935

Conversation

@Whning0513

Copy link
Copy Markdown

Summary

  • preserve top-level Annotated/Field metadata for dict[str, T] tool return types
  • pass the original return annotation into the dict RootModel path
  • add a regression test covering Field(description=...) on dict outputs

Testing

  • PYTHONPATH=src:src/mcp-types python -m pytest -q tests/server/mcpserver/test_func_metadata.py -k structured_output_dict_str_types
  • PYTHONPATH=src:src/mcp-types python -m pytest -q tests/server/mcpserver/test_func_metadata.py

Fixes #2935

Copilot AI review requested due to automatic review settings July 1, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes MCPServer tool output-schema generation so that dict[str, T] return types preserve top-level Annotated[...] / Field(...) metadata (e.g., description) in the generated JSON schema, aligning dict outputs with other structured output return types.

Changes:

  • Pass the original (potentially Annotated) return annotation into the dict[str, T] RootModel creation path.
  • Add a regression test asserting that Field(description=...) on Annotated[dict[str, int], ...] appears in meta.output_schema.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/mcp/server/mcpserver/utilities/func_metadata.py Ensures dict[str, T] structured output schema generation uses the original return annotation so Annotated/Field metadata is preserved.
tests/server/mcpserver/test_func_metadata.py Adds a regression assertion that description is retained for Annotated[dict[str, T], Field(...)] outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more

Re-trigger cubic

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.

dict[str, T] tool return types lose Annotated/Field metadata in output schema

2 participants