client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

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 Model Context Protocol client

func NewClient

func NewClient(transport transport.Transport, opts ...Option) *Client

NewClient creates a new MCP client

func NewDefaultClient

func NewDefaultClient(ctx context.Context, connectString string, opts ...Option) (*Client, error)

NewDefaultClient creates an MCP client with default settings

func NewSseClient added in v0.2.0

func NewSseClient(ctx context.Context, serverAddr string, opts ...Option) (*Client, error)

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

func (c *Client) Close() error

Close shuts down the client

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

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

Initialize initiates the connection with the server

func (*Client) ListPrompts

func (c *Client) ListPrompts(ctx context.Context) ([]types.Prompt, error)

ListPrompts returns a list of all available prompts from the server. Returns an error if the server does not support prompts.

func (*Client) ListResourceTemplates

func (c *Client) ListResourceTemplates(ctx context.Context) ([]types.ResourceTemplate, error)

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

func (c *Client) ListResources(ctx context.Context) ([]types.Resource, error)

ListResources returns a list of all available resources from the server. Returns an error if the server does not support resources.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]types.Tool, error)

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

func (c *Client) OnResourceUpdated(callback func(uri string))

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

func (c *Client) ReadResource(ctx context.Context, uri string) ([]types.ResourceContent, error)

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

func (c *Client) SetRoots(ctx context.Context, roots []types.Root) error

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

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

Start begins processing messages

func (*Client) SubscribeResource

func (c *Client) SubscribeResource(ctx context.Context, uri string) error

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

func (c *Client) SupportsPrompts() bool

SupportsPrompts returns whether the server supports prompts functionality

func (*Client) SupportsResources

func (c *Client) SupportsResources() bool

SupportsResources returns whether the server supports resources functionality

func (*Client) SupportsRoots

func (c *Client) SupportsRoots() bool

SupportsRoots returns whether the client supports roots functionality

func (*Client) SupportsSampling

func (c *Client) SupportsSampling() bool

SupportsSampling returns whether the client supports sampling functionality

func (*Client) SupportsTools

func (c *Client) SupportsTools() bool

SupportsTools returns whether the server supports tools functionality

func (*Client) UnsubscribeResource

func (c *Client) UnsubscribeResource(ctx context.Context, uri string) error

UnsubscribeResource removes a subscription for a specific resource. Returns an error if the server does not support resources or if the subscription cannot be removed.

type Option

type Option func(*Client)

Option is a function that configures a Client

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger sets the logger for the client

func WithRoots

func WithRoots(initialRoots []types.Root) Option

WithRoots enables roots functionality on the client

func WithSampling

func WithSampling(handler types.SamplingHandler) Option

WithSampling enables sampling functionality on the client

Jump to

Keyboard shortcuts

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