client

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: MIT Imports: 16 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 an MCP client instance using the SSE+HTTP hybrid transport.

func NewClient

func NewClient(clientName string, opts ClientOptions) (*Client, error)

NewClient creates a new Client for SSE+HTTP transport.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, params protocol.CallToolParams, progressToken *protocol.ProgressToken) (*protocol.CallToolResult, error)

CallTool sends a 'tools/call' request via HTTP POST and waits for the response via SSE.

func (*Client) Close

func (c *Client) Close() error

Close gracefully shuts down the client connection.

func (*Client) Connect

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

Connect establishes the SSE connection and performs the MCP handshake.

func (*Client) ListTools

ListTools sends a 'tools/list' request via HTTP POST and waits for the response via SSE.

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

func (*Client) ServerInfo

func (c *Client) ServerInfo() protocol.Implementation

type ClientOptions

type ClientOptions struct {
	Logger                   types.Logger
	ClientCapabilities       protocol.ClientCapabilities
	HTTPClient               *http.Client // Allow providing a custom HTTP client
	ServerBaseURL            string       // Required: Base URL of the MCP server
	MessageEndpoint          string       // Optional: Defaults to "/message"
	SSEEndpoint              string       // Optional: Defaults to "/sse"
	PreferredProtocolVersion string       // Optional: Defaults to CurrentProtocolVersion
}

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