-
Notifications
You must be signed in to change notification settings - Fork 368
Automatically fall back from Streamable HTTP to SSE on the client by default #456
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
Merged
+489
−49
Conversation
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
…default - Adds automatic transport detection to the client that tries Streamable HTTP first and falls back to SSE if that fails and makes it the default - This matches VS Code's behavior for maximum compatibility when sharing mcp.json files.
stephentoub
reviewed
May 28, 2025
src/ModelContextProtocol/Client/AutoDetectingClientSessionTransport.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
May 28, 2025
src/ModelContextProtocol/Client/AutoDetectingClientSessionTransport.cs
Outdated
Show resolved
Hide resolved
- Improve test names
stephentoub
reviewed
May 28, 2025
stephentoub
approved these changes
May 28, 2025
halter73
commented
May 28, 2025
halter73
commented
May 28, 2025
src/ModelContextProtocol/Client/StreamableHttpClientSessionTransport.cs
Outdated
Show resolved
Hide resolved
…g messages - This might fix the WithProgress_ProgressReported failures Failed ModelContextProtocol.Tests.Client.McpClientExtensionsTests.WithProgress_ProgressReported [22 ms] Error Message: System.IO.IOException : Transport is already disconnected and can't be reconnected. Stack Trace: at ModelContextProtocol.Protocol.TransportBase.SetConnected() in /_/src/ModelContextProtocol/Protocol/TransportBase.cs:line 125 at ModelContextProtocol.Client.StreamClientSessionTransport..ctor(TextWriter serverInput, TextReader serverOutput, String endpointName, ILoggerFactory loggerFactory) in /_/src/ModelContextProtocol/Client/StreamClientSessionTransport.cs:line 54 at ModelContextProtocol.Protocol.StreamClientTransport.ConnectAsync(CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/StreamClientTransport.cs:line 49 at ModelContextProtocol.Client.McpClient.ConnectAsync(CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/McpClient.cs:line 105 at ModelContextProtocol.Client.McpClient.ConnectAsync(CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/McpClient.cs:line 164 at ModelContextProtocol.Client.McpClientFactory.CreateAsync(IClientTransport clientTransport, McpClientOptions clientOptions, ILoggerFactory loggerFactory, CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/McpClientFactory.cs:line 37 at ModelContextProtocol.Client.McpClientFactory.CreateAsync(IClientTransport clientTransport, McpClientOptions clientOptions, ILoggerFactory loggerFactory, CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/McpClientFactory.cs:line 46 at ModelContextProtocol.Tests.ClientServerTestBase.CreateMcpClientForServer() in /_/tests/ModelContextProtocol.Tests/ClientServerTestBase.cs:line 67 at ModelContextProtocol.Tests.Client.McpClientExtensionsTests.WithProgress_ProgressReported() in /_/tests/ModelContextProtocol.Tests/Client/McpClientExtensionsTests.cs:line 356 --- End of stack trace from previous location --- Standard Output Messages: | [2025-05-28T16:24:33] ModelContextProtocol.Client.StreamClientSessionTransport Information: Client (stream) transport reading messages. | [2025-05-28T16:24:33] ModelContextProtocol.Client.StreamClientSessionTransport Warning: Client (stream) transport message reading failed. System.InvalidOperationException: Transport is not connected. at ModelContextProtocol.Protocol.TransportBase.WriteMessageAsync(JsonRpcMessage message, CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Protocol/TransportBase.cs:line 91 at ModelContextProtocol.Client.StreamClientSessionTransport.ProcessMessageAsync(String line, CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/StreamClientSessionTransport.cs:line 134 at ModelContextProtocol.Client.StreamClientSessionTransport.ReadMessagesAsync(CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/StreamClientSessionTransport.cs:line 108 | [2025-05-28T16:24:33] ModelContextProtocol.Client.StreamClientSessionTransport Information: Client (stream) shutting down. | [2025-05-28T16:24:33] ModelContextProtocol.Client.StreamClientSessionTransport Information: Client (stream) shut down. | [2025-05-28T16:24:33] ModelContextProtocol.Client.McpClient Error: in-memory-stream client initialization error. System.IO.IOException: Transport is already disconnected and can't be reconnected. at ModelContextProtocol.Protocol.TransportBase.SetConnected() in /_/src/ModelContextProtocol/Protocol/TransportBase.cs:line 125 at ModelContextProtocol.Client.StreamClientSessionTransport..ctor(TextWriter serverInput, TextReader serverOutput, String endpointName, ILoggerFactory loggerFactory) in /_/src/ModelContextProtocol/Client/StreamClientSessionTransport.cs:line 54 at ModelContextProtocol.Protocol.StreamClientTransport.ConnectAsync(CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/StreamClientTransport.cs:line 49 at ModelContextProtocol.Client.McpClient.ConnectAsync(CancellationToken cancellationToken) in /_/src/ModelContextProtocol/Client/McpClient.cs:line 105 - https://github.com/modelcontextprotocol/csharp-sdk/actions/runs/15305366319/job/43056566292?pr=456
eiriktsarpalis
approved these changes
May 28, 2025
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.
IMcpEndpoint
,IMcpClient
, andIMcpServer
types to classes. #355I used copilot for the initial stages of this PR on Friday, but then took it over myself to avoid the awkward Channel forwarding by making it a constructor parameter and removing a bunch of extraneous code. I might have been able to coach Copilot to do this as well, but at that point it felt easier to just do it. It was really helpful for stuff like writing tests and brainstorming option names.
Fixes #440 @AArnott