Skip to content

feat(server): add --transport option and STDIO mode to Program.cs #21

@CalvinAllen

Description

@CalvinAllen

Parent Epic

Part of #18 - STDIO Transport Support

Description

Modify Server Program.cs to support both HTTP and STDIO transports via a command-line option.

Implementation

Modify: src/CodingWithCalvin.MCPServer.Server/Program.cs

New Command Line Option

var transportOption = new Option<string>(
    name: "--transport",
    getDefaultValue: () => "http",
    description: "MCP transport: 'http' (HTTP/SSE server) or 'stdio' (STDIO transport)");

STDIO Mode Logic

if (transport == "stdio")
{
    // 1. Create RpcServer with well-known pipe name
    var rpcServer = new RpcServer(shutdownCts);
    await rpcServer.StartAsync(McpConstants.StdioPipeName);
    
    // 2. Wait for VS Extension to connect (with timeout)
    await rpcServer.WaitForConnectionAsync(TimeSpan.FromSeconds(60));
    
    // 3. Build MCP server with STDIO transport
    // Use Host.CreateDefaultBuilder() instead of WebApplication
    // Use WithStdioServerTransport() instead of WithHttpTransport()
    
    // 4. Run until shutdown
}
else // http mode - unchanged
{
    // Existing implementation
}

Error Handling

  • Clear error message if VS doesn't connect within timeout
  • Proper cleanup on CTRL+C / shutdown

Dependencies

Acceptance Criteria

  • --transport option added (http/stdio)
  • HTTP mode unchanged (regression test)
  • STDIO mode creates pipe server
  • STDIO mode uses STDIO transport for MCP
  • Timeout with helpful error message

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions