@@ -10,8 +10,7 @@ import (
10
10
"text/tabwriter"
11
11
"time"
12
12
13
- "github.com/mark3labs/mcp-go/client"
14
- "github.com/mark3labs/mcp-go/mcp"
13
+ "github.com/modelcontextprotocol/go-sdk/mcp"
15
14
"github.com/spf13/cobra"
16
15
17
16
"github.com/stacklok/toolhive/pkg/logger"
@@ -119,23 +118,23 @@ func mcpListCmdFunc(cmd *cobra.Command, _ []string) error {
119
118
data := make (map [string ]interface {})
120
119
121
120
// List tools
122
- if tools , err := mcpClient .ListTools (ctx , mcp.ListToolsRequest {}); err != nil {
121
+ if tools , err := mcpClient .ListTools (ctx , & mcp.ListToolsParams {}); err != nil {
123
122
logger .Warnf ("Failed to list tools: %v" , err )
124
123
data ["tools" ] = []mcp.Tool {}
125
124
} else {
126
125
data ["tools" ] = tools .Tools
127
126
}
128
127
129
128
// List resources
130
- if resources , err := mcpClient .ListResources (ctx , mcp.ListResourcesRequest {}); err != nil {
129
+ if resources , err := mcpClient .ListResources (ctx , & mcp.ListResourcesParams {}); err != nil {
131
130
logger .Warnf ("Failed to list resources: %v" , err )
132
131
data ["resources" ] = []mcp.Resource {}
133
132
} else {
134
133
data ["resources" ] = resources .Resources
135
134
}
136
135
137
136
// List prompts
138
- if prompts , err := mcpClient .ListPrompts (ctx , mcp.ListPromptsRequest {}); err != nil {
137
+ if prompts , err := mcpClient .ListPrompts (ctx , & mcp.ListPromptsParams {}); err != nil {
139
138
logger .Warnf ("Failed to list prompts: %v" , err )
140
139
data ["prompts" ] = []mcp.Prompt {}
141
140
} else {
@@ -166,7 +165,7 @@ func mcpListToolsCmdFunc(cmd *cobra.Command, _ []string) error {
166
165
return err
167
166
}
168
167
169
- result , err := mcpClient .ListTools (ctx , mcp.ListToolsRequest {})
168
+ result , err := mcpClient .ListTools (ctx , & mcp.ListToolsParams {})
170
169
if err != nil {
171
170
return fmt .Errorf ("failed to list tools: %w" , err )
172
171
}
@@ -195,7 +194,7 @@ func mcpListResourcesCmdFunc(cmd *cobra.Command, _ []string) error {
195
194
return err
196
195
}
197
196
198
- result , err := mcpClient .ListResources (ctx , mcp.ListResourcesRequest {})
197
+ result , err := mcpClient .ListResources (ctx , & mcp.ListResourcesParams {})
199
198
if err != nil {
200
199
return fmt .Errorf ("failed to list resources: %w" , err )
201
200
}
@@ -224,7 +223,7 @@ func mcpListPromptsCmdFunc(cmd *cobra.Command, _ []string) error {
224
223
return err
225
224
}
226
225
227
- result , err := mcpClient .ListPrompts (ctx , mcp.ListPromptsRequest {})
226
+ result , err := mcpClient .ListPrompts (ctx , & mcp.ListPromptsParams {})
228
227
if err != nil {
229
228
return fmt .Errorf ("failed to list prompts: %w" , err )
230
229
}
@@ -262,29 +261,45 @@ func resolveServerURL(ctx context.Context, serverInput string) (string, error) {
262
261
}
263
262
264
263
// createMCPClient creates an MCP client based on the server URL and transport type
265
- func createMCPClient (serverURL string ) (* client. Client , error ) {
264
+ func createMCPClient (serverURL string ) (* mcp. ClientSession , error ) {
266
265
transportType := determineTransportType (serverURL , mcpTransport )
267
266
267
+ // Create the MCP client
268
+ client := mcp .NewClient (
269
+ & mcp.Implementation {
270
+ Name : "thv-mcp-cli" ,
271
+ Version : versions .Version ,
272
+ },
273
+ & mcp.ClientOptions {},
274
+ )
275
+
276
+ var transport mcp.Transport
277
+
268
278
switch transportType {
269
279
case types .TransportTypeSSE :
270
- mcpClient , err := client .NewSSEMCPClient (serverURL )
271
- if err != nil {
272
- return nil , fmt .Errorf ("failed to create SSE MCP client: %w" , err )
280
+ transport = & mcp.SSEClientTransport {
281
+ Endpoint : serverURL ,
273
282
}
274
- return mcpClient , nil
275
283
case types .TransportTypeStreamableHTTP :
276
- mcpClient , err := client . NewStreamableHttpClient ( serverURL )
277
- if err != nil {
278
- return nil , fmt . Errorf ( "failed to create Streamable HTTP MCP client: %w" , err )
284
+ transport = & mcp. StreamableClientTransport {
285
+ Endpoint : serverURL ,
286
+ MaxRetries : 5 ,
279
287
}
280
- return mcpClient , nil
281
288
case types .TransportTypeStdio :
282
289
return nil , fmt .Errorf ("stdio transport is not supported for MCP client connections" )
283
290
case types .TransportTypeInspector :
284
291
return nil , fmt .Errorf ("inspector transport is not supported for MCP client connections" )
285
292
default :
286
293
return nil , fmt .Errorf ("unsupported transport type: %s" , transportType )
287
294
}
295
+
296
+ // Connect using the transport
297
+ session , err := client .Connect (context .Background (), transport , nil )
298
+ if err != nil {
299
+ return nil , fmt .Errorf ("failed to connect to MCP server: %w" , err )
300
+ }
301
+
302
+ return session , nil
288
303
}
289
304
290
305
// determineTransportType determines the transport type based on URL path and user preference
@@ -325,29 +340,15 @@ func determineTransportType(serverURL, transportFlag string) types.TransportType
325
340
}
326
341
327
342
// initializeMCPClient initializes the MCP client connection
328
- func initializeMCPClient (ctx context.Context , mcpClient * client. Client ) error {
329
- // Start the transport
330
- if err := mcpClient . Start ( ctx ); err ! = nil {
331
- return fmt .Errorf ("failed to start MCP transport: %w" , err )
343
+ func initializeMCPClient (ctx context.Context , mcpClient * mcp. ClientSession ) error {
344
+ // Initialization happens during Connect, just verify we're connected
345
+ if mcpClient = = nil {
346
+ return fmt .Errorf ("client session not connected" )
332
347
}
333
-
334
- // Initialize the connection
335
- initRequest := mcp.InitializeRequest {}
336
- initRequest .Params .ProtocolVersion = mcp .LATEST_PROTOCOL_VERSION
337
- initRequest .Params .Capabilities = mcp.ClientCapabilities {
338
- // Basic client capabilities for listing
339
- }
340
- versionInfo := versions .GetVersionInfo ()
341
- initRequest .Params .ClientInfo = mcp.Implementation {
342
- Name : "toolhive-cli" ,
343
- Version : versionInfo .Version ,
344
- }
345
-
346
- _ , err := mcpClient .Initialize (ctx , initRequest )
347
- if err != nil {
348
- return fmt .Errorf ("failed to initialize MCP client: %w" , err )
348
+ result := mcpClient .InitializeResult ()
349
+ if result == nil {
350
+ return fmt .Errorf ("client session not initialized" )
349
351
}
350
-
351
352
return nil
352
353
}
353
354
@@ -438,7 +439,7 @@ func outputMCPPrompts(w *tabwriter.Writer, data map[string]interface{}) bool {
438
439
}
439
440
440
441
// formatPromptArguments formats the prompt arguments for display
441
- func formatPromptArguments (arguments []mcp.PromptArgument ) string {
442
+ func formatPromptArguments (arguments []* mcp.PromptArgument ) string {
442
443
argCount := len (arguments )
443
444
if argCount == 0 {
444
445
return "0"
0 commit comments