Skip to content

feat: Add configurable STDIO and HTTP transport support for MCP server#143

Open
Meir017 wants to merge 7 commits intomainfrom
005-mcp-stdio-and
Open

feat: Add configurable STDIO and HTTP transport support for MCP server#143
Meir017 wants to merge 7 commits intomainfrom
005-mcp-stdio-and

Conversation

@Meir017
Copy link
Owner

@Meir017 Meir017 commented Oct 11, 2025

Summary

Implements configurable transport modes for the MCP (Model Context Protocol) server, supporting both STDIO (standard input/output) and HTTP transports. This allows the server to work seamlessly with different MCP client types.

Changes

Core Implementation

  • Dual Transport Support: STDIO and HTTP transport modes
  • Unified Architecture: Uses WebApplicationBuilder with NoOpServer for STDIO mode
  • Configuration-Driven: Supports appsettings.json, environment variables, and command-line arguments
  • Smart Defaults: STDIO as default (ideal for MCP servers), easily overrideable

Key Files

  • src/LoggerUsage.Mcp/Program.cs - Conditional transport registration with NoOpServer
  • src/LoggerUsage.Mcp/TransportOptions.cs - Transport configuration model with XML docs
  • src/LoggerUsage.Mcp/appsettings.json - STDIO default configuration
  • src/LoggerUsage.Mcp/appsettings.Development.json - STDIO for development
  • est/LoggerUsage.Mcp.Tests/TransportConfigurationTests.cs - Comprehensive tests (6 methods, 10 test cases)

Features

  1. STDIO Transport (Default)

    • Uses standard input/output streams
    • Ideal for VS Code, command-line tools, and MCP clients that spawn processes
    • Lower latency than HTTP
    • No network overhead
  2. HTTP Transport

    • Traditional HTTP+SSE endpoints
    • Supports remote connections
    • Multiple concurrent clients
    • Web-based integrations
  3. Configuration Options
    \\�ash

    Via command-line

    dotnet run --project src/LoggerUsage.Mcp -- --Transport:Mode=Http

    Via environment variable

    export Transport__Mode=Stdio

    Via appsettings.json

    { "Transport": { "Mode": "Stdio" } }
    \\

  4. Validation

    • Throws InvalidOperationException if configuration fails
    • Clear error messages for invalid transport modes

Technical Details

Architecture

Uses a unified WebApplicationBuilder with conditional configuration:

  • STDIO Mode: Registers NoOpServer to avoid Kestrel overhead, adds WithStdioServerTransport()
  • HTTP Mode: Uses default Kestrel server, adds WithHttpTransport() and MapMcp() middleware

NoOpServer Implementation

Custom IServer implementation that satisfies ASP.NET Core hosting requirements without starting an HTTP listener:
\\csharp
internal class NoOpServer : IServer
{
public IFeatureCollection Features { get; } = new FeatureCollection();
public void Dispose() { }
public Task StartAsync(...) => Task.CompletedTask;
public Task StopAsync(...) => Task.CompletedTask;
}
\\

Testing

  • 6 Transport Configuration Tests - All passing (10 test cases total)
    • Default STDIO behavior
    • Explicit HTTP/STDIO configuration
    • Invalid mode exception handling
    • Case-insensitive parsing (6 variations)
    • Configuration priority (command-line overrides)
  • ⚠️ 4 Integration Tests - Need refactoring for NoOpServer pattern (tracked separately)

Commits

  • \23f42ee\ - Planning and specification
  • \

- Complete feature specification with 8 functional requirements
- Research findings on ASP.NET Core configuration and MCP transports
- Data model for TransportOptions and TransportMode enum
- Configuration contract for CLI/config/env variable support
- Quickstart guide with 5 test scenarios
- 17 numbered tasks following TDD principles (6 tests, 11 implementation)
- Updated Copilot instructions with new framework dependencies

This feature enables LoggerUsage.Mcp to support both STDIO and HTTP
transports via --Transport:Mode command-line argument, maintaining
backward compatibility (defaults to HTTP).
- Add TransportMode enum (Http, Stdio) and TransportOptions class
- Add comprehensive configuration binding tests (6 test methods)
- Update appsettings.json with Transport:Mode = Http (production default)
- Update appsettings.Development.json with Transport:Mode = Stdio (dev preference)
- Modify Program.cs to read transport configuration and log selected mode
- Document limitation: STDIO transport not yet supported by ModelContextProtocol.AspNetCore 0.4.0-preview.1
- Server falls back to HTTP transport with warning when STDIO is configured

This implements FR-001 through FR-006 from spec.md with a documented limitation that
STDIO transport will be supported in a future update when the SDK adds support.
Comprehensive status document explaining:
- Completed tasks T001-T011
- Discovered ModelContextProtocol.AspNetCore 0.4.0-preview.1 limitation
- Current HTTP-only behavior with graceful STDIO fallback
- Remaining tasks and next steps
- Recommendation to document current state and wait for SDK update
BREAKTHROUGH: WithStdioServerTransport() method exists and works!

Implementation:
- Program.cs now switches between HostApplicationBuilder (STDIO) and WebApplicationBuilder (HTTP)
- HTTP transport uses WebApplication with MapMcp() middleware
- STDIO transport uses HostApplication with WithStdioServerTransport()
- Both transports fully functional and tested

Test Updates:
- Updated ConfigurationBinding_WithInvalidMode test to expect exceptions (correct behavior)
- All 6 transport configuration tests now passing
- Integration tests need refactoring for dual-builder architecture (4 failures)

Status: STDIO transport fully implemented and functional
Remaining: Fix integration tests, add documentation
Complete documentation covering:
- Configuration options (files, CLI args, env vars)
- HTTP vs STDIO transport characteristics and use cases
- Configuration priority and validation
- VS Code integration examples
- Troubleshooting common issues
- Performance considerations
- Architecture details
- Docker and production examples
- FAQ section

This completes T016 documentation task.
…onBuilder

Major improvements:
- Use single WebApplicationBuilder for both transports (simpler architecture)
- Implement NoOpServer for STDIO mode (avoids Kestrel overhead)
- Change default transport to STDIO (more appropriate for MCP servers)
- Add comprehensive XML documentation to TransportOptions (completes T017)
- Throw InvalidOperationException if configuration fails to load
- Remove conditional builder switching complexity

This cleaner approach:
- Fixes integration test issues (single builder type)
- Reduces code complexity
- Maintains full STDIO and HTTP functionality
- Better aligns with MCP server expectations (STDIO default)
- Update test name and assertion: DefaultsToStdio (was DefaultsToHttp)
- Update appsettings.json to use Stdio as default
- All 6 transport configuration tests now passing
- Integration tests still need updating (known issue, tracked separately)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant