Project: SharpClaw.Code.Mcp
Registration: McpServiceCollectionExtensions.AddSharpClawMcp (pulled in by AddSharpClawRuntime)
MCP sessions use the ModelContextProtocol NuGet package (official MCP C# SDK, version pinned in Directory.Packages.props). SharpClaw keeps registry, CLI, Protocol DTOs, and diagnostics as first-party code; SdkMcpProcessSupervisor drives:
- stdio —
StdioClientTransport+McpClient(subprocess;--commandis the executable,--argfor arguments). - http / https —
HttpClientTransportwithHttpTransportMode.AutoDetect(streamable HTTP with SSE fallback);--commandmust be an absolute URL (for examplehttps://host/mcp). - streamable-http —
HttpTransportMode.StreamableHttpexplicitly. - sse —
HttpTransportMode.Ssefor legacy SSE endpoints.
Initialize, session lifetime, and capability discovery use ListTools / ListPrompts / ListResources counts.
Active sessions are stopped by disposing the SDK client via an opaque SessionHandle on McpServerStatus. The official stdio client does not expose the child process Pid on its public surface; use SessionHandle for mcp stop. HTTP transports have no OS process Pid.
FileBackedMcpRegistry persists definitions and status under:
{workspace}/.sharpclaw/mcp/servers.json
(JSON with McpServerDefinition map + McpServerStatus map — Web defaults; indented.)
RegisteredMcpServer (Protocol + status) is returned from IMcpRegistry register/list/get operations.
| Interface | Role |
|---|---|
IMcpRegistry |
Register/list/get servers, UpdateStatusAsync |
IMcpServerHost |
StartAsync, StopAsync, RestartAsync, GetStatusAsync |
IMcpDoctorService |
Workspace MCP diagnostics → CommandResult |
IMcpProcessSupervisor |
SDK-backed sessions (SdkMcpProcessSupervisor: stdio + HTTP/SSE) |
Lifecycle state is tracked in McpServerStatus (Protocol McpLifecycleState, McpFailureKind, SessionHandle, tool/prompt/resource counts, etc.).
Subcommands of mcp (see McpCommandHandler):
list/status— delegate toIMcpDoctorService.GetStatusAsyncregister—--id,--name,--command(executable or absolute MCP URL), optional--transport(stdio,http,https,streamable-http,sse; defaultstdio), repeatable--arg,--enabledstart,stop,restart—--id;IMcpServerHostdoctor—IMcpDoctorService.RunDoctorAsync
Global CLI options apply (--cwd, --output-format, …).
JSON DataJson for register/start/stop/restart uses ProtocolJsonContext where types are RegisteredMcpServer / McpServerStatus. MCP doctor/status payloads serialize failureKind with the protocol enum names (none, startup, handshake, capabilities, runtime).
McpDoctorService still builds some diagnostic payloads with anonymous objects (see ARCHITECTURE-NOTES.md).
Runtime doctor includes McpRegistryHealthCheck (registry + optional host).