@@ -13,6 +13,7 @@ import (
1313 "github.com/stacklok/toolhive/pkg/labels"
1414 "github.com/stacklok/toolhive/pkg/lifecycle"
1515 "github.com/stacklok/toolhive/pkg/logger"
16+ "github.com/stacklok/toolhive/pkg/transport"
1617)
1718
1819var listCmd = & cobra.Command {
2829)
2930
3031// Constants for list command
31- const (
32- defaultHost = "localhost"
33- unknownTransport = "unknown"
34- )
32+ const unknownTransport = "unknown"
3533
3634// ContainerOutput represents container information for JSON output
3735type ContainerOutput struct {
@@ -101,9 +99,9 @@ func printJSONOutput(containers []rt.ContainerInfo) error {
10199 }
102100
103101 // 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
107105 }
108106
109107 // Get tool type from labels
@@ -118,15 +116,15 @@ func printJSONOutput(containers []rt.ContainerInfo) error {
118116 // Generate URL for the MCP server
119117 url := ""
120118 if port > 0 {
121- url = client .GenerateMCPServerURL (defaultHost , port , name )
119+ url = client .GenerateMCPServerURL (transport . LocalhostIPv4 , port , name )
122120 }
123121
124122 output = append (output , ContainerOutput {
125123 ID : truncatedID ,
126124 Name : name ,
127125 Image : c .Image ,
128126 State : c .State ,
129- Transport : transport ,
127+ Transport : t ,
130128 ToolType : toolType ,
131129 Port : port ,
132130 URL : url ,
@@ -174,7 +172,7 @@ func printMCPServersOutput(containers []rt.ContainerInfo) error {
174172 // Generate URL for the MCP server
175173 url := ""
176174 if port > 0 {
177- url = client .GenerateMCPServerURL (defaultHost , port , name )
175+ url = client .GenerateMCPServerURL (transport . LocalhostIPv4 , port , name )
178176 }
179177
180178 // Add the MCP server to the map
@@ -217,9 +215,9 @@ func printTextOutput(containers []rt.ContainerInfo) {
217215 }
218216
219217 // 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
223221 }
224222
225223 // Get port from labels
@@ -231,7 +229,7 @@ func printTextOutput(containers []rt.ContainerInfo) {
231229 // Generate URL for the MCP server
232230 url := ""
233231 if port > 0 {
234- url = client .GenerateMCPServerURL (defaultHost , port , name )
232+ url = client .GenerateMCPServerURL (transport . LocalhostIPv4 , port , name )
235233 }
236234
237235 // Print container information
@@ -240,7 +238,7 @@ func printTextOutput(containers []rt.ContainerInfo) {
240238 name ,
241239 c .Image ,
242240 c .State ,
243- transport ,
241+ t ,
244242 port ,
245243 url ,
246244 )
0 commit comments