Skip to content

Commit 9d8eb14

Browse files
andyjmorganclaude
andcommitted
fix: handle MCP ping at bridge level for servers that don't support it
server-filesystem silently drops ping requests, causing MCP Inspector and other Streamable HTTP clients to timeout on their first connectivity check. The bridge now responds to ping directly without forwarding to the child process. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a660be5 commit 9d8eb14

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/DonkeyWork.CodeSandbox.McpServer/Services/StdioBridge.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ void Emit(string eventType, string message, Action<McpStartEvent>? configure = n
187187

188188
// Extract method name for logging
189189
var method = ExtractMethod(jsonRpcRequest);
190+
191+
// Handle ping at the bridge level - not all MCP servers respond to ping
192+
if (method == "ping")
193+
{
194+
_logger.LogInformation("Handling ping request id={Id} at bridge level", requestId);
195+
lock (_stateLock) _lastRequestAt = DateTime.UtcNow;
196+
var rawId = ExtractRawId(jsonRpcRequest);
197+
return $"{{\"jsonrpc\":\"2.0\",\"result\":{{}},\"id\":{rawId}}}";
198+
}
199+
190200
_logger.LogInformation("Sending request id={Id} method={Method}, registering TCS", requestId, method);
191201

192202
// Register the TCS BEFORE writing to stdin to avoid a race where
@@ -638,6 +648,12 @@ private static bool IsNotification(string json)
638648
}
639649
}
640650

651+
private static string ExtractRawId(string json)
652+
{
653+
using var doc = JsonDocument.Parse(json);
654+
return doc.RootElement.GetProperty("id").GetRawText();
655+
}
656+
641657
private static string? ExtractMethod(string json)
642658
{
643659
try

0 commit comments

Comments
 (0)