Repository navigation
feat(mcp): headers for HTTP MCP servers - #280
Merged
Merged
Conversation
HttpTransport::with_header(name, value) sends a header on every request of the session (initialize, the initialized notification, tool calls and the closing DELETE) through one request helper. Replace on repeat; values marked sensitive; invalid or reserved names (Accept, Content-Type, Mcp-Session-Id) refused before sending, without echoing the value. McpClient::connect_http_with and Agent::with_mcp_server_http_transport connect through a configured transport; connect_http and with_mcp_server_http are unchanged and now delegate to them. Closes #275. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
Review of #280: HeaderValue accepts bytes 0x80-0xFF, which wasm32's reqwest refuses on every request (and many servers reject), so with_header now requires visible ASCII. Content-Length, Transfer-Encoding, Connection and Host are reserved too. The wasm32 MCP test now sends an authorization header through the host's fetch and checks it on every request. Docs note that a browser may drop some headers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
Merged
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.
Closes #275.
Per the issue:
initialize,notifications/initialized, tool calls and the closingDELETE— through one privaterequest(Method)helper used by all three paths.Accept,Content-Type,Mcp-Session-Id.HttpTransport::new,connect_httpandwith_mcp_server_httpbehave as before (they now delegate to the new constructors).fetch.Tests (
tests/mcp_http_transport_test.rs): a server that 404s without the headers — a full session throughMcpClient::connect_http_with(all five requests carry both headers, checked per request sinceclosetolerates a rejected DELETE; mutation-checked by sending the DELETE without them); an agent connecting throughwith_mcp_server_http_transportand calling the discovered tool; the same server refusing a plain connect; refusals (bad name, CRLF value not echoed, reserved names any case); replacement; a plain transport sending no auth/User-Agent; a unit test that values are sensitive. Full suite: 1524 passed. Docs: MCP guide "Servers that need headers", Workers guide, CHANGELOG, CLAUDE.md.This is the general version of what #271 needed (caller identification).
🤖 Generated with Claude Code
https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG