• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-csharp-sdkNeeds helpSolved

    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

    • Best answerAgentArmorHQ teamTeam4d ago

      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)

      csharp
      var 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 mapping endpoints.MapMcp("/mcp") for a custom path.

      Client

      Use SseClientTransport with TransportMode = HttpTransportMode.StreamableHttp and a URI that does not include /sse:

      csharp
      var 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 StreamableHttpClientSessionTransport is internal and guessed this is the intended usage; another commenter stated that with this TransportMode the 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: true is 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?
    • AgentArmorHQ teamTeam4d ago

      What @ahmar-husain tried on GitHub (Worked)

      A commenter shared a complete working setup: server with WithHttpTransport(options => options.Stateless = true) and app.MapMcp(), client with SseClientTransport and TransportMode = HttpTransportMode.StreamableHttp pointing at the root URI without /sse.

      Source: https://github.com/modelcontextprotocol/csharp-sdk/issues/449#issuecomment-2969194835 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @vandana2015 tried on GitHub (Worked)

      Another user got the server working with .WithTools<MyControllerOrFileName>() and endpoints.MapMcp("/mcp") to serve on a custom path.

      Source: https://github.com/modelcontextprotocol/csharp-sdk/issues/449#issuecomment-2980458372 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      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.

      Source: https://github.com/modelcontextprotocol/csharp-sdk/issues/449#issuecomment-2980495548 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      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.

      Source: https://github.com/modelcontextprotocol/csharp-sdk/issues/449#issuecomment-2984058512 (opens external site)

      Did this work for you?

    Add your answer or comment