Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolsListChanged     = "notifications/tools/list_changed"
	PromptsListChanged   = "notifications/prompts/list_changed"
	ResourcesListChanged = "notifications/resources/list_changed"
	ResourceUpdated      = "notifications/resources/updated"
)

Notification methods a client receives via subscriptions/listen.

View Source
const StatelessRevision = "2026-07-28"

StatelessRevision is the first protocol revision without initialize, ping and logging/setLevel (SEP-2575); the handshake is server/discover.

View Source
const TasksExtension = "io.modelcontextprotocol/tasks"

TasksExtension identifies the Tasks extension (spec 2026-07-28).

Variables

NotificationMethods are the methods Notifications can wait for.

Functions

func CallRaw added in v1.4.0

func CallRaw(ctx context.Context, session *mcp.ClientSession, method string, params any) (map[string]any, error)

CallRaw sends any request on the session's connection and returns the raw result. Nothing is added to params, not even the per-request metadata.

func CallToolRaw

func CallToolRaw(ctx context.Context, session *mcp.ClientSession, toolName string, arguments any, meta map[string]any) (map[string]any, error)

CallToolRaw performs a tool call and returns the raw map[string]any result, bypassing the strict SDK unmarshaling that fails on missing "type" fields.

func Complete added in v1.4.0

func Complete(ctx context.Context, session *mcp.ClientSession, ref, arg, value string, contextArgs map[string]string) (*mcp.CompleteResult, error)

Complete asks the server for completion candidates of one argument. contextArgs are previously resolved arguments; nil if there are none.

func IsStateless added in v1.4.0

func IsStateless(session *mcp.ClientSession) bool

IsStateless reports whether the session negotiated StatelessRevision or later.

func ListAllPrompts added in v1.4.0

func ListAllPrompts(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Prompt, error)

ListAllPrompts follows nextCursor through every page of prompts/list.

func ListAllResources added in v1.4.0

func ListAllResources(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Resource, error)

ListAllResources follows nextCursor through every page of resources/list.

func ListAllTools added in v1.4.0

func ListAllTools(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Tool, error)

ListAllTools follows nextCursor through every page of tools/list. A single ListTools call returns only the first page, so servers that paginate would seem to have fewer tools.

func ParseCompleteRef added in v1.4.0

func ParseCompleteRef(ref string) (*mcp.CompleteReference, error)

ParseCompleteRef turns "prompt:<name>" or "resource:<uri template>" into a completion reference.

func ParseElicitAnswer added in v1.4.0

func ParseElicitAnswer(action, content string) (*mcp.ElicitResult, error)

ParseElicitAnswer turns "accept", "decline", "cancel" or "accept:<json>" and an optional separate JSON object into an elicitation result.

func Ping added in v1.4.0

func Ping(ctx context.Context, session *mcp.ClientSession) (string, error)

Ping checks that the server answers and returns the method that proved it. Since 2026-07-28 ping is removed; the server/discover exchange that opened the session is the liveness check then.

func RequestMeta added in v1.4.0

func RequestMeta(session *mcp.ClientSession, capabilities map[string]any) map[string]any

RequestMeta is the per-request metadata (2026-07-28) for requests sent over the raw path, which the SDK does not fill in: protocol version, client info and the given client capabilities (nil means none).

func TaskResult added in v1.4.0

func TaskResult(task map[string]any) (map[string]any, error)

TaskResult returns the final tool result of a completed task, or an error for a failed or cancelled one.

func WithLogLevel added in v1.4.0

func WithLogLevel(meta mcp.Meta, level string) mcp.Meta

WithLogLevel adds the per-request log level (2026-07-28) to meta.

Types

type DeprecationWatch added in v1.6.1

type DeprecationWatch struct {
	// contains filtered or unexported fields
}

DeprecationWatch notes the deprecated client features a server asks for: sampling and roots, deprecated since 2026-07-28 (SEP-2577).

It watches the wire, not the SDK: the SDK answers such requests inside its multi round-trip loop, behind any middleware. Answers travel in the inputResponses of the retried request, and multi round-trip only exists from 2026-07-28 on, so servers on older revisions — where both features are regular server-to-client requests — are not reported.

func (*DeprecationWatch) Used added in v1.6.1

func (w *DeprecationWatch) Used() []string

Used lists the deprecated features seen so far, sorted.

func (*DeprecationWatch) Wrap added in v1.6.1

Wrap returns t with every outgoing request inspected.

type Notification added in v1.4.0

type Notification struct {
	Method string
	URI    string // only for resources/updated
}

Notification is one received server notification.

type Notifications added in v1.4.0

type Notifications struct {
	// Out receives one line per notification.
	Out io.Writer
	// contains filtered or unexported fields
}

Notifications records list-changed and resource-updated notifications. Installing its handlers makes the SDK open a subscriptions/listen stream for every list the server marks as listChanged.

func (*Notifications) Install added in v1.4.0

func (n *Notifications) Install(opts *mcp.ClientOptions)

Install sets the notification handlers on opts.

func (*Notifications) Wait added in v1.4.0

func (n *Notifications) Wait(ctx context.Context, method, uri string, timeout time.Duration) error

Wait blocks until a notification with method (and uri, if not empty) arrives or timeout passes, and consumes it. Notifications received before the call count, so a wait after the triggering call cannot miss one.

type RPCError added in v0.2.1

type RPCError struct {
	Code    int64
	Message string
	Data    any
}

RPCError representing a JSON-RPC error

func (*RPCError) Error added in v0.2.1

func (e *RPCError) Error() string

type Responder added in v1.4.0

type Responder struct {
	// Strict makes a request without a queued answer fail the call; otherwise
	// elicitations are declined and sampling fails with an explanation.
	Strict bool
	// Out receives one line per answered request.
	Out io.Writer
	// contains filtered or unexported fields
}

Responder answers the input a server asks the client for (elicitation and sampling, since 2026-07-28 via multi round-trip requests) from queued, prepared answers, and remembers the last request for assertions.

func (*Responder) Answer added in v1.4.0

func (r *Responder) Answer(ctx context.Context, ir mcp.InputRequest, roots []*mcp.Root) (any, error)

Answer answers one input request that arrived outside the SDK's own multi round-trip handling, e.g. in a task's inputRequests. roots supplies the answer to roots/list.

func (*Responder) Install added in v1.4.0

func (r *Responder) Install(opts *mcp.ClientOptions)

Install sets the handlers on opts and declares the matching capabilities: roots, elicitation in form and URL mode, and sampling.

func (*Responder) LastElicitMessage added in v1.4.0

func (r *Responder) LastElicitMessage() string

LastElicitMessage returns the message of the last elicitation request, or "".

func (*Responder) LastSamplePrompt added in v1.4.0

func (r *Responder) LastSamplePrompt() string

LastSamplePrompt returns the text of the last sampling request, or "".

func (*Responder) QueueElicit added in v1.4.0

func (r *Responder) QueueElicit(res *mcp.ElicitResult)

QueueElicit adds an answer for the next elicitation request.

func (*Responder) QueueSample added in v1.4.0

func (r *Responder) QueueSample(text string)

QueueSample adds the model reply for the next sampling request.

type TaskClient added in v1.4.0

type TaskClient struct {
	Session   *mcp.ClientSession
	Responder *Responder // answers the task's inputRequests
	//lint:ignore SA1019 roots are deprecated since 2026-07-28 (SEP-2577) but still used by servers and regular before; remove with T-20260927-05
	Roots []*mcp.Root
	Out   io.Writer // one line per status change; optional
	// MaxPoll caps the server's pollIntervalMs, to keep tests fast.
	MaxPoll time.Duration
	// contains filtered or unexported fields
}

TaskClient runs tool calls as tasks. The go-sdk client does not know the extension (it drops the task fields of a CreateTaskResult), so requests go over the raw connection with the per-request metadata built here.

func (*TaskClient) Cancel added in v1.4.0

func (c *TaskClient) Cancel(ctx context.Context, taskID string) error

Cancel asks the server to cancel a task (tasks/cancel).

func (*TaskClient) Get added in v1.4.0

func (c *TaskClient) Get(ctx context.Context, taskID string) (map[string]any, error)

Get returns the current state of a task (tasks/get).

func (*TaskClient) Start added in v1.4.0

func (c *TaskClient) Start(ctx context.Context, name string, args map[string]any) (res map[string]any, done bool, err error)

Start calls the tool declaring the extension. It returns the task handle, or with done set the synchronous CallToolResult if the server chose not to create a task.

func (*TaskClient) Wait added in v1.4.0

func (c *TaskClient) Wait(ctx context.Context, taskID string) (map[string]any, error)

Wait polls the task until it is completed, failed or cancelled, answering input requests on the way, and returns its final state.

type ToolError added in v1.2.0

type ToolError struct {
	Message string
}

ToolError represents an application-level tool error (CallToolResult with isError: true).

func (*ToolError) Error added in v1.2.0

func (e *ToolError) Error() string

Jump to

Keyboard shortcuts

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