From 46bd20b3d9562c7f639e89af3ed406a772f391ea Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Thu, 29 Oct 2026 11:10:22 +0200 Subject: [PATCH 1/3] fix(clients): credit mcp-remote-bridged Claude Desktop and codex-mcp-client sessions (#1786) Presence, the Clients hub and 24h call counts matched clientInfo.name exactly against ClientInfoNames. Claude Desktop through the mcp-remote bridge Connect writes sends "claude-ai (via mcp-remote )" and Codex CLI sends "codex-mcp-client", so both stayed connected_never_seen and their sessions landed in other: rows, one per mcp-remote version. clientidentity.AliasCandidate strips one trailing mcp-remote tag before known-alias lookup; it keeps controls like NormalizeRaw, so an escape-prefixed name still cannot pass as a supported client, and unknown names keep their exact key. Codex gains the codex-mcp-client alias. Stale bridged other: rows from earlier releases are hidden. Closes #1786 Co-Authored-By: Claude Opus 5.5 --- internal/clientidentity/client_identity.go | 17 ++++++ .../clientidentity/client_identity_test.go | 21 ++++++++ internal/connect/clients.go | 19 ++++--- internal/httpapi/clients.go | 9 ++-- internal/httpapi/clients_presence_test.go | 53 +++++++++++++++++++ .../clients_presence_generation_test.go | 18 +++++++ internal/runtime/runtime.go | 4 +- internal/runtime/usage_aggregate.go | 4 ++ internal/runtime/usage_aggregate_test.go | 16 ++++++ 9 files changed, 148 insertions(+), 13 deletions(-) diff --git a/internal/clientidentity/client_identity.go b/internal/clientidentity/client_identity.go index 8d54cd0a0..745cefc59 100644 --- a/internal/clientidentity/client_identity.go +++ b/internal/clientidentity/client_identity.go @@ -5,6 +5,7 @@ package clientidentity import ( "crypto/sha256" "encoding/hex" + "regexp" "strings" ) @@ -127,6 +128,22 @@ func NormalizeRaw(raw string) string { return strings.ToLower(strings.TrimSpace(raw)) } +// mcpRemoteSuffix matches the " (via mcp-remote )" tag mcp-remote +// appends to the clientInfo.name of the client it bridges (GH #1786). +var mcpRemoteSuffix = regexp.MustCompile(`\s+\(via mcp-remote(?:\s+[^()]*)?\)$`) + +// AliasCandidate is NormalizeRaw with one trailing mcp-remote bridge tag +// removed, so "claude-ai (via mcp-remote 0.15.2)" classifies as the client +// behind the bridge. Use it only to look up supported aliases: like +// NormalizeRaw it preserves controls, and unknown names keep their exact key. +func AliasCandidate(raw string) string { + normalized := NormalizeRaw(raw) + if stripped := mcpRemoteSuffix.ReplaceAllString(normalized, ""); stripped != "" { + return stripped + } + return normalized +} + // SanitizeDisplay keeps rendered names safe and bounded. func SanitizeDisplay(raw string) string { var b strings.Builder diff --git a/internal/clientidentity/client_identity_test.go b/internal/clientidentity/client_identity_test.go index bf84146bc..61b958c9b 100644 --- a/internal/clientidentity/client_identity_test.go +++ b/internal/clientidentity/client_identity_test.go @@ -22,3 +22,24 @@ func TestFromRawKeepsTransformedAndFormerSuffixLookalikeDistinct(t *testing.T) { require.Equal(t, "~p:"+transformed.PublicID, sentinelLookalike.PublicID) require.NotEqual(t, transformedWithSentinelDisplay.PublicID, sentinelDisplayLookalike.PublicID, "a transformed display beginning with the sentinel must not recreate an escaped ordinary ID") } + +func TestAliasCandidateStripsOneMCPRemoteBridgeSuffix(t *testing.T) { + cases := map[string]string{ + "claude-ai (via mcp-remote 0.15.2)": "claude-ai", + " Claude-AI (via mcp-remote 0.1.29) ": "claude-ai", + "claude-ai (via mcp-remote)": "claude-ai", + "codex-mcp-client": "codex-mcp-client", + "Cursor": "cursor", + "claude-ai (via something-else 1.0)": "claude-ai (via something-else 1.0)", + "claude-ai (via mcp-remote 1) (via mcp-remote 2)": "claude-ai (via mcp-remote 1)", + "(via mcp-remote 0.15.2)": "(via mcp-remote 0.15.2)", + "claude-ai(via mcp-remote 0.15.2)": "claude-ai(via mcp-remote 0.15.2)", + "claude-ai (via mcp-remote 0.15.2) x": "claude-ai (via mcp-remote 0.15.2) x", + } + for raw, want := range cases { + require.Equal(t, want, AliasCandidate(raw), raw) + } + // Controls survive, so an escape-prefixed bridged name cannot pass as a + // supported alias once the suffix is removed. + require.Equal(t, "\x1bclaude-ai", AliasCandidate("\x1bclaude-ai (via mcp-remote 0.15.2)")) +} diff --git a/internal/connect/clients.go b/internal/connect/clients.go index 4456ff15f..728abcf38 100644 --- a/internal/connect/clients.go +++ b/internal/connect/clients.go @@ -70,7 +70,9 @@ var allClients = []ClientDef{ Bridge: true, Icon: "claude-desktop", // "claude-ai" is Anthropic's published clientInfo.name for the Claude - // Desktop app's MCP client. + // Desktop app's MCP client. Through the mcp-remote bridge Connect + // writes, it arrives as "claude-ai (via mcp-remote )"; + // clientidentity.AliasCandidate strips that tag before matching. ClientInfoNames: []string{"claude-ai", "Claude"}, ReloadHint: "Restart Claude Desktop to load MCPProxy", }, @@ -105,13 +107,14 @@ var allClients = []ClientDef{ ReloadHint: "Run \"MCP: List Servers\" → Restart (or reload the window) in VS Code to load MCPProxy", }, { - ID: "codex", - Name: "Codex CLI", - Format: "toml", - ServerKey: "mcp_servers", - Supported: true, - Icon: "codex", - ClientInfoNames: []string{"codex", "codex-cli"}, + ID: "codex", + Name: "Codex CLI", + Format: "toml", + ServerKey: "mcp_servers", + Supported: true, + Icon: "codex", + // Codex CLI's rmcp client sends "codex-mcp-client" (GH #1786). + ClientInfoNames: []string{"codex", "codex-cli", "codex-mcp-client"}, ReloadHint: "Restart Codex CLI to load MCPProxy", }, { diff --git a/internal/httpapi/clients.go b/internal/httpapi/clients.go index eebd4a0a9..ce4e1d41f 100644 --- a/internal/httpapi/clients.go +++ b/internal/httpapi/clients.go @@ -568,7 +568,7 @@ func (s *Server) clientPresence(withSessions bool, detailID string) ([]clientPre } for _, session := range sessions { identity := clientidentity.FromRaw(session.ClientName) - if identity.Key == "" || known[identity.RawNormalized] { + if identity.Key == "" || known[clientidentity.AliasCandidate(session.ClientName)] { continue } id := "other:" + identity.PublicID @@ -599,7 +599,9 @@ func (s *Server) clientPresence(withSessions bool, detailID string) ([]clientPre // omitting configuration paths: MCP clientInfo has no trustworthy path. for name, seenAt := range state.ClientLastSeen { identity := clientidentity.FromStoredKey(name) - if identity.Key == "" || known[identity.RawNormalized] { + // A bridged known client recorded by an earlier release under its full + // name is credited to that client, not listed as other:. + if identity.Key == "" || known[identity.RawNormalized] || known[clientidentity.AliasCandidate(identity.RawNormalized)] { continue } id := "other:" + identity.PublicID @@ -635,8 +637,9 @@ func latestClientSeen(seen map[string]time.Time, aliases []string) *time.Time { return &latest } func clientMatches(name string, aliases []string) bool { + candidate := clientidentity.AliasCandidate(name) for _, alias := range aliases { - if strings.EqualFold(strings.TrimSpace(name), alias) { + if candidate == clientidentity.NormalizeRaw(alias) { return true } } diff --git a/internal/httpapi/clients_presence_test.go b/internal/httpapi/clients_presence_test.go index 8ef80c700..eb37dc0ad 100644 --- a/internal/httpapi/clients_presence_test.go +++ b/internal/httpapi/clients_presence_test.go @@ -516,3 +516,56 @@ func successData(t *testing.T, rec *httptest.ResponseRecorder) map[string]any { require.True(t, envelope.Success) return envelope.Data } + +func TestClientsPresence_CreditsBridgedClaudeDesktopAndCodex(t *testing.T) { + rt, err := proxyRuntime.New(&config.Config{DataDir: t.TempDir(), Listen: "127.0.0.1:0"}, "", zap.NewNop()) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, rt.Close()) }) + + rt.RecordClientSeen("claude-ai (via mcp-remote 0.15.2)") + rt.RecordClientSeen("codex-mcp-client") + state, err := rt.GetOnboardingState() + require.NoError(t, err) + // An other: row recorded by an earlier release under the bridged name. + state.ClientLastSeen["claude-ai (via mcp-remote 0.14.3)"] = time.Now().Add(-time.Hour) + ctrl := &clientPresenceController{state: state, sessions: []*contracts.MCPSession{ + {ID: "desktop", ClientName: "claude-ai (via mcp-remote 0.15.2)", Status: "active", StartTime: time.Now().Add(-time.Minute), LastActivity: time.Now()}, + {ID: "codex", ClientName: "codex-mcp-client", Status: "active", StartTime: time.Now().Add(-time.Minute), LastActivity: time.Now()}, + }} + srv := NewServer(ctrl, zap.NewNop().Sugar(), nil) + req := httptest.NewRequest(http.MethodGet, "/api/v1/clients", nil) + req.Header.Set("X-API-Key", "clients-admin-key") + rec := httptest.NewRecorder() + srv.ServeHTTP(rec, req) + require.Equal(t, http.StatusOK, rec.Code, rec.Body.String()) + + rows := map[string]map[string]any{} + for _, raw := range successData(t, rec)["clients"].([]any) { + row := raw.(map[string]any) + require.NotEqual(t, "other", row["kind"], "bridged and Codex sessions must not become other: rows: %v", row["id"]) + rows[row["id"].(string)] = row + } + for _, id := range []string{"claude-desktop", "codex"} { + require.Contains(t, rows, id) + require.NotNil(t, rows[id]["last_seen"], id) + require.Equal(t, float64(1), rows[id]["active_sessions"], id) + } +} + +func TestClientsPresence_EscapePrefixedBridgedAliasRemainsOtherClient(t *testing.T) { + ctrl := &clientPresenceController{sessions: []*contracts.MCPSession{{ + ID: "escaped", ClientName: "\x1bclaude-ai (via mcp-remote 0.15.2)", Status: "active", StartTime: time.Now().Add(-time.Minute), LastActivity: time.Now(), + }}} + srv := NewServer(ctrl, zap.NewNop().Sugar(), nil) + req := httptest.NewRequest(http.MethodGet, "/api/v1/clients", nil) + req.Header.Set("X-API-Key", "clients-admin-key") + rec := httptest.NewRecorder() + srv.ServeHTTP(rec, req) + require.Equal(t, http.StatusOK, rec.Code, rec.Body.String()) + for _, raw := range successData(t, rec)["clients"].([]any) { + row := raw.(map[string]any) + if row["id"] == "claude-desktop" { + require.Equal(t, float64(0), row["active_sessions"], "escaped name must not credit Claude Desktop") + } + } +} diff --git a/internal/runtime/clients_presence_generation_test.go b/internal/runtime/clients_presence_generation_test.go index 5de79c9b4..1e5ec8f37 100644 --- a/internal/runtime/clients_presence_generation_test.go +++ b/internal/runtime/clients_presence_generation_test.go @@ -55,3 +55,21 @@ func TestRecordClientSeenCapsOtherNamesWithoutEvictingKnownAliases(t *testing.T) require.LessOrEqual(t, len(state.ClientLastSeen), 32) require.Contains(t, state.ClientLastSeen, "cursor") } + +func TestRecordClientSeenCreditsBridgedAndCodexClientNames(t *testing.T) { + mgr, err := storage.NewManager(t.TempDir(), zap.NewNop().Sugar()) + require.NoError(t, err) + t.Cleanup(func() { _ = mgr.Close() }) + r := &Runtime{storageManager: mgr, logger: zap.NewNop()} + r.RecordClientSeen("claude-ai (via mcp-remote 0.15.2)") + r.RecordClientSeen("codex-mcp-client") + r.RecordClientSeen("\x1bclaude-ai (via mcp-remote 0.15.2)") + + state, err := mgr.GetOnboardingState() + require.NoError(t, err) + require.Contains(t, state.ClientLastSeen, "claude-ai") + require.Contains(t, state.ClientLastSeen, "codex-mcp-client") + require.NotNil(t, latestSeenForAliases(state.ClientLastSeen, []string{"claude-ai", "Claude"})) + require.NotContains(t, state.ClientLastSeen, "v1:p:claude-ai (via mcp-remote 0.15.2)", "a bridged known client must not keep an other: key") + require.Len(t, state.ClientLastSeen, 3, "the escape-prefixed name stays a distinct unknown client") +} diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index 3dc1a7983..d67e06f73 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -4567,8 +4567,8 @@ func sanitizeClientName(raw string) string { if identity.Key == "" { return "" } - if isKnownClientAlias(identity.RawNormalized) { - return identity.RawNormalized + if alias := clientidentity.AliasCandidate(raw); isKnownClientAlias(alias) { + return alias } return identity.Key } diff --git a/internal/runtime/usage_aggregate.go b/internal/runtime/usage_aggregate.go index beb4986a7..5cfc22bd6 100644 --- a/internal/runtime/usage_aggregate.go +++ b/internal/runtime/usage_aggregate.go @@ -1,6 +1,7 @@ package runtime import ( + "github.com/smart-mcp-proxy/mcpproxy-go/internal/clientidentity" "math" "sort" "strings" @@ -281,6 +282,9 @@ func (a *UsageAggregate) applyClientCalls(rec *storage.ActivityRecord) { if client == "" { return } + if alias := clientidentity.AliasCandidate(raw); alias != client && knownClientAliases()[alias] { + client = alias + } if a.ClientCalls == nil { a.ClientCalls = make(map[string]map[int64]int64) } diff --git a/internal/runtime/usage_aggregate_test.go b/internal/runtime/usage_aggregate_test.go index 4bf6da217..cba20a7c7 100644 --- a/internal/runtime/usage_aggregate_test.go +++ b/internal/runtime/usage_aggregate_test.go @@ -554,3 +554,19 @@ func TestUsageAggregate_ClientCallsRetentionPreservesSupportedClients(t *testing require.Equal(t, 1, agg.ClientCallsSince([]string{"cursor"}, base.Add(-24*time.Hour))) require.LessOrEqual(t, len(agg.ClientCalls), 32) } + +func TestUsageAggregate_ClientCallsCreditBridgedKnownClient(t *testing.T) { + base := time.Date(2026, 10, 29, 12, 0, 0, 0, time.UTC) + agg := newUsageAggregate() + for _, client := range []string{"claude-ai (via mcp-remote 0.15.2)", "claude-ai (via mcp-remote 0.15.1)", "codex-mcp-client", "zed (via mcp-remote 0.15.2)"} { + agg.Apply(&storage.ActivityRecord{ + Type: storage.ActivityTypeToolCall, ServerName: "github", ToolName: "search", + Status: storage.ActivityStatusSuccess, Timestamp: base, + Metadata: map[string]interface{}{"client_name": client}, + }) + } + since := base.Add(-24 * time.Hour) + require.Equal(t, 2, agg.ClientCallsSince([]string{"claude-ai", "Claude"}, since)) + require.Equal(t, 1, agg.ClientCallsSince([]string{"codex", "codex-cli", "codex-mcp-client"}, since)) + require.Equal(t, 1, agg.ClientCallsSince([]string{"zed (via mcp-remote 0.15.2)"}, since), "an unknown bridged client keeps its exact key") +} From 990548d9327d2750ad31d8ec6f20ed40396156f5 Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Thu, 29 Oct 2026 11:14:57 +0200 Subject: [PATCH 2/3] fix(clients): strict mcp-remote tag grammar, no hidden legacy rows, telemetry parity Review round 1 (opencode Sol 6.1 + Claude adversarial): - The bridge tag now needs single-space separators and a printable, parenthesis-free version, so newline/control-bearing tags no longer strip to a supported alias. - Stop hiding pre-upgrade bridged other: rows: they were hidden without being credited, silently dropping last_seen evidence. - Telemetry activation's client-name sanitizer reports a bridged client as the client behind the bridge, matching presence and usage. Co-Authored-By: Claude Opus 5.5 --- internal/clientidentity/client_identity.go | 10 ++++++---- .../clientidentity/client_identity_test.go | 11 +++++++++++ internal/httpapi/clients.go | 4 +--- internal/httpapi/clients_presence_test.go | 2 -- internal/telemetry/activation.go | 5 ++++- internal/telemetry/activation_test.go | 19 +++++++++++-------- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/internal/clientidentity/client_identity.go b/internal/clientidentity/client_identity.go index 745cefc59..99bec94ed 100644 --- a/internal/clientidentity/client_identity.go +++ b/internal/clientidentity/client_identity.go @@ -129,8 +129,10 @@ func NormalizeRaw(raw string) string { } // mcpRemoteSuffix matches the " (via mcp-remote )" tag mcp-remote -// appends to the clientInfo.name of the client it bridges (GH #1786). -var mcpRemoteSuffix = regexp.MustCompile(`\s+\(via mcp-remote(?:\s+[^()]*)?\)$`) +// appends to the clientInfo.name of the client it bridges (GH #1786). The +// separators are single spaces and the version is printable ASCII without +// parentheses, so a tag carrying a control character never matches. +var mcpRemoteSuffix = regexp.MustCompile(`^(.*[^ ]) \(via mcp-remote(?: [!-'*-~]+)?\)$`) // AliasCandidate is NormalizeRaw with one trailing mcp-remote bridge tag // removed, so "claude-ai (via mcp-remote 0.15.2)" classifies as the client @@ -138,8 +140,8 @@ var mcpRemoteSuffix = regexp.MustCompile(`\s+\(via mcp-remote(?:\s+[^()]*)?\)$`) // NormalizeRaw it preserves controls, and unknown names keep their exact key. func AliasCandidate(raw string) string { normalized := NormalizeRaw(raw) - if stripped := mcpRemoteSuffix.ReplaceAllString(normalized, ""); stripped != "" { - return stripped + if m := mcpRemoteSuffix.FindStringSubmatch(normalized); m != nil { + return m[1] } return normalized } diff --git a/internal/clientidentity/client_identity_test.go b/internal/clientidentity/client_identity_test.go index 61b958c9b..1da8b9730 100644 --- a/internal/clientidentity/client_identity_test.go +++ b/internal/clientidentity/client_identity_test.go @@ -42,4 +42,15 @@ func TestAliasCandidateStripsOneMCPRemoteBridgeSuffix(t *testing.T) { // Controls survive, so an escape-prefixed bridged name cannot pass as a // supported alias once the suffix is removed. require.Equal(t, "\x1bclaude-ai", AliasCandidate("\x1bclaude-ai (via mcp-remote 0.15.2)")) + for _, raw := range []string{ + "claude-ai\n(via mcp-remote 0.15.2)", + "claude-ai\t(via mcp-remote 0.15.2)", + "claude-ai (via mcp-remote 0.15.2)", + "claude-ai (via mcp-remote \x00)", + "claude-ai (via mcp-remote 0.15\x1b2)", + "claude-ai (via mcp-remote 0.15.2\n)", + "claude-ai (via mcp-remote 0.15.2)", + } { + require.Equal(t, NormalizeRaw(raw), AliasCandidate(raw), "%q must not strip to a supported alias", raw) + } } diff --git a/internal/httpapi/clients.go b/internal/httpapi/clients.go index ce4e1d41f..d1c42566c 100644 --- a/internal/httpapi/clients.go +++ b/internal/httpapi/clients.go @@ -599,9 +599,7 @@ func (s *Server) clientPresence(withSessions bool, detailID string) ([]clientPre // omitting configuration paths: MCP clientInfo has no trustworthy path. for name, seenAt := range state.ClientLastSeen { identity := clientidentity.FromStoredKey(name) - // A bridged known client recorded by an earlier release under its full - // name is credited to that client, not listed as other:. - if identity.Key == "" || known[identity.RawNormalized] || known[clientidentity.AliasCandidate(identity.RawNormalized)] { + if identity.Key == "" || known[identity.RawNormalized] { continue } id := "other:" + identity.PublicID diff --git a/internal/httpapi/clients_presence_test.go b/internal/httpapi/clients_presence_test.go index eb37dc0ad..c5f54bb89 100644 --- a/internal/httpapi/clients_presence_test.go +++ b/internal/httpapi/clients_presence_test.go @@ -526,8 +526,6 @@ func TestClientsPresence_CreditsBridgedClaudeDesktopAndCodex(t *testing.T) { rt.RecordClientSeen("codex-mcp-client") state, err := rt.GetOnboardingState() require.NoError(t, err) - // An other: row recorded by an earlier release under the bridged name. - state.ClientLastSeen["claude-ai (via mcp-remote 0.14.3)"] = time.Now().Add(-time.Hour) ctrl := &clientPresenceController{state: state, sessions: []*contracts.MCPSession{ {ID: "desktop", ClientName: "claude-ai (via mcp-remote 0.15.2)", Status: "active", StartTime: time.Now().Add(-time.Minute), LastActivity: time.Now()}, {ID: "codex", ClientName: "codex-mcp-client", Status: "active", StartTime: time.Now().Add(-time.Minute), LastActivity: time.Now()}, diff --git a/internal/telemetry/activation.go b/internal/telemetry/activation.go index d2acdb965..77789a4e0 100644 --- a/internal/telemetry/activation.go +++ b/internal/telemetry/activation.go @@ -9,6 +9,8 @@ import ( "time" "go.etcd.io/bbolt" + + "github.com/smart-mcp-proxy/mcpproxy-go/internal/clientidentity" ) // ActivationBucketName is the BBolt bucket that stores retention activation @@ -452,7 +454,8 @@ var clientNameRegex = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`) // // Valid names are lowercased and returned unchanged. func sanitizeClientName(raw string) string { - trimmed := strings.TrimSpace(raw) + // A client behind the mcp-remote bridge reports as the client it bridges. + trimmed := strings.TrimSpace(clientidentity.AliasCandidate(raw)) if trimmed == "" { return "unknown" } diff --git a/internal/telemetry/activation_test.go b/internal/telemetry/activation_test.go index 8902c42d3..6f722cee1 100644 --- a/internal/telemetry/activation_test.go +++ b/internal/telemetry/activation_test.go @@ -258,14 +258,17 @@ func TestSanitizeClientName(t *testing.T) { }{ {"claude-code", "claude-code"}, {"cursor", "cursor"}, - {"Windsurf", "windsurf"}, // lowercased - {"", "unknown"}, // empty - {"/Users/alice/bin", "unknown"}, // path - {"C:\\Users\\bob", "unknown"}, // windows path - {"../relative", "unknown"}, // relative traversal - {"user@host", "unknown"}, // email-like - {"a.b.c_d-2", "a.b.c_d-2"}, // allowed chars - {"toolong" + longString(64), "unknown"}, // too long (>64) + {"Windsurf", "windsurf"}, // lowercased + {"", "unknown"}, // empty + {"/Users/alice/bin", "unknown"}, // path + {"C:\\Users\\bob", "unknown"}, // windows path + {"../relative", "unknown"}, // relative traversal + {"user@host", "unknown"}, // email-like + {"a.b.c_d-2", "a.b.c_d-2"}, // allowed chars + {"toolong" + longString(64), "unknown"}, // too long (>64) + {"claude-ai (via mcp-remote 0.15.2)", "claude-ai"}, // bridged client (GH #1786) + {"user@host (via mcp-remote 0.15.2)", "unknown"}, // bridge tag does not launder a bad name + {"claude-ai\n(via mcp-remote 0.15.2)", "unknown"}, // control separator is not a bridge tag } for _, tc := range cases { got := sanitizeClientName(tc.in) From cdd363dcf890eedb3e4381e25906575cd54036b2 Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Thu, 29 Oct 2026 11:16:41 +0200 Subject: [PATCH 3/3] fix(telemetry): keep a control before the mcp-remote tag in the client name Review round 2: re-trimming AliasCandidate's result dropped a tab/newline before the bridge tag, so telemetry credited a name runtime and httpapi reject. Co-Authored-By: Claude Opus 5.5 --- internal/telemetry/activation.go | 4 +++- internal/telemetry/activation_test.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/telemetry/activation.go b/internal/telemetry/activation.go index 77789a4e0..52ad0b7ba 100644 --- a/internal/telemetry/activation.go +++ b/internal/telemetry/activation.go @@ -455,7 +455,9 @@ var clientNameRegex = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`) // Valid names are lowercased and returned unchanged. func sanitizeClientName(raw string) string { // A client behind the mcp-remote bridge reports as the client it bridges. - trimmed := strings.TrimSpace(clientidentity.AliasCandidate(raw)) + // AliasCandidate already trims the raw name; trimming its result again + // would drop a control that sat before the bridge tag. + trimmed := clientidentity.AliasCandidate(raw) if trimmed == "" { return "unknown" } diff --git a/internal/telemetry/activation_test.go b/internal/telemetry/activation_test.go index 6f722cee1..e90929349 100644 --- a/internal/telemetry/activation_test.go +++ b/internal/telemetry/activation_test.go @@ -269,6 +269,9 @@ func TestSanitizeClientName(t *testing.T) { {"claude-ai (via mcp-remote 0.15.2)", "claude-ai"}, // bridged client (GH #1786) {"user@host (via mcp-remote 0.15.2)", "unknown"}, // bridge tag does not launder a bad name {"claude-ai\n(via mcp-remote 0.15.2)", "unknown"}, // control separator is not a bridge tag + {"claude-ai\t (via mcp-remote 0.15.2)", "unknown"}, // control before the tag survives stripping + {"claude-ai\n (via mcp-remote 0.15.2)", "unknown"}, + {"claude-ai\r (via mcp-remote 0.15.2)", "unknown"}, } for _, tc := range cases { got := sanitizeClientName(tc.in)