Fix MCP connection failure on notifications/initialized due to CORS preflight#19
Closed
Fix MCP connection failure on notifications/initialized due to CORS preflight#19
Conversation
Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
…ents Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
…larity Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add client initialization protocol for remote service
Fix MCP connection failure on notifications/initialized due to CORS preflight
Feb 9, 2026
Contributor
|
@copilot 这个pr做了什么?你是如何实现的? |
Contributor
Author
这个 PR 修复了浏览器连接 MCP 服务器时第二个请求失败的问题。 问题原因: 实现方案:
这样既避免了 CORS preflight 问题,又保持了完整的 MCP 协议兼容性(协议版本仍在 initialize 请求/响应体中协商)。 主要改动在 |
Contributor
|
@copilot 原先存在的问题如何复现? |
Contributor
Author
复现步骤:
根本原因: 验证修复: |
Contributor
|
No help for MCP server which does not support CORS, close this PR for now. |
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.
Browser connections to MCP servers fail on the second request (
notifications/initialized) when servers don't handle CORS preflight for themcp-protocol-versioncustom header. Observed withhttps://slips-mcp-dev.up.railway.app/.Changes
BrowserCompatibleTransportwrapper that delegates all Transport methods toStreamableHTTPClientTransportbut omitssetProtocolVersionimplementationmcp-protocol-versionheader from being sent, avoiding CORS preflight while maintaining protocol compatibility (version still negotiated in initialize request/response body)McpClientto use wrapper instead of direct transportTechnical Details
The MCP SDK calls
transport.setProtocolVersion()after initialization if the method exists:Our wrapper intentionally does not implement this method:
The
mcp-protocol-versionheader is informational - protocol version is already established through the initialize handshake body. Omitting the header prevents CORS preflight without affecting compatibility.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.