Skip to content

Commit 8c7962b

Browse files
committed
fix(diagnostics): classify auto-detected stdio servers (resolved transport hint)
Codex review round on PR #606: the supervisor built the classifier transport hint from raw Config.Protocol, so auto-detected stdio servers (Protocol=='' + Command!='') missed the stdio-gated rules and stayed UNKNOWN. Use transport.DetermineTransportType(config) at both hint sites so the resolved transport drives classification + add a DetermineTransportType regression test. Related #599
1 parent d963178 commit 8c7962b

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

internal/runtime/supervisor/supervisor.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/smart-mcp-proxy/mcpproxy-go/internal/diagnostics"
1616
"github.com/smart-mcp-proxy/mcpproxy-go/internal/runtime/configsvc"
1717
"github.com/smart-mcp-proxy/mcpproxy-go/internal/runtime/stateview"
18+
transportpkg "github.com/smart-mcp-proxy/mcpproxy-go/internal/transport"
1819
"github.com/smart-mcp-proxy/mcpproxy-go/internal/upstream/types"
1920
)
2021

@@ -696,9 +697,12 @@ func (s *Supervisor) updateStateView(name string, state *ServerState) {
696697
status.LastError = errorStr
697698

698699
// Spec 044: classify raw error into stable diagnostic code.
700+
// Use the RESOLVED transport, not the raw Config.Protocol: an
701+
// auto-detected stdio server has Protocol=="" + Command!="" and
702+
// would otherwise miss the stdio-gated classifier rules (#599).
699703
transport := ""
700704
if state.Config != nil {
701-
transport = string(state.Config.Protocol)
705+
transport = transportpkg.DetermineTransportType(state.Config)
702706
}
703707
classifyAndAttach(status, state.ConnectionInfo.LastError, transport)
704708
// Spec 044 Phase H: notify telemetry counter store.
@@ -969,9 +973,12 @@ func (s *Supervisor) updateSnapshotFromEvent(event Event) {
969973
status.LastError = errorStr
970974

971975
// Spec 044: classify raw error into stable diagnostic code.
976+
// Resolved transport (not raw Config.Protocol) so auto-detected
977+
// stdio servers (Protocol=="" + Command!="") hit the stdio
978+
// classifier rules (#599).
972979
transport := ""
973980
if status.Config != nil {
974-
transport = string(status.Config.Protocol)
981+
transport = transportpkg.DetermineTransportType(status.Config)
975982
}
976983
classifyAndAttach(status, connInfo.LastError, transport)
977984
// Spec 044 Phase H: notify telemetry counter store.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package transport
2+
3+
import (
4+
"testing"
5+
6+
"github.com/smart-mcp-proxy/mcpproxy-go/internal/config"
7+
)
8+
9+
// Locks the behavior the supervisor classifier hint relies on (#599 / PR #606):
10+
// an auto-detected stdio server (empty/auto protocol + a command) must resolve to
11+
// stdio, so the stdio-gated diagnostic rules fire for it — using the raw
12+
// Config.Protocol would leave such servers unclassified.
13+
func TestDetermineTransportType(t *testing.T) {
14+
cases := []struct {
15+
name string
16+
cfg config.ServerConfig
17+
want string
18+
}{
19+
{"explicit stdio", config.ServerConfig{Protocol: "stdio"}, TransportStdio},
20+
{"auto-detected stdio (empty protocol + command)", config.ServerConfig{Command: "npx"}, TransportStdio},
21+
{"auto protocol + command", config.ServerConfig{Protocol: "auto", Command: "docker"}, TransportStdio},
22+
{"empty protocol + url", config.ServerConfig{URL: "https://example.com/mcp"}, TransportStreamableHTTP},
23+
{"explicit http", config.ServerConfig{Protocol: "http", URL: "https://example.com/mcp"}, "http"},
24+
}
25+
for _, tc := range cases {
26+
t.Run(tc.name, func(t *testing.T) {
27+
cfg := tc.cfg
28+
if got := DetermineTransportType(&cfg); got != tc.want {
29+
t.Errorf("DetermineTransportType(%+v) = %q, want %q", tc.cfg, got, tc.want)
30+
}
31+
})
32+
}
33+
}

0 commit comments

Comments
 (0)