Documentation
¶
Overview ¶
Package client is a client of a remote MCP server, over HTTP, with go-client as its transport, so its options, such as a user agent, headers, a token, and tracing, apply to the requests of the MCP SDK.
A server is reached at its URL, with the streamable HTTP transport of the 2025-03-26 protocol, or the SSE transport of the 2024-11-05 protocol, as the server has. A server which runs as a command, over stdio, isn't one.
Index ¶
- type ChangeFunc
- type Client
- func (c *Client) Authorized() bool
- func (c *Client) CallTool(ctx context.Context, name string, arguments json.RawMessage) (*sdkmcp.CallToolResult, error)
- func (c *Client) Challenge() *authclient.AuthError
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) Connected() bool
- func (c *Client) Disconnect() error
- func (c *Client) Endpoint() string
- func (c *Client) Instructions() string
- func (c *Client) ListTools(ctx context.Context) ([]*sdkmcp.Tool, error)
- func (c *Client) Status() (*sdkmcp.Implementation, error)
- type Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangeFunc ¶ added in v1.6.0
type ChangeFunc func(server *sdkmcp.Implementation, err error)
ChangeFunc is called, without a lock, when the client is connected, with the server, as it said, or disconnected, with nil, and why, when it wasn't disconnected, such as when the server closed the session
type Client ¶
type Client struct {
*authclient.Client
// contains filtered or unexported fields
}
Client is a client of a remote MCP server, at its URL, whose requests are made with the auth package's client, of go-client, so a server which needs to be authorized says how, which Discover, and DiscoverWithError, discover
func New ¶
New returns a client of the MCP server at the URL, such as https://mcp.example.com/mcp, or one which ends /sse, of a server with the SSE transport, with the options, such as its name, and version, which the server is told, with WithName, and go-client's, with WithClientOpts. It isn't connected, until Connect is called. Returns ErrBadParameter when the URL isn't an http, or https, URL with a host.
func (*Client) Authorized ¶ added in v1.6.0
Authorized returns true when the client's requests are authorized, with a token
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, arguments json.RawMessage) (*sdkmcp.CallToolResult, error)
CallTool calls the server's tool with the name, with its arguments, as JSON, which can be nil, and returns its result, which can be an error the tool returned, rather than one of the call. Returns ErrServiceUnavailable when it isn't connected.
func (*Client) Challenge ¶ added in v1.6.0
func (c *Client) Challenge() *authclient.AuthError
Challenge returns the challenge of the server, as its last request wasn't authorized, such as as it was connected, which says how it's authorized, or nil
func (*Client) Connect ¶
Connect connects to the server, with the streamable HTTP transport, or with SSE, when the server hasn't it, and returns once the session is initialized, or at once, when it's connected. The context is the connection's, as it's made, rather than the session's, which has its own, so it lasts until it's disconnected, or the server closes it, as SSE's stream lasts as long as the context it's connected with. It's connected without the client's lock held, so its status can be asked for as it is, and once at a time: a Connect as it's being connected waits for it, and returns as it does, or as its own context is cancelled. Returns ErrServiceUnavailable when it can't be connected, with each transport's error, or the context's error, when it's cancelled, or disconnected, as it's connected.
func (*Client) Connected ¶ added in v1.6.0
Connected returns true when the client has a session with the server, which it hasn't once it's disconnected, or the server closes it
func (*Client) Disconnect ¶ added in v1.6.0
Disconnect closes the session, when it's connected, or does nothing when it isn't
func (*Client) Instructions ¶ added in v1.6.0
Instructions returns how to use the server, and its tools, as it said when it was connected, or nothing, when it isn't, or said nothing
type Opt ¶
type Opt func(*opt) error
Opt is an option of a client
func WithChange ¶ added in v1.6.0
func WithChange(fn ChangeFunc) Opt
WithChange is called when the client is connected, or disconnected, without a lock, which it isn't when a connection fails, or it's disconnected when it isn't connected
func WithClientOpts ¶ added in v1.6.0
WithClientOpts are options of go-client, such as client.OptHeader, client.OptUserAgent, client.OptReqToken, or client.OptTrace, which apply to the client's requests, and so to those of the MCP SDK. Its timeout, with client.OptTimeout, applies to its own requests, but not to an MCP session's, whose streams last as long as the session, and are cancelled with its context.
func WithName ¶ added in v1.6.0
WithName is the name, and version, of the client, which the server is told, as it connects, rather than schema.DefaultName, and schema.DefaultVersion. The version can be empty.
func WithTokenSource ¶ added in v1.6.0
func WithTokenSource(tokens oauth2.TokenSource) Opt
WithTokenSource is the source of the token the server's requests are authorized with, as a bearer token, such as one which is refreshed, as it expires, which is only sent to the server's origin
func WithToolsChanged ¶ added in v1.6.0
func WithToolsChanged(fn func()) Opt
WithToolsChanged is called when the server says its tools changed, so they're listed again, without a lock