@@ -13,6 +13,7 @@ import (
13
13
"github.com/stacklok/toolhive/pkg/labels"
14
14
"github.com/stacklok/toolhive/pkg/lifecycle"
15
15
"github.com/stacklok/toolhive/pkg/logger"
16
+ "github.com/stacklok/toolhive/pkg/transport"
16
17
)
17
18
18
19
var listCmd = & cobra.Command {
28
29
)
29
30
30
31
// Constants for list command
31
- const (
32
- defaultHost = "localhost"
33
- unknownTransport = "unknown"
34
- )
32
+ const unknownTransport = "unknown"
35
33
36
34
// ContainerOutput represents container information for JSON output
37
35
type ContainerOutput struct {
@@ -101,9 +99,9 @@ func printJSONOutput(containers []rt.ContainerInfo) error {
101
99
}
102
100
103
101
// Get transport type from labels
104
- transport := labels .GetTransportType (c .Labels )
105
- if transport == "" {
106
- transport = unknownTransport
102
+ t := labels .GetTransportType (c .Labels )
103
+ if t == "" {
104
+ t = unknownTransport
107
105
}
108
106
109
107
// Get tool type from labels
@@ -118,15 +116,15 @@ func printJSONOutput(containers []rt.ContainerInfo) error {
118
116
// Generate URL for the MCP server
119
117
url := ""
120
118
if port > 0 {
121
- url = client .GenerateMCPServerURL (defaultHost , port , name )
119
+ url = client .GenerateMCPServerURL (transport . LocalhostIPv4 , port , name )
122
120
}
123
121
124
122
output = append (output , ContainerOutput {
125
123
ID : truncatedID ,
126
124
Name : name ,
127
125
Image : c .Image ,
128
126
State : c .State ,
129
- Transport : transport ,
127
+ Transport : t ,
130
128
ToolType : toolType ,
131
129
Port : port ,
132
130
URL : url ,
@@ -174,7 +172,7 @@ func printMCPServersOutput(containers []rt.ContainerInfo) error {
174
172
// Generate URL for the MCP server
175
173
url := ""
176
174
if port > 0 {
177
- url = client .GenerateMCPServerURL (defaultHost , port , name )
175
+ url = client .GenerateMCPServerURL (transport . LocalhostIPv4 , port , name )
178
176
}
179
177
180
178
// Add the MCP server to the map
@@ -217,9 +215,9 @@ func printTextOutput(containers []rt.ContainerInfo) {
217
215
}
218
216
219
217
// Get transport type from labels
220
- transport := labels .GetTransportType (c .Labels )
221
- if transport == "" {
222
- transport = unknownTransport
218
+ t := labels .GetTransportType (c .Labels )
219
+ if t == "" {
220
+ t = unknownTransport
223
221
}
224
222
225
223
// Get port from labels
@@ -231,7 +229,7 @@ func printTextOutput(containers []rt.ContainerInfo) {
231
229
// Generate URL for the MCP server
232
230
url := ""
233
231
if port > 0 {
234
- url = client .GenerateMCPServerURL (defaultHost , port , name )
232
+ url = client .GenerateMCPServerURL (transport . LocalhostIPv4 , port , name )
235
233
}
236
234
237
235
// Print container information
@@ -240,7 +238,7 @@ func printTextOutput(containers []rt.ContainerInfo) {
240
238
name ,
241
239
c .Image ,
242
240
c .State ,
243
- transport ,
241
+ t ,
244
242
port ,
245
243
url ,
246
244
)
0 commit comments