Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Nov 15, 2025

Reduces the overcomplicated $ref resolution logic to a simple check. Self-referencing types always produce object schemas in our use case.

Note: this is what #2424 SHOULD have been except it was prematurely opened and merged by LLM.

Actually closes #2421

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2025

Walkthrough

The _is_object_schema function in src/fastmcp/tools/tool.py was simplified to use a more deterministic approach. The function now returns True when a schema contains a $ref that also includes a $defs, or when the schema has an explicit object type or properties. The previous recursive resolution traversal logic was removed and replaced with a single-condition check. The docstring was shortened accordingly. No exported public signatures were modified.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description explains the change rationale but is missing required checklist items from the template (no checkboxes completed, no issue closure reference in standard format). Complete the Contributors and Review checklists from the template, and format the issue closure as '- [x] My change closes #2421' for clarity.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: simplifying the _is_object_schema helper function.
Linked Issues check ✅ Passed The PR addresses issue #2421 by simplifying the _is_object_schema logic to correctly handle self-referencing types, treating them as object schemas as intended.
Out of Scope Changes check ✅ Passed The changes are focused on simplifying the _is_object_schema helper function in src/fastmcp/tools/tool.py, which is directly related to fixing the self-referencing types issue without introducing unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch simplify-object-schema-check

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6936d0 and e9667b6.

⛔ Files ignored due to path filters (1)
  • tests/server/test_server.py is excluded by none and included by none
📒 Files selected for processing (1)
  • src/fastmcp/tools/tool.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run tests: Python 3.10 on windows-latest
🔇 Additional comments (1)
src/fastmcp/tools/tool.py (1)

380-382: The simplification is pragmatic but test coverage for edge cases is missing.

The assumption that schemas containing both $ref and $defs at root level always represent objects is intentional and well-documented in code comments. For Pydantic/dataclass auto-generated schemas (line 499, the primary use case per issue #2421), this assumption holds. However, no unit tests were found to validate this assumption or cover edge cases for user-provided explicit schemas (line 299).

A malformed user schema like {"$ref": "#/$defs/MyStr", "$defs": {"MyStr": {"type": "string"}}} would pass this check but isn't actually an object type. While unlikely in practice, this edge case is unvalidated.

The PR intentionally chose pragmatic simplification over defensive validation. Consider whether test coverage for edge cases in user-provided explicit schemas is needed before merging, or document this as an acceptable risk given the MCP spec requirement that output schemas must be objects (which may implicitly filter such cases).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@marvin-context-protocol marvin-context-protocol bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. server Related to FastMCP server implementation or server-side functionality. labels Nov 15, 2025
@jlowin jlowin merged commit b5f88bf into main Nov 15, 2025
10 checks passed
@jlowin jlowin deleted the simplify-object-schema-check branch November 15, 2025 17:39
@dhdaines
Copy link

Excellent, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self-referencing types not supported correctly in structured output

3 participants