Fix MCP header encoding for non-ASCII values#27771
Conversation
|
📊 PR Size: size/M
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where MCP HTTP transports failed to handle non-ASCII characters in configured headers. By implementing a normalization step that encodes these values into a format compatible with Fetch headers, the change ensures that discovery processes remain robust even when using Unicode text in header configurations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces header value encoding for HTTP and SSE transports in the MCP client to prevent errors when headers contain non-ByteString characters (such as UTF-8 characters). It adds helper functions encodeHeaderValuesForFetch and isByteString to convert non-ByteString values into Latin-1, and applies this encoding in createTransportRequestInit and createSSETransportWithAuth. A corresponding unit test has been added to verify this behavior. No review comments were provided, so there is no additional feedback to address.
Summary
Fixes #25668.
MCP HTTP transports now encode configured header values that cannot be passed to Fetch as
ByteStringvalues. This prevents discovery from failing when a configured header contains Unicode text such asmąka.Changes
ByteStringvalues.ByteStringvalues as UTF-8 bytes represented in Latin-1, which keeps FetchHeadersvalidation from throwing while preserving the intended bytes.httpUrlMCP server configured with a non-ASCII header value.Verification