Skip to content

fix: handle bare MCP request types for fastmcp 3.x compatibility#1813

Merged
alexmojaki merged 2 commits intomainfrom
claude/slack-session-OAI1n
Mar 27, 2026
Merged

fix: handle bare MCP request types for fastmcp 3.x compatibility#1813
alexmojaki merged 2 commits intomainfrom
claude/slack-session-OAI1n

Conversation

@alexmojaki
Copy link
Copy Markdown
Collaborator

Summary

  • Fix AttributeError: 'ReadResourceRequest' object has no attribute 'root' when using logfire.instrument_mcp() with fastmcp 3.x
  • The MCP integration assumed requests always have a .root attribute (RootModel wrappers like ClientRequest), but fastmcp 3.x can send bare request types directly when OTel context propagation is active
  • Use getattr(request, 'root', request) fallback to handle both RootModel wrappers and bare request types

Test plan

  • Existing MCP integration tests should continue to pass
  • Manual testing with fastmcp 3.x using the reproduction script from the Slack thread

Slack thread: https://pydantic.slack.com/archives/C08KLDX918V/p1774633203047079?thread_ts=1774364407.066059&cid=C08KLDX918V

https://claude.ai/code/session_01BRaoRh5qKYjqJxMrxDpxJQ

…compatibility

The MCP integration assumed requests always have a `.root` attribute (RootModel
wrappers like ClientRequest), but fastmcp 3.x can send bare request types directly
(e.g. ReadResourceRequest) when OTel context propagation is active. This caused
AttributeError crashes.

Use getattr fallback to handle both cases - RootModel wrappers use `.root`,
bare request types fall back to themselves.

https://claude.ai/code/session_01BRaoRh5qKYjqJxMrxDpxJQ
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 27, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 47c5342
Status: ✅  Deploy successful!
Preview URL: https://d3a6643f.logfire-docs.pages.dev
Branch Preview URL: https://claude-slack-session-oai1n.logfire-docs.pages.dev

View logs

devin-ai-integration[bot]

This comment was marked as resolved.

@alexmojaki alexmojaki enabled auto-merge (squash) March 27, 2026 17:45
@alexmojaki alexmojaki disabled auto-merge March 27, 2026 17:45
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 No tests added for the bare request type (fastmcp 3.x) code path

The PR adds defensive getattr guards to handle bare request types sent by fastmcp 3.x, but there are no new tests exercising this code path. The existing tests in test_openai_agents_mcp.py and test_pydantic_ai_mcp.py use the standard MCP library which sends RootModel wrappers. If fastmcp 3.x is not a test dependency, this fallback path is untested. While the logic is straightforward, a test with a mock bare request type would increase confidence.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(Claude) Noted, tracking in questions.md — the getattr fallback is straightforward but testing the fastmcp 3.x bare-type path would require adding it as a test dependency, which is beyond scope for this compatibility fix.

@alexmojaki alexmojaki merged commit 5b37781 into main Mar 27, 2026
25 checks passed
@alexmojaki alexmojaki deleted the claude/slack-session-OAI1n branch March 27, 2026 18:00
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.

2 participants