client

package
v0.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package client is a drop-in compatibility shim for github.com/mark3labs/mcp-go/client, reimplemented on top of the official github.com/modelcontextprotocol/go-sdk.

It presents mcp-go's flat client API (NewStreamableHttpClient, Start, Initialize, ListTools, CallTool, ...) while delegating the actual protocol to a go-sdk Client and ClientSession underneath. Data types are exchanged as the mcp-go-shaped types from mcpcompat/mcp; conversion to and from the go-sdk's own types happens at this boundary via JSON round-trips, which is robust because both encode the identical MCP wire format.

Stability: Alpha.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an MCP client backed by the official go-sdk. It mirrors the subset of mcp-go's client.Client that ToolHive uses.

func NewSSEMCPClient

func NewSSEMCPClient(baseURL string, options ...transport.ClientOption) (*Client, error)

NewSSEMCPClient creates an SSE MCP client for baseURL. The returned client is not yet connected; call Start then Initialize.

func NewStreamableHttpClient

func NewStreamableHttpClient(baseURL string, options ...transport.StreamableHTTPCOption) (*Client, error)

NewStreamableHttpClient creates a Streamable HTTP MCP client for baseURL. Like mcp-go, the returned client is not yet connected; call Start then Initialize.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

CallTool invokes a tool.

func (*Client) Close

func (c *Client) Close() error

Close terminates the session.

func (*Client) GetPrompt

func (c *Client) GetPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error)

GetPrompt gets a prompt, rendered with the provided arguments.

func (*Client) GetSessionId

func (c *Client) GetSessionId() string

GetSessionId returns the current MCP session ID, if any.

func (*Client) GetTransport

func (c *Client) GetTransport() transport.Interface

GetTransport returns the transport handle. For a Streamable HTTP client the dynamic type is *transport.StreamableHTTP (as ToolHive expects); otherwise it is nil.

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, request mcp.InitializeRequest) (*mcp.InitializeResult, error)

Initialize connects the underlying go-sdk client and performs the MCP initialize handshake using the supplied client info and capabilities.

func (*Client) IsInitialized

func (c *Client) IsInitialized() bool

IsInitialized reports whether the client has completed initialization.

func (*Client) ListPrompts

func (c *Client) ListPrompts(ctx context.Context, request mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)

ListPrompts lists the server's prompts.

func (*Client) ListResourceTemplates

func (c *Client) ListResourceTemplates(
	ctx context.Context, request mcp.ListResourceTemplatesRequest,
) (*mcp.ListResourceTemplatesResult, error)

ListResourceTemplates lists the server's resource templates.

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context, request mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)

ListResources lists the server's resources.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)

ListTools lists the server's tools.

func (*Client) OnConnectionLost

func (c *Client) OnConnectionLost(handler func(error))

OnConnectionLost registers a handler invoked when the connection to the server is lost. It mirrors mcp-go's client.Client.OnConnectionLost, which is used to handle transport-level disconnections (e.g. an HTTP/2 idle timeout) that should not be treated as fatal errors.

The go-sdk signals a dropped connection by having ClientSession.Wait return. The handler is invoked once, with the error Wait reports (nil on a clean close). If registered before Initialize, the watch starts once the session connects; if registered after, it starts immediately.

func (*Client) OnNotification

func (c *Client) OnNotification(handler func(notification mcp.JSONRPCNotification))

OnNotification registers a handler invoked for server-initiated notifications. Handlers must be registered before Initialize so they can be wired into the underlying go-sdk client. The go-sdk exposes typed notification handlers rather than a single catch-all, so this shim synthesizes JSONRPCNotification values for the list-changed, progress and logging notifications.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping verifies the server is responsive.

func (*Client) ReadResource

func (c *Client) ReadResource(ctx context.Context, request mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)

ReadResource reads a resource by URI.

func (*Client) Start

func (*Client) Start(_ context.Context) error

Start prepares the client. The go-sdk performs connection and initialization together in a single Connect call, which this shim issues from Initialize; Start is therefore a no-op retained for API compatibility.

Directories

Path Synopsis
Package transport is a drop-in compatibility shim for github.com/mark3labs/mcp-go/client/transport.
Package transport is a drop-in compatibility shim for github.com/mark3labs/mcp-go/client/transport.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL