Skip to content

Commit f8c38c6

Browse files
committed
return the proxy mode in the server type for stdio
when we run a server via stdio, we wrap it into a proxy, exposing via sse or streamable-http. So show this as the server type, instead of the stdio type Closes: #1717
1 parent 8f1a7e9 commit f8c38c6

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

cmd/thv/app/list.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/stacklok/toolhive/pkg/core"
1212
"github.com/stacklok/toolhive/pkg/logger"
13+
"github.com/stacklok/toolhive/pkg/transport/types"
1314
"github.com/stacklok/toolhive/pkg/workloads"
1415
)
1516

@@ -108,10 +109,14 @@ func printMCPServersOutput(workloadList []core.Workload) error {
108109
mcpServers := make(map[string]map[string]string)
109110

110111
for _, c := range workloadList {
112+
// Determine the effective transport type to show to users
113+
// This is the transport they actually connect to, not the underlying MCP server transport
114+
effectiveTransport := getEffectiveTransportType(c)
115+
111116
// Add the MCP server to the map
112117
mcpServers[c.Name] = map[string]string{
113118
"url": c.URL,
114-
"type": c.TransportType.String(),
119+
"type": effectiveTransport,
115120
}
116121
}
117122

@@ -157,3 +162,17 @@ func printTextOutput(workloadList []core.Workload) {
157162
logger.Errorf("Warning: Failed to flush tabwriter: %v", err)
158163
}
159164
}
165+
166+
// getEffectiveTransportType determines the effective transport type that clients should use
167+
// This handles the case where stdio MCP servers are proxied through SSE or streamable-http
168+
func getEffectiveTransportType(workload core.Workload) string {
169+
// If the underlying transport is stdio and we have a proxy mode set,
170+
// return the proxy mode as that's what clients actually connect to
171+
if workload.TransportType == types.TransportTypeStdio && workload.ProxyMode != "" {
172+
return workload.ProxyMode
173+
}
174+
175+
// For all other cases (direct sse, streamable-http, or when no proxy mode is set),
176+
// return the transport type directly
177+
return workload.TransportType.String()
178+
}

cmd/thv/app/list_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package app
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"github.com/stacklok/toolhive/pkg/core"
9+
"github.com/stacklok/toolhive/pkg/transport/types"
10+
)
11+
12+
func TestGetEffectiveTransportType(t *testing.T) {
13+
t.Parallel()
14+
15+
tests := []struct {
16+
name string
17+
workload core.Workload
18+
expectedTransport string
19+
}{
20+
{
21+
name: "stdio transport with sse proxy mode should return sse",
22+
workload: core.Workload{
23+
TransportType: types.TransportTypeStdio,
24+
ProxyMode: "sse",
25+
},
26+
expectedTransport: "sse",
27+
},
28+
{
29+
name: "stdio transport with streamable-http proxy mode should return streamable-http",
30+
workload: core.Workload{
31+
TransportType: types.TransportTypeStdio,
32+
ProxyMode: "streamable-http",
33+
},
34+
expectedTransport: "streamable-http",
35+
},
36+
{
37+
name: "stdio transport with empty proxy mode should return stdio",
38+
workload: core.Workload{
39+
TransportType: types.TransportTypeStdio,
40+
ProxyMode: "",
41+
},
42+
expectedTransport: "stdio",
43+
},
44+
{
45+
name: "sse transport should return sse regardless of proxy mode",
46+
workload: core.Workload{
47+
TransportType: types.TransportTypeSSE,
48+
ProxyMode: "streamable-http", // This shouldn't matter for non-stdio
49+
},
50+
expectedTransport: "sse",
51+
},
52+
{
53+
name: "streamable-http transport should return streamable-http",
54+
workload: core.Workload{
55+
TransportType: types.TransportTypeStreamableHTTP,
56+
ProxyMode: "",
57+
},
58+
expectedTransport: "streamable-http",
59+
},
60+
}
61+
62+
for _, tt := range tests {
63+
t.Run(tt.name, func(t *testing.T) {
64+
t.Parallel()
65+
66+
result := getEffectiveTransportType(tt.workload)
67+
assert.Equal(t, tt.expectedTransport, result, "Effective transport type should match expected")
68+
})
69+
}
70+
}

0 commit comments

Comments
 (0)