Repository navigation
Open
Description
Parent Epic
Part of #18 - STDIO Transport Support (Broker + Shim Architecture)
Description
Modify Server.exe to support broker mode: bind to an OS-assigned port (port 0) and register with the broker on startup, deregister on shutdown, and re-register when the solution changes.
Implementation
Modify: src/CodingWithCalvin.MCPServer.Server/Program.cs
New CLI Option
var brokerPortOption = new Option<int>(
name: "--broker-port",
getDefaultValue: () => 0,
description: "Broker port to register with (0 = standalone mode, no broker)");Broker Mode Logic (--broker-port > 0)
- Bind
http://localhost:0instead of configured port (OS assigns available port) - Split
app.RunAsync()intoapp.StartAsync()+app.WaitForShutdownAsync()to get the actual port - Read actual port from
IServerAddressesFeatureafter start - Fetch solution info via RPC:
rpcClient.GetSolutionInfoAsync() - POST
InstanceRegistrationtohttp://localhost:{brokerPort}/api/instances - On
ApplicationStopping: DELETEhttp://localhost:{brokerPort}/api/instances/{instanceId}(best-effort, short timeout)
Standalone Mode (--broker-port == 0)
Existing behavior, completely unchanged. Uses --port value as before.
Modify: src/CodingWithCalvin.MCPServer.Server/RpcClient.cs
Implement the new IServerRpc.OnSolutionChangedAsync(...):
- Store broker URL and instance ID as fields
- On call: re-POST registration to broker with updated solution info (upsert by instanceId)
Registration Payload
{
"instanceId": "generated-guid",
"solutionPath": "C:/repos/MyApp/MyApp.sln",
"solutionDirectory": "C:/repos/MyApp",
"displayName": "Visual Studio MCP",
"vsPid": 12345,
"serverPort": 52341,
"serverHost": "localhost"
}instanceId: new GUID generated at Server.exe startupsolutionPath/solutionDirectory: fromGetSolutionInfoAsync()(nullable if no solution open)displayName: from--nameCLI argvsPid: parsed from pipe name (vsmcp-{pid})serverPort: actual bound port from Kestrel
Dependencies
- Requires Phase 1 (shared models + RPC contract)
- Requires Phase 2 (broker with registration endpoints)
Acceptance Criteria
-
--broker-portCLI option added - Standalone mode (
--broker-port 0) works exactly as before - Broker mode binds port 0 and reads actual assigned port
- Registration POST sent to broker on startup
- Deregistration DELETE sent to broker on shutdown
-
OnSolutionChangedAsyncre-registers with updated solution info - Graceful handling when broker is unreachable
Metadata
Metadata
Assignees
Labels
No labels
Activity