Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

barnuri
Copy link
Contributor

@barnuri barnuri commented Apr 21, 2025

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@barnuri barnuri force-pushed the sse-pass-http-req branch 2 times, most recently from 5bce794 to 6dcbb3d Compare April 22, 2025 06:56
@barnuri barnuri force-pushed the sse-pass-http-req branch from 6dcbb3d to 1952bfd Compare April 22, 2025 06:59
@barnuri
Copy link
Contributor Author

barnuri commented Apr 23, 2025

@ihrpr @jerome3o-anthropic can you review ?

Copy link
Contributor

@ihrpr ihrpr left a 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

@barnuri
Copy link
Contributor Author

barnuri commented Apr 29, 2025

  • motivation and context is missing
  • test evidence missing

updated

@barnuri barnuri requested a review from ihrpr April 29, 2025 20:01
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