How to use HTTP Streamable transport for MCP server and client in .NET csharp-sdk?
The modelcontextprotocol/csharp-sdk repo (June 2025) had no samples for the HTTP Streamable transport, and the API is confusing: the client transport class is named SseClientTransport. How do I set up a Streamable HTTP MCP server and client in .NET, and can the server return JSON instead of SSE? When I run the same server code with VS Code as the MCP client, I get "Discovered 0 tools" and "Connection state: Error ; will retry with new session ID".
Originally asked on GitHub: https://github.com/modelcontextprotocol/csharp-sdk/issues/449
5 answers
The issue is closed (completed); the working setup was shared in the thread by a community member, and a project contributor clarified the JSON vs SSE behavior.
Server (ASP.NET Core)
csharpvar builder = WebApplication.CreateBuilder(args); builder.Services.AddMcpServer() .WithHttpTransport(options => options.Stateless = true) .WithToolsFromAssembly(); var app = builder.Build(); app.UseHttpsRedirection(); app.MapMcp(); app.Run();Another user got the same server working by registering tools with
.WithTools<MyControllerOrFileName>()and mappingendpoints.MapMcp("/mcp")for a custom path.Client
Use
SseClientTransportwithTransportMode = HttpTransportMode.StreamableHttpand a URI that does not include/sse:csharpvar clientTransport = new SseClientTransport(new SseClientTransportOptions { Endpoint = new Uri("https://localhost:7042"), TransportMode = HttpTransportMode.StreamableHttp }); var mcpClient = await McpClientFactory.CreateAsync(clientTransport);One commenter noted the SDK's
StreamableHttpClientSessionTransportisinternaland guessed this is the intended usage; another commenter stated that with thisTransportModethe client won't attempt an SSE connection even as a fallback. There is no maintainer confirmation in the thread.JSON vs SSE: a project contributor explained the csharp-sdk client supports both JSON and SSE responses as the spec requires, but the server currently only produces SSE responses (which the spec allows). A JSON-only server response like the TypeScript SDK's
enableJsonResponse: trueis not supported yet and is tracked in issue #545.The "Discovered 0 tools" / "Connection state: Error" problem with VS Code as the client was reported in this thread but not resolved there. General advice: check that the server is reachable at the exact path you mapped (root vs
/mcp) and that your client configuration matches.Note: the sample client stores Azure OpenAI credentials in Program.cs — replace them with your own and keep secrets out of source control.
Did this work for you?What @ahmar-husain tried on GitHub (Worked)
A commenter shared a complete working setup: server with
WithHttpTransport(options => options.Stateless = true)andapp.MapMcp(), client withSseClientTransportandTransportMode = HttpTransportMode.StreamableHttppointing at the root URI without/sse.Did this work for you?What @vandana2015 tried on GitHub (Worked)
Another user got the server working with
.WithTools<MyControllerOrFileName>()andendpoints.MapMcp("/mcp")to serve on a custom path.Did this work for you?What @ahmar-husain tried on GitHub (Didn't work)
A commenter inspected the SDK source code looking for a JSON-only response option and concluded it is not possible with the current SDK.
Did this work for you?What @ananthubabu-geodis tried on GitHub (Outcome unclear)
A user ran the same server code with VS Code as the MCP client and got "Discovered 0 tools" plus "Connection state: Error ; will retry with new session ID"; no fix was provided in the thread.
Did this work for you?
Related questions
- Does the C# MCP SDK implement the Streamable HTTP transport (2025-03-26 spec)?
- How to pass HttpContext/bearer token from /message endpoint to MCP tool handler in csharp-sdk?
- Why is there no MCP Streamable HTTP server support on .NET Framework?
- C# MCP SDK: decouple StructuredContent from Content in McpServerTool results?
- Can I build MCP Apps with the C# SDK?