Repository navigation
Tags
Tags
fix: drop inherited HTTP request headers on in-process requests (#5) ## Description An in-process MCP client called from inside a Streamable HTTP handler could inherit the HTTP headers of the request that handler was serving. The inner server then validated those headers as if they belonged to the in-process request. This could make the nested call fail, because the headers came from an unrelated outer request. This PR fixes that in two parts: - It adds `server.WithoutRequestHeaders(ctx)`. It returns a context that carries no HTTP request headers, and returns the context unchanged if it has none. - `InProcessTransport` now calls it in both `SendRequest` and `SendNotification`, before the session is attached to the context. In-process requests are therefore never checked against headers from an outer HTTP request. A new test, `TestInProcessMCPClient_CalledFromAStreamableHTTPHandler`, covers this scenario. An outer server exposed over Streamable HTTP has a tool that calls an inner server through an in-process client. The test runs with protocol versions `2026-07-28` and `2025-11-25` on the outer connection and checks that the nested call succeeds. Fixes #<issue_number> (if applicable) ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] MCP spec compatibility implementation - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [ ] Code refactoring (no functional changes) - [ ] Performance improvement - [ ] Tests only (no functional changes) - [ ] Other (please describe): ## Checklist - [ ] My code follows the code style of this project - [ ] I have performed a self-review of my own code - [x] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the documentation accordingly ## MCP Spec Compliance - [ ] This PR implements a feature defined in the MCP specification - [ ] Link to relevant spec section: [Link text](https://modelcontextprotocol.io/specification/path-to-section) - [ ] Implementation follows the specification exactly ## Additional Information `WithoutRequestHeaders` is exported from the `server` package so the client transport can use it. It only replaces the header value when one is already present in the context, so contexts that never passed through an HTTP handler are left untouched.