@@ -10,8 +10,7 @@ import (
1010 "text/tabwriter"
1111 "time"
1212
13- "github.com/mark3labs/mcp-go/client"
14- "github.com/mark3labs/mcp-go/mcp"
13+ "github.com/modelcontextprotocol/go-sdk/mcp"
1514 "github.com/spf13/cobra"
1615
1716 "github.com/stacklok/toolhive/pkg/logger"
@@ -119,23 +118,23 @@ func mcpListCmdFunc(cmd *cobra.Command, _ []string) error {
119118 data := make (map [string ]interface {})
120119
121120 // List tools
122- if tools , err := mcpClient .ListTools (ctx , mcp.ListToolsRequest {}); err != nil {
121+ if tools , err := mcpClient .ListTools (ctx , & mcp.ListToolsParams {}); err != nil {
123122 logger .Warnf ("Failed to list tools: %v" , err )
124123 data ["tools" ] = []mcp.Tool {}
125124 } else {
126125 data ["tools" ] = tools .Tools
127126 }
128127
129128 // List resources
130- if resources , err := mcpClient .ListResources (ctx , mcp.ListResourcesRequest {}); err != nil {
129+ if resources , err := mcpClient .ListResources (ctx , & mcp.ListResourcesParams {}); err != nil {
131130 logger .Warnf ("Failed to list resources: %v" , err )
132131 data ["resources" ] = []mcp.Resource {}
133132 } else {
134133 data ["resources" ] = resources .Resources
135134 }
136135
137136 // List prompts
138- if prompts , err := mcpClient .ListPrompts (ctx , mcp.ListPromptsRequest {}); err != nil {
137+ if prompts , err := mcpClient .ListPrompts (ctx , & mcp.ListPromptsParams {}); err != nil {
139138 logger .Warnf ("Failed to list prompts: %v" , err )
140139 data ["prompts" ] = []mcp.Prompt {}
141140 } else {
@@ -166,7 +165,7 @@ func mcpListToolsCmdFunc(cmd *cobra.Command, _ []string) error {
166165 return err
167166 }
168167
169- result , err := mcpClient .ListTools (ctx , mcp.ListToolsRequest {})
168+ result , err := mcpClient .ListTools (ctx , & mcp.ListToolsParams {})
170169 if err != nil {
171170 return fmt .Errorf ("failed to list tools: %w" , err )
172171 }
@@ -195,7 +194,7 @@ func mcpListResourcesCmdFunc(cmd *cobra.Command, _ []string) error {
195194 return err
196195 }
197196
198- result , err := mcpClient .ListResources (ctx , mcp.ListResourcesRequest {})
197+ result , err := mcpClient .ListResources (ctx , & mcp.ListResourcesParams {})
199198 if err != nil {
200199 return fmt .Errorf ("failed to list resources: %w" , err )
201200 }
@@ -224,7 +223,7 @@ func mcpListPromptsCmdFunc(cmd *cobra.Command, _ []string) error {
224223 return err
225224 }
226225
227- result , err := mcpClient .ListPrompts (ctx , mcp.ListPromptsRequest {})
226+ result , err := mcpClient .ListPrompts (ctx , & mcp.ListPromptsParams {})
228227 if err != nil {
229228 return fmt .Errorf ("failed to list prompts: %w" , err )
230229 }
@@ -262,29 +261,45 @@ func resolveServerURL(ctx context.Context, serverInput string) (string, error) {
262261}
263262
264263// 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 ) {
266265 transportType := determineTransportType (serverURL , mcpTransport )
267266
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+
268278 switch transportType {
269279 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 ,
273282 }
274- return mcpClient , nil
275283 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 ,
279287 }
280- return mcpClient , nil
281288 case types .TransportTypeStdio :
282289 return nil , fmt .Errorf ("stdio transport is not supported for MCP client connections" )
283290 case types .TransportTypeInspector :
284291 return nil , fmt .Errorf ("inspector transport is not supported for MCP client connections" )
285292 default :
286293 return nil , fmt .Errorf ("unsupported transport type: %s" , transportType )
287294 }
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
288303}
289304
290305// determineTransportType determines the transport type based on URL path and user preference
@@ -325,29 +340,15 @@ func determineTransportType(serverURL, transportFlag string) types.TransportType
325340}
326341
327342// 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" )
332347 }
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" )
349351 }
350-
351352 return nil
352353}
353354
@@ -438,7 +439,7 @@ func outputMCPPrompts(w *tabwriter.Writer, data map[string]interface{}) bool {
438439}
439440
440441// formatPromptArguments formats the prompt arguments for display
441- func formatPromptArguments (arguments []mcp.PromptArgument ) string {
442+ func formatPromptArguments (arguments []* mcp.PromptArgument ) string {
442443 argCount := len (arguments )
443444 if argCount == 0 {
444445 return "0"
0 commit comments