-
Notifications
You must be signed in to change notification settings - Fork 580
fix(mcp): Nest MCP spans under HTTP transactions #5292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Span Streaming
Other
Bug Fixes 🐛Google Genai
Mcp
Span Streaming
Other
Internal Changes 🔧Fastmcp
Mcp
Other
Other
🤖 This preview updates automatically when you update the PR. |
sentrivana
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments, but other than that LGTM!
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.35s All tests are passing successfully. ❌ Patch coverage is 1.82%. Project has 13629 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Description
Patch
StreamableHTTPServerTransport.handle_request()to store isolation and current scopes on the Starlette request object'sscopeattribute.Run MCP handlers in the context of the stored scopes, if these are available.
Modify
use_isolation_scope()anduse_scope()context managers to acceptNone. The MCP protocol allows for transport layers that are not HTTP-based, so the scopes may not be available.The Python MCP SDK uses an in-memory queue of requests. The HTTP propagation context is not active in the MCP decorators we patch, since they run after requests are retrieved from the queue.
Issues
Closes #5272
Closes PY-2022
Closes TET-1688
Reminders
tox -e linters.feat:,fix:,ref:,meta:)