Documentation
¶
Index ¶
- Constants
- Variables
- func CallRaw(ctx context.Context, session *mcp.ClientSession, method string, params any) (map[string]any, error)
- func CallRawJSON(ctx context.Context, session *mcp.ClientSession, method string, params any) (json.RawMessage, error)
- func CallToolRaw(ctx context.Context, session *mcp.ClientSession, toolName string, ...) (map[string]any, error)
- func Complete(ctx context.Context, session *mcp.ClientSession, ref, arg, value string, ...) (*mcp.CompleteResult, error)
- func IsStateless(session *mcp.ClientSession) bool
- func ListAllPrompts(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Prompt, error)
- func ListAllResources(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Resource, error)
- func ListAllTools(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Tool, error)
- func ParseCompleteRef(ref string) (*mcp.CompleteReference, error)
- func ParseElicitAnswer(action, content string) (*mcp.ElicitResult, error)
- func Ping(ctx context.Context, session *mcp.ClientSession) (string, error)
- func RequestMeta(session *mcp.ClientSession, capabilities map[string]any) map[string]any
- func TaskResult(task map[string]any) (map[string]any, error)
- func WithLogLevel(meta mcp.Meta, level string) mcp.Meta
- type DeprecationWatch
- type Notification
- type NotificationTap
- type Notifications
- type RPCError
- type Responder
- func (r *Responder) Answer(ctx context.Context, ir mcp.InputRequest, roots []*mcp.Root) (any, error)
- func (r *Responder) Install(opts *mcp.ClientOptions)
- func (r *Responder) LastElicitMessage() string
- func (r *Responder) LastSamplePrompt() string
- func (r *Responder) QueueElicit(res *mcp.ElicitResult)
- func (r *Responder) QueueSample(text string)
- type TappedNotification
- type TaskClient
- func (c *TaskClient) Answer(ctx context.Context, taskID string, raw any, answered map[string]bool) error
- func (c *TaskClient) Cancel(ctx context.Context, taskID string) error
- func (c *TaskClient) Get(ctx context.Context, taskID string) (map[string]any, error)
- func (c *TaskClient) Start(ctx context.Context, name string, args map[string]any) (res map[string]any, done bool, err error)
- func (c *TaskClient) Wait(ctx context.Context, taskID string) (map[string]any, error)
- type ToolError
Constants ¶
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.
const StatelessRevision = "2026-07-28"
StatelessRevision is the first protocol revision without initialize, ping and logging/setLevel (SEP-2575); the handshake is server/discover.
const TasksExtension = "io.modelcontextprotocol/tasks"
TasksExtension identifies the Tasks extension (spec 2026-07-28).
Variables ¶
var NotificationMethods = []string{ToolsListChanged, PromptsListChanged, ResourcesListChanged, ResourceUpdated}
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 CallRawJSON ¶ added in v1.9.0
func CallRawJSON(ctx context.Context, session *mcp.ClientSession, method string, params any) (json.RawMessage, error)
CallRawJSON is CallRaw returning the result exactly as it came over the wire, which keeps the key order of objects that a map would lose.
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
ListAllPrompts follows nextCursor through every page of prompts/list.
func ListAllResources ¶ added in v1.4.0
ListAllResources follows nextCursor through every page of resources/list.
func ListAllTools ¶ added in v1.4.0
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
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
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
TaskResult returns the final tool result of a completed task, or an error for a failed or cancelled one.
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.
type Notification ¶ added in v1.4.0
Notification is one received server notification.
type NotificationTap ¶ added in v1.8.0
type NotificationTap struct {
// contains filtered or unexported fields
}
NotificationTap records server notifications the go-sdk does not know (notifications/tasks) or keeps to itself (notifications/subscriptions/ acknowledged), by reading the raw messages below the SDK. The messages are passed on unchanged.
func NewNotificationTap ¶ added in v1.8.0
func NewNotificationTap(methods ...string) *NotificationTap
NewNotificationTap records notifications with one of the methods.
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.
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
LastElicitMessage returns the message of the last elicitation request, or "".
func (*Responder) LastSamplePrompt ¶ added in v1.4.0
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
QueueSample adds the model reply for the next sampling request.
type TappedNotification ¶ added in v1.8.0
TappedNotification is one recorded notification.
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
// 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) Answer ¶ added in v1.8.0
func (c *TaskClient) Answer(ctx context.Context, taskID string, raw any, answered map[string]bool) error
Answer fulfills the not yet answered input requests of a task via tasks/update; answered carries the keys already answered across polls.
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) 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.