Skip to content

fix(func_metadata): give bare dict/list/tuple returns a structured output model - #3731

Closed
CodeAlex52 wants to merge 1 commit into
modelcontextprotocol:mainfrom
CodeAlex52:fix/bare-container-output-model
Closed

CodeAlex52 wants to merge 1 commit into
modelcontextprotocol:mainfrom
CodeAlex52:fix/bare-container-output-model

Conversation

@CodeAlex52

Copy link
Copy Markdown

Fixes #3725

Summary

A tool annotated with a bare dict (or list / tuple) produced no output model at all:

  • no outputSchema on the tool,
  • no structuredContent in the result (only JSON text),
  • with structured_output=True, InvalidSignature: ... return type <class 'dict'> is not serializable for structured output.

Root cause

In _create_output_model, bare containers are plain classes with no annotations, so they fell into the "other class types" branch:

else:
    type_hints = get_type_hints(type_annotation)   # {} for bare dict/list/tuple
    if type_hints:
        model = _create_model_from_class(...)
    # empty -> model stays None == "silently opt out"

dict[str, Any] never took that path (it is a GenericAlias), which is why only the bare form misbehaved.

Change

Handle bare containers as their parameterised equivalents before the generic class branch:

elif type_annotation in (dict, list, tuple):
    model = _create_wrapped_model(func_name, original_annotation)
    wrap_output = True

That matches the behaviour the docs already promise for dict[str, Any] (a {"result": ...} wrapper), and keeps str/int/... unchanged.

Tests

Added to tests/server/mcpserver/test_func_metadata.py:

  • parametrised over dict, list, tuple: func_metadata(func).output_model is not None and wrap_output is True (previously None/False);
  • func_metadata(func) -> dict with structured_output=True produces a model that validates {"a": 1} into {"result": {"a": 1}} (previously raised InvalidSignature).

…tput model

A tool annotated with a bare `dict` (or `list` / `tuple`) produced no output
model: those classes have no type hints, so they reached the generic class
branch, `get_type_hints()` came back empty and the model stayed None. The tool
therefore advertised no outputSchema and returned no structuredContent, and
`structured_output=True` raised InvalidSignature claiming the return type was
not serializable for structured output.

Treat bare containers like their parameterised equivalents (wrapped in
{"result": ...}), which is what `dict[str, Any]` already did.

Fixes modelcontextprotocol#3725
@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 20, 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 #3725.

If a maintainer assigns you to #3725, 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 20, 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.

Bare dict / list / tuple return annotations silently produce no structured output

1 participant