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 ¶
- type Client
- func (c *Client) CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (c *Client) Close() error
- func (c *Client) GetPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
- func (c *Client) GetSessionId() string
- func (c *Client) GetTransport() transport.Interface
- func (c *Client) Initialize(ctx context.Context, request mcp.InitializeRequest) (*mcp.InitializeResult, error)
- func (c *Client) IsInitialized() bool
- func (c *Client) ListPrompts(ctx context.Context, request mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)
- func (c *Client) ListResourceTemplates(ctx context.Context, request mcp.ListResourceTemplatesRequest) (*mcp.ListResourceTemplatesResult, error)
- func (c *Client) ListResources(ctx context.Context, request mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)
- func (c *Client) ListTools(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)
- func (c *Client) OnConnectionLost(handler func(error))
- func (c *Client) OnNotification(handler func(notification mcp.JSONRPCNotification))
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) ReadResource(ctx context.Context, request mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
- func (*Client) Start(_ context.Context) error
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) 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 ¶
GetSessionId returns the current MCP session ID, if any.
func (*Client) GetTransport ¶
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 ¶
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 ¶
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) ReadResource ¶
func (c *Client) ReadResource(ctx context.Context, request mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
ReadResource reads a resource by URI.