Closed
Conversation
5bce794 to
6dcbb3d
Compare
6dcbb3d to
1952bfd
Compare
Contributor
Author
|
@ihrpr @jerome3o-anthropic can you review ? |
ihrpr
requested changes
Apr 29, 2025
Contributor
ihrpr
left a comment
There was a problem hiding this comment.
- motivation and context is missing
- test evidence missing
Contributor
Author
updated |
There was a problem hiding this comment.
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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