fix(mcp): treat "method not found" ping responses as healthy (#1)

MCP servers that don't implement the `ping` method return a "method not
found" error. The health loop previously treated this as a failure,
triggering exponential backoff reconnects and making tools temporarily
unavailable.

Now uses case-insensitive matching to detect "method not found" responses
and treats the server as healthy (it did respond, just doesn't support
ping). Resets reconnect attempts and clears error state.
This commit is contained in:
Michael authored and GitHub committed 2026-02-27 16:02:53 +07:00
1 parent 99c0d7e445
commit 406f83160e
1 file changed
+10
+10
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"strings"
"sync"
"sync/atomic"
"time"
@@ -338,6 +339,15 @@ func (m *Manager) healthLoop(ctx context.Context, ss *serverState) {
return
case <-ticker.C:
if err := ss.client.Ping(ctx); err != nil {
// Servers that don't implement "ping" are still alive — treat as healthy.
if strings.Contains(strings.ToLower(err.Error()), "method not found") {
ss.connected.Store(true)
ss.mu.Lock()
ss.reconnAttempts = 0
ss.lastErr = ""
ss.mu.Unlock()
continue
}
ss.connected.Store(false)
ss.mu.Lock()
ss.lastErr = err.Error()