Documentation
¶
Index ¶
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]interface{}) (*types.CallToolResult, error)
- func (c *Client) Close() error
- func (c *Client) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*types.GetPromptResult, error)
- func (c *Client) Initialize(ctx context.Context) error
- func (c *Client) ListPrompts(ctx context.Context) ([]types.Prompt, error)
- func (c *Client) ListResourceTemplates(ctx context.Context) ([]types.ResourceTemplate, error)
- func (c *Client) ListResources(ctx context.Context) ([]types.Resource, error)
- func (c *Client) ListTools(ctx context.Context) ([]types.Tool, error)
- func (c *Client) OnPromptListChanged(callback func())
- func (c *Client) OnResourceListChanged(callback func())
- func (c *Client) OnResourceUpdated(callback func(uri string))
- func (c *Client) OnToolListChanged(callback func())
- func (c *Client) ReadResource(ctx context.Context, uri string) ([]types.ResourceContent, error)
- func (c *Client) SetRoots(ctx context.Context, roots []types.Root) error
- func (c *Client) Start(ctx context.Context) error
- func (c *Client) SubscribeResource(ctx context.Context, uri string) error
- func (c *Client) SupportsPrompts() bool
- func (c *Client) SupportsResources() bool
- func (c *Client) SupportsRoots() bool
- func (c *Client) SupportsSampling() bool
- func (c *Client) SupportsTools() bool
- func (c *Client) UnsubscribeResource(ctx context.Context, uri string) error
- type Option
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 Model Context Protocol client
func NewDefaultClient ¶
NewDefaultClient creates an MCP client with default settings
func NewSseClient ¶ added in v0.2.0
NewSseClient creates an MCP client using SSE transport rather than stdio. `serverAddr` is the host:port where the MCP server is listening for SSE (e.g. "localhost:8080").
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]interface{}) (*types.CallToolResult, error)
CallTool invokes a specific tool by name with the provided arguments. Returns the tool's execution result or an error if the tool cannot be called. Returns an error if the server does not support tools.
func (*Client) GetPrompt ¶
func (c *Client) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*types.GetPromptResult, error)
GetPrompt retrieves a specific prompt by name, with optional arguments for templating. Returns the prompt content and any associated messages. Returns an error if the server does not support prompts or if the prompt cannot be found.
func (*Client) Initialize ¶
Initialize initiates the connection with the server
func (*Client) ListPrompts ¶
ListPrompts returns a list of all available prompts from the server. Returns an error if the server does not support prompts.
func (*Client) ListResourceTemplates ¶
ListResourceTemplates returns a list of available resource templates from the server. Templates can be used to construct valid resource URIs. Returns an error if the server does not support resources.
func (*Client) ListResources ¶
ListResources returns a list of all available resources from the server. Returns an error if the server does not support resources.
func (*Client) ListTools ¶
ListTools returns a list of all available tools from the server. Returns an error if the server does not support tools.
func (*Client) OnPromptListChanged ¶
func (c *Client) OnPromptListChanged(callback func())
OnPromptListChanged registers a callback that will be invoked when the list of available prompts changes on the server. No-op if the server does not support prompts.
func (*Client) OnResourceListChanged ¶
func (c *Client) OnResourceListChanged(callback func())
OnResourceListChanged registers a callback that will be invoked when the list of available resources changes on the server. No-op if the server does not support resources.
func (*Client) OnResourceUpdated ¶
OnResourceUpdated registers a callback that will be invoked when a subscribed resource changes. The callback receives the URI of the updated resource. No-op if the server does not support resources.
func (*Client) OnToolListChanged ¶
func (c *Client) OnToolListChanged(callback func())
OnToolListChanged registers a callback that will be invoked when the list of available tools changes on the server. No-op if the server does not support tools.
func (*Client) ReadResource ¶
ReadResource retrieves the contents of a specific resource identified by its URI. Returns the resource contents, which can be either text or binary data. Returns an error if the server does not support resources or if the resource cannot be read.
func (*Client) SetRoots ¶
SetRoots updates the list of root directories that the client exposes to the server. Each root must be a valid file:// URI. Returns an error if the client does not support roots or if any root is invalid.
func (*Client) SubscribeResource ¶
SubscribeResource subscribes to updates for a specific resource identified by its URI. The client will receive notifications through OnResourceUpdated when the resource changes. Returns an error if the server does not support resources or subscriptions.
func (*Client) SupportsPrompts ¶
SupportsPrompts returns whether the server supports prompts functionality
func (*Client) SupportsResources ¶
SupportsResources returns whether the server supports resources functionality
func (*Client) SupportsRoots ¶
SupportsRoots returns whether the client supports roots functionality
func (*Client) SupportsSampling ¶
SupportsSampling returns whether the client supports sampling functionality
func (*Client) SupportsTools ¶
SupportsTools returns whether the server supports tools functionality
type Option ¶
type Option func(*Client)
Option is a function that configures a Client
func WithSampling ¶
func WithSampling(handler types.SamplingHandler) Option
WithSampling enables sampling functionality on the client