-
Notifications
You must be signed in to change notification settings - Fork 2.9k
sse-pass-http-req #549
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
sse-pass-http-req #549
Conversation
5bce794 to
6dcbb3d
Compare
6dcbb3d to
1952bfd
Compare
|
@ihrpr @jerome3o-anthropic can you review ? |
ihrpr
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.
- motivation and context is missing
- test evidence missing
updated |
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.
-
HTTP Request Context Exposure:
- This feature exposes HTTP transport details to tools, which breaks the transport abstraction layer that MCP is designed to maintain.
- The MCP is designed to be transport-agnostic, and exposing HTTP-specific details leaks implementation details into the protocol.
-
Maintenance Cost & Complexity:
- Adding this feature increases complexity by creating dependencies between the transport layer and tools.
- It may introduce issues when other transport types are used (WebSockets, gRPC, etc.) as they would need to conform to HTTP-like interfaces.
-
Security Considerations:
- Exposing raw HTTP request objects to tools could create security vulnerabilities if tools access sensitive headers or data.
- No validation or sanitization of headers is implemented before passing them to tools.
-
Architectural Concerns:
- This approach tightly couples the FastAPI implementation with the MCP protocol layer.
-
Test Coverage:
- While the PR description mentions tests in a real application, there are no unit tests added to verify this behavior.
- The changes to the serialization mechanism have updated tests, but the core feature has no tests.
Motivation and Context
When working with MCP tools, particularly over Server-Sent Events (SSE), it's important to access request metadata such as headers, IP addresses, and other context. This is crucial for features like authorization, tenant resolution, request tracing, and custom routing logic. By default, SSE provides limited context handling, which poses a challenge when such metadata is needed in downstream tools.
To solve this, I extended the MCP server to inject the request context into tool invocations. This allows tools to access request headers and additional metadata even in long-lived SSE streams. The implementation also abstracts transport-specific logic, making it easy to support future transport types like WebSockets or gRPC.
How Has This Been Tested?
This change has been tested in a real MCP application with SSE transport. Scenarios tested:
Validating that tools correctly receive request headers (e.g., Authorization, X-Custom-Tenant-ID).
Injecting and accessing request query parameters within tools.
Ensuring SSE connections remain stable while context is being passed.
Fallback behavior when context is missing or malformed.
Regression tested for standard tool flows to ensure no breaking changes.
Breaking Changes
Types of changes
Checklist
Additional context