client

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func New(endpoint string, opts ...Opt) (*Client, error)

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

func (c *Client) Authorized() bool

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

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

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

func (c *Client) Connected() bool

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

func (c *Client) Disconnect() error

Disconnect closes the session, when it's connected, or does nothing when it isn't

func (*Client) Endpoint added in v1.6.0

func (c *Client) Endpoint() string

Endpoint returns the URL of the server

func (*Client) Instructions added in v1.6.0

func (c *Client) Instructions() string

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

func (*Client) ListTools

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

ListTools returns the server's tools, every page of them. Returns ErrServiceUnavailable when it isn't connected.

func (*Client) Status added in v1.6.0

func (c *Client) Status() (*sdkmcp.Implementation, error)

Status returns the server's name, and version, as it said when it was connected, or nil when it isn't, and the error of the last connection, or of the session, when the server closed it, or nil

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

func WithClientOpts(opts ...client.ClientOpt) Opt

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

func WithName(name, version string) Opt

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

Jump to

Keyboard shortcuts

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