client

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package client provides the MCP client implementation.

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 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) Close

func (c *Client) Close() error

Close gracefully shuts down the client connection and its transport.

func (*Client) Connect

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

Connect performs the MCP handshake using the configured transport.

func (*Client) CurrentState added in v1.0.7

func (c *Client) CurrentState() (connected bool, initialized bool, closed bool)

CurrentState returns the current connection, initialization, and closed states.

func (*Client) IsClosed added in v1.0.7

func (c *Client) IsClosed() bool

IsClosed returns true if the client has been explicitly closed.

func (*Client) IsConnected added in v0.1.11

func (c *Client) IsConnected() bool

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

func (c *Client) IsInitialized() bool

IsInitialized returns true if the client has successfully completed the initialization handshake.

func (*Client) ListTools

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

type NotificationHandlerFunc func(ctx context.Context, params interface{}) error

NotificationHandlerFunc defines the signature for functions that handle server-to-client notifications.

type RequestHandlerFunc

type RequestHandlerFunc func(ctx context.Context, id interface{}, params interface{}) error

RequestHandlerFunc defines the signature for functions that handle server-to-client requests.

Jump to

Keyboard shortcuts

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