Documentation
¶
Overview ¶
Package client provides the MCP client implementation.
Index ¶
- type Client
- func NewClient(clientName string, opts ClientOptions) (*Client, error)
- func NewSSEClient(clientName string, baseURL string, basePath string, opts ClientOptions) (*Client, error)
- func NewStdioClient(clientName string, opts ClientOptions) (*Client, error)
- func NewWebSocketClient(clientName string, baseURL string, basePath string, opts ClientOptions) (*Client, error)
- func (c *Client) CallTool(ctx context.Context, params protocol.CallToolParams, progressToken interface{}) (*protocol.CallToolResult, error)
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) CurrentState() (connected bool, initialized bool, closed bool)
- func (c *Client) IsClosed() bool
- func (c *Client) IsConnected() bool
- func (c *Client) IsInitialized() bool
- func (c *Client) ListTools(ctx context.Context, params protocol.ListToolsRequestParams) (*protocol.ListToolsResult, error)
- func (c *Client) RegisterNotificationHandler(method string, handler NotificationHandlerFunc) error
- func (c *Client) RegisterRequestHandler(method string, handler RequestHandlerFunc) error
- func (c *Client) ServerCapabilities() protocol.ServerCapabilities
- func (c *Client) ServerInfo() protocol.Implementation
- type ClientOptions
- type NotificationHandlerFunc
- type RequestHandlerFunc
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 represents a generic MCP client instance.
func NewClient ¶
func NewClient(clientName string, opts ClientOptions) (*Client, error)
NewClient creates a new generic Client instance. Transport must be provided via ClientOptions by specific constructors (NewSSEClient, NewWebSocketClient, etc.).
func NewSSEClient ¶ added in v0.1.11
func NewSSEClient(clientName string, baseURL string, basePath string, opts ClientOptions) (*Client, error)
NewSSEClient creates a new MCP client using the Streamable HTTP transport (SSE + POST). The baseURL should include the scheme and host (e.g., "http://localhost:8080"). The basePath argument defines the single path for the MCP endpoint (e.g., "/mcp").
func NewStdioClient ¶ added in v0.1.11
func NewStdioClient(clientName string, opts ClientOptions) (*Client, error)
NewStdioClient creates a new MCP client using stdio transport. This is useful for command-line tools and testing.
func NewWebSocketClient ¶ added in v0.1.11
func NewWebSocketClient(clientName string, baseURL string, basePath string, opts ClientOptions) (*Client, error)
NewWebSocketClient creates a new MCP client using WebSocket transport. The baseURL should include the scheme and host (e.g., "ws://localhost:8080" or "wss://localhost:8080"). The basePath argument defines the URL prefix for the WebSocket endpoint (e.g., "/mcp", resulting in "/mcp/ws").
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, params protocol.CallToolParams, progressToken interface{}) (*protocol.CallToolResult, error)
CallTool sends a 'tools/call' request via the transport.
func (*Client) CurrentState ¶ added in v1.0.7
CurrentState returns the current connection, initialization, and closed states.
func (*Client) IsClosed ¶ added in v1.0.7
IsClosed returns true if the client has been explicitly closed.
func (*Client) IsConnected ¶ added in v0.1.11
IsConnected returns true if the client has successfully completed the handshake and the underlying transport is not known to be closed.
func (*Client) IsInitialized ¶ added in v1.0.7
IsInitialized returns true if the client has successfully completed the initialization handshake.
func (*Client) ListTools ¶
func (c *Client) ListTools(ctx context.Context, params protocol.ListToolsRequestParams) (*protocol.ListToolsResult, error)
ListTools sends a 'tools/list' request via the transport.
func (*Client) RegisterNotificationHandler ¶
func (c *Client) RegisterNotificationHandler(method string, handler NotificationHandlerFunc) error
func (*Client) RegisterRequestHandler ¶
func (c *Client) RegisterRequestHandler(method string, handler RequestHandlerFunc) error
func (*Client) ServerCapabilities ¶
func (c *Client) ServerCapabilities() protocol.ServerCapabilities
ServerCapabilities returns the capabilities reported by the server.
func (*Client) ServerInfo ¶
func (c *Client) ServerInfo() protocol.Implementation
ServerInfo returns the information about the connected server.
type ClientOptions ¶
type ClientOptions struct {
Logger types.Logger
ClientCapabilities protocol.ClientCapabilities
PreferredProtocolVersion *string // Optional: Defaults to OldProtocolVersion
Transport types.Transport // Required: Must be provided by specific constructors
}
ClientOptions contains configuration options for creating a Client.
type NotificationHandlerFunc ¶
NotificationHandlerFunc defines the signature for functions that handle server-to-client notifications.
type RequestHandlerFunc ¶
RequestHandlerFunc defines the signature for functions that handle server-to-client requests.