Documentation
¶
Index ¶
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, arguments json.RawMessage, ...) (any, error)
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*sdkmcp.GetPromptResult, error)
- func (c *Client) GetResource(ctx context.Context, uri string) (llm.Resource, error)
- func (c *Client) ListPrompts(_ context.Context) ([]llm.Prompt, error)
- func (c *Client) ListResources(_ context.Context) ([]llm.Resource, error)
- func (c *Client) ListTools(_ context.Context) ([]llm.Tool, error)
- func (c *Client) Probe(ctx context.Context, authfn func(err error, config *authclient.Config) error) (*schema.ConnectorState, error)
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) ServerInfo() (name, version, protocol string)
- type OnLoggingMessage
- type OnProgress
- type OnPromptListChanged
- type OnResourceListChanged
- type OnResourceUpdated
- type OnStateChange
- type OnToolListChanged
- type Opt
- func OptOnLoggingMessage(fn OnLoggingMessage) Opt
- func OptOnProgress(fn OnProgress) Opt
- func OptOnPromptListChanged(fn OnPromptListChanged) Opt
- func OptOnResourceListChanged(fn OnResourceListChanged) Opt
- func OptOnResourceUpdated(fn OnResourceUpdated) Opt
- func OptOnStateChange(fn OnStateChange) Opt
- func OptOnToolListChanged(fn OnToolListChanged) Opt
- func WithClientOpt(opts ...client.ClientOpt) Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
*authclient.Client
sdkmcp.Implementation
// contains filtered or unexported fields
}
Client is an MCP HTTP client that wraps the base HTTP client and provides typed methods for interacting with the MCP server.
func New ¶
New creates a new HTTP client with the given base URL and options. The url parameter should point to the MCP server endpoint, e.g. https://mcp.asana.com/sse
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, arguments json.RawMessage, meta ...schema.MetaValue) (any, error)
CallTool invokes a tool on the connected MCP server by name with the given Returns ErrNotConnected if no session is active.
func (*Client) Connect ¶
Connect establishes an MCP session, populates the tool/prompt/resource caches and leaves the session available for subsequent API calls.
func (*Client) GetPrompt ¶
func (c *Client) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*sdkmcp.GetPromptResult, error)
GetPrompt fetches a prepared prompt from the connected MCP server.
func (*Client) GetResource ¶
GetResource returns a resource handle for the given URI. If the URI does not exist in the cached metadata list, a minimal resource handle is still returned so callers can attempt a direct read.
func (*Client) ListPrompts ¶
ListPrompts returns the cached list of prompts advertised by the connected MCP server. The cache is populated on connect and refreshed automatically on each PromptListChanged notification. Returns ErrServiceUnavailable if not active.
func (*Client) ListResources ¶
ListResources returns the cached list of resources advertised by the connected MCP server. The cache is populated on connect and refreshed automatically on each ResourceListChanged notification. Returns ErrServiceUnavailable if no session is active.
func (*Client) ListTools ¶
ListTools returns the cached list of tools advertised by the connected MCP server. The cache is populated on connect and refreshed automatically on each ToolListChanged notification. Returns ErrServiceUnavailable if not active.
func (*Client) Probe ¶
func (c *Client) Probe(ctx context.Context, authfn func(err error, config *authclient.Config) error) (*schema.ConnectorState, error)
Probe makes a single MCP connection, reads the initialisation result (server name, version, instructions and capabilities), closes the session and returns the collected data as a ConnectorState ready to persist. It never leaves a persistent session open.
The provided ctx governs the connection timeout; cancelling it before the server responds causes Probe to return ctx.Err().
func (*Client) Run ¶
Run establishes an MCP session (including OAuth if required) and drives it until ctx is cancelled or the server closes the connection. It blocks until all in-flight messages have been drained and the underlying transport is torn down cleanly.
Run is safe to call concurrently with tool-call methods (CallTool, etc.); those methods return ErrNotConnected until the session is established and continue to work until Run returns.
Server-sent log messages and progress notifications are written to the default slog logger while Run is blocking.
func (*Client) ServerInfo ¶
ServerInfo returns the name, version and negotiated protocol version of the connected MCP server. It returns empty strings if the client is not connected.
type OnLoggingMessage ¶
OnLoggingMessage is called when the server sends a logging message.
type OnProgress ¶
OnProgress is called when the server sends a progress notification.
type OnPromptListChanged ¶
OnPromptListChanged is called when the server sends a prompt-list-changed notification.
type OnResourceListChanged ¶
OnResourceListChanged is called when the server sends a resource-list-changed notification.
type OnResourceUpdated ¶
OnResourceUpdated is called when the server sends a resource-updated notification.
type OnStateChange ¶
type OnStateChange func(ctx context.Context, state *schema.ConnectorState)
OnStateChange is called once after a successful connection handshake. The state carries the server name, version and capabilities from the MCP initialize response.
type OnToolListChanged ¶
OnToolListChanged is called when the server sends a tool-list-changed notification.
type Opt ¶
Opt is a functional option for configuring a Client.
func OptOnLoggingMessage ¶
func OptOnLoggingMessage(fn OnLoggingMessage) Opt
OptOnLoggingMessage registers a callback invoked whenever the server sends a logging message notification.
func OptOnProgress ¶
func OptOnProgress(fn OnProgress) Opt
OptOnProgress registers a callback invoked whenever the server sends a progress notification.
func OptOnPromptListChanged ¶
func OptOnPromptListChanged(fn OnPromptListChanged) Opt
OptOnPromptListChanged registers a callback invoked with the refreshed prompt list whenever the server notifies the client that its prompt list has changed.
func OptOnResourceListChanged ¶
func OptOnResourceListChanged(fn OnResourceListChanged) Opt
OptOnResourceListChanged registers a callback invoked with the refreshed resource list whenever the server notifies the client that its resource list has changed.
func OptOnResourceUpdated ¶
func OptOnResourceUpdated(fn OnResourceUpdated) Opt
OptOnResourceUpdated registers a callback invoked with the URI of the resource whenever the server sends a resource-updated notification.
func OptOnStateChange ¶
func OptOnStateChange(fn OnStateChange) Opt
OptOnStateChange registers a callback invoked once after each successful connection handshake. The state carries the server name, version and capabilities from the MCP initialize response.
func OptOnToolListChanged ¶
func OptOnToolListChanged(fn OnToolListChanged) Opt
OptOnToolListChanged registers a callback invoked whenever the server notifies the client that its tool list has changed.
func WithClientOpt ¶
WithClientOpt wraps one or more go-client options so they can be passed alongside mcp Opt values to New().