protocol

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package protocol defines the wire types of the Model Context Protocol, revision 2026-07-28. It has no dependencies outside the standard library.

Index

Constants

View Source
const (
	RefPrompt   = "ref/prompt"
	RefResource = "ref/resource"
)
View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602 // also: unknown tool/prompt, resource not found, bad cursor
	CodeInternal       = -32603
)

JSON-RPC standard error codes.

View Source
const (
	CodeHeaderMismatch             = -32020
	CodeMissingClientCapability    = -32021
	CodeUnsupportedProtocolVersion = -32022
)

MCP-reserved error codes (-32020..-32099). No constants exist in -32000..-32019: the spec forbids allocating new codes there.

View Source
const (
	ResultTypeComplete      = "complete"
	ResultTypeInputRequired = "input_required"
)
View Source
const (
	MetaProtocolVersion    = "io.modelcontextprotocol/protocolVersion"
	MetaClientInfo         = "io.modelcontextprotocol/clientInfo"
	MetaClientCapabilities = "io.modelcontextprotocol/clientCapabilities"
	MetaServerInfo         = "io.modelcontextprotocol/serverInfo"
	MetaSubscriptionID     = "io.modelcontextprotocol/subscriptionId"
)

Reserved _meta keys.

View Source
const (
	MethodDiscover               = "server/discover"
	MethodToolsList              = "tools/list"
	MethodToolsCall              = "tools/call"
	MethodPromptsList            = "prompts/list"
	MethodPromptsGet             = "prompts/get"
	MethodResourcesList          = "resources/list"
	MethodResourcesTemplatesList = "resources/templates/list"
	MethodResourcesRead          = "resources/read"
	MethodCompletionComplete     = "completion/complete"
	MethodSubscriptionsListen    = "subscriptions/listen"

	// MethodElicitationCreate appears only inside MRTR inputRequests, never
	// as a dispatched RPC.
	MethodElicitationCreate = "elicitation/create"

	NotificationProgress                  = "notifications/progress"
	NotificationCancelled                 = "notifications/cancelled"
	NotificationSubscriptionsAcknowledged = "notifications/subscriptions/acknowledged"
	NotificationToolsListChanged          = "notifications/tools/list_changed"
	NotificationPromptsListChanged        = "notifications/prompts/list_changed"
	NotificationResourcesListChanged      = "notifications/resources/list_changed"
	NotificationResourcesUpdated          = "notifications/resources/updated"
)

The complete 2026-07-28 method set. sampling/createMessage and roots/list exist on the wire only as MRTR InputRequest payload shapes and are not modeled by this SDK (both features are deprecated).

View Source
const JSONRPCVersion = "2.0"
View Source
const MaxCompletionValues = 100
View Source
const Version = "2026-07-28"

Version is the only protocol revision this SDK speaks.

Variables

This section is empty.

Functions

func MarshalResult added in v1.3.0

func MarshalResult(r Result) ([]byte, error)

MarshalResult marshals r with its resultType discriminator spliced in as the first key of the JSON object. This is the only code path that writes resultType, so it can never be forgotten or inconsistent.

func PeekResultType added in v1.3.0

func PeekResultType(raw json.RawMessage) (string, error)

PeekResultType reads the resultType discriminator from a raw result body. An absent resultType maps to "complete" — the spec's backward-compat rule for results from servers on earlier protocol revisions. Servers implementing 2026-07-28 MUST include the field, and the client rejects responses without it; this helper stays lenient for raw consumers.

Types

type AckParams added in v1.3.0

type AckParams struct {
	Meta          NotificationMeta   `json:"_meta,omitzero"`
	Notifications SubscriptionFilter `json:"notifications"`
}

AckParams is the payload of notifications/subscriptions/acknowledged — the first message on every subscription stream, carrying the honored subset.

type Annotations added in v1.3.0

type Annotations struct {
	Audience     []Role   `json:"audience,omitempty"`
	Priority     *float64 `json:"priority,omitempty"`
	LastModified string   `json:"lastModified,omitempty"`
}

Annotations attach audience/priority/recency hints to content and resources.

type AudioContent added in v1.1.2

type AudioContent struct {
	Data        string                     `json:"data"` // base64
	MimeType    string                     `json:"mimeType"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

func NewAudioContent added in v1.1.2

func NewAudioContent(data, mimeType string) AudioContent

func (AudioContent) MarshalJSON added in v1.3.0

func (c AudioContent) MarshalJSON() ([]byte, error)

type CacheControl added in v1.3.0

type CacheControl struct {
	TTLMs      int64      `json:"ttlMs"`
	CacheScope CacheScope `json:"cacheScope"`
}

CacheControl is embedded in the six cacheable results (server/discover, tools/list, prompts/list, resources/list, resources/templates/list, resources/read). Both fields are required on the wire: ttlMs deliberately has no omitempty because 0 is meaningful ("immediately stale").

func (*CacheControl) CacheControlRef added in v1.3.0

func (c *CacheControl) CacheControlRef() *CacheControl

type CacheScope added in v1.3.0

type CacheScope string
const (
	CacheScopePublic  CacheScope = "public"
	CacheScopePrivate CacheScope = "private"
)

type Cacheable added in v1.3.0

type Cacheable interface {
	CacheControlRef() *CacheControl
}

Cacheable is satisfied by every result embedding CacheControl; the server uses it to fill defaults centrally.

type CallToolParams

type CallToolParams struct {
	Meta      RequestMeta    `json:"_meta"`
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments,omitempty"`
	// InputResponses and RequestState are set only on an MRTR retry.
	InputResponses InputResponses `json:"inputResponses,omitempty"`
	RequestState   string         `json:"requestState,omitempty"`
}

type CallToolResult

type CallToolResult struct {
	WithMeta
	Content ContentList `json:"content"`
	// StructuredContent may be any JSON value (SEP-2106).
	StructuredContent any  `json:"structuredContent,omitempty"`
	IsError           bool `json:"isError,omitempty"`
}

func NewToolResultError

func NewToolResultError(text string) *CallToolResult

NewToolResultError reports a tool execution error (isError, not a protocol error).

func NewToolResultStructured added in v1.3.0

func NewToolResultStructured(v any) (*CallToolResult, error)

NewToolResultStructured returns structured content mirrored as serialized JSON in a text block, as the spec recommends for backwards compatibility.

func NewToolResultText

func NewToolResultText(text string) *CallToolResult

func (*CallToolResult) ResultType added in v1.3.0

func (*CallToolResult) ResultType() string

type CancelledParams added in v1.3.0

type CancelledParams struct {
	Meta      NotificationMeta `json:"_meta,omitzero"`
	RequestID RequestID        `json:"requestId"`
	Reason    string           `json:"reason,omitempty"`
}

CancelledParams is the payload of notifications/cancelled. On stdio the client sends it to cancel an in-flight request; servers send it only to tear down a subscriptions/listen stream.

type ClientCapabilities

type ClientCapabilities struct {
	Elicitation  *ElicitationCapability     `json:"elicitation,omitempty"`
	Extensions   map[string]json.RawMessage `json:"extensions,omitempty"`
	Experimental map[string]json.RawMessage `json:"experimental,omitempty"`
}

ClientCapabilities travels in every request's _meta. The zero value is a valid, empty declaration. Roots and sampling are deprecated in 2026-07-28 and intentionally not modeled; unknown keys are ignored on decode.

type CompleteArgument added in v1.3.0

type CompleteArgument struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type CompleteContext added in v1.3.0

type CompleteContext struct {
	Arguments map[string]string `json:"arguments,omitempty"`
}

type CompleteParams added in v1.3.0

type CompleteParams struct {
	Meta     RequestMeta      `json:"_meta"`
	Ref      CompletionRef    `json:"ref"`
	Argument CompleteArgument `json:"argument"`
	Context  *CompleteContext `json:"context,omitempty"`
}

type CompleteResult added in v1.1.2

type CompleteResult struct {
	WithMeta
	Completion CompletionValues `json:"completion"`
}

func NewCompleteResult added in v1.3.0

func NewCompleteResult(values []string) *CompleteResult

NewCompleteResult caps values at MaxCompletionValues and sets hasMore accordingly.

func (*CompleteResult) ResultType added in v1.3.0

func (*CompleteResult) ResultType() string

type CompletionRef added in v1.3.0

type CompletionRef struct {
	Type string `json:"type"` // RefPrompt | RefResource
	Name string `json:"name,omitempty"`
	URI  string `json:"uri,omitempty"`
}

CompletionRef identifies what is being completed: a prompt (by name) or a resource template (by uri).

type CompletionValues added in v1.3.0

type CompletionValues struct {
	Values  []string `json:"values"`
	Total   int      `json:"total,omitempty"`
	HasMore bool     `json:"hasMore,omitempty"`
}

type Content

type Content interface {
	// contains filtered or unexported methods
}

Content is the sealed union of message content blocks. Concrete types: TextContent, ImageContent, AudioContent, ResourceLink, EmbeddedResource, and UnknownContent (which round-trips unrecognized types verbatim).

func UnmarshalContent

func UnmarshalContent(data []byte) (Content, error)

UnmarshalContent decodes a single content block by its type discriminator.

type ContentList added in v1.3.0

type ContentList []Content

ContentList is the decodable form of []Content. It marshals nil as [].

func (ContentList) MarshalJSON added in v1.3.0

func (l ContentList) MarshalJSON() ([]byte, error)

func (*ContentList) UnmarshalJSON added in v1.3.0

func (l *ContentList) UnmarshalJSON(b []byte) error

type DiscoverParams added in v1.3.0

type DiscoverParams struct {
	Meta RequestMeta `json:"_meta"`
}

DiscoverParams carries only _meta. Servers must implement server/discover; clients may call it before any other request.

type DiscoverResult added in v1.3.0

type DiscoverResult struct {
	WithMeta
	CacheControl
	SupportedVersions []string           `json:"supportedVersions"`
	Capabilities      ServerCapabilities `json:"capabilities"`
	Instructions      string             `json:"instructions,omitempty"`
}

DiscoverResult advertises supported versions, capabilities and identity (serverInfo travels in _meta). It is cacheable.

func (*DiscoverResult) ResultType added in v1.3.0

func (*DiscoverResult) ResultType() string

type ElicitAction added in v1.3.0

type ElicitAction string
const (
	ElicitActionAccept  ElicitAction = "accept"
	ElicitActionDecline ElicitAction = "decline"
	ElicitActionCancel  ElicitAction = "cancel"
)

type ElicitMode added in v1.3.0

type ElicitMode string
const (
	ElicitModeForm ElicitMode = "form"
	ElicitModeURL  ElicitMode = "url"
)

type ElicitParams added in v1.3.0

type ElicitParams struct {
	Mode    ElicitMode `json:"mode,omitempty"`
	Message string     `json:"message"`
	// RequestedSchema is a flat object schema of primitives (form mode).
	RequestedSchema JSONSchema `json:"requestedSchema,omitempty"`
	// URL is the address the user should visit (url mode). Servers must use
	// url mode — never form mode — for secrets and credentials.
	URL string `json:"url,omitempty"`
}

ElicitParams is the params shape of an elicitation/create input request. A missing Mode means form.

func (*ElicitParams) EffectiveMode added in v1.3.0

func (p *ElicitParams) EffectiveMode() ElicitMode

type ElicitResult added in v1.3.0

type ElicitResult struct {
	Action  ElicitAction   `json:"action"`
	Content map[string]any `json:"content,omitempty"`
}

ElicitResult is the bare result body a client supplies for an elicitation input request. Content values are primitives or string arrays.

type ElicitationCapability added in v1.1.1

type ElicitationCapability struct {
	Form *struct{} `json:"form,omitempty"`
	URL  *struct{} `json:"url,omitempty"`
}

ElicitationCapability declares supported elicitation modes. An empty object is equivalent to declaring form mode only.

func (*ElicitationCapability) SupportsForm added in v1.3.0

func (c *ElicitationCapability) SupportsForm() bool

SupportsForm reports whether form-mode elicitation is declared. Per spec an empty elicitation object means form-only support.

func (*ElicitationCapability) SupportsURL added in v1.3.0

func (c *ElicitationCapability) SupportsURL() bool

type EmbeddedResource added in v1.3.0

type EmbeddedResource struct {
	Resource    ResourceContents           `json:"resource"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

func NewEmbeddedResource added in v1.3.0

func NewEmbeddedResource(contents ResourceContents) EmbeddedResource

func (EmbeddedResource) MarshalJSON added in v1.3.0

func (c EmbeddedResource) MarshalJSON() ([]byte, error)

type EmptyResult added in v1.2.0

type EmptyResult struct{ WithMeta }

EmptyResult is a bare complete result, used by acknowledgement-style methods (e.g. the tasks extension's tasks/update and tasks/cancel).

func (*EmptyResult) ResultType added in v1.3.0

func (*EmptyResult) ResultType() string

type Error added in v1.3.0

type Error struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
	// contains filtered or unexported fields
}

Error is the single error type of this SDK. It round-trips code, message and data in both directions: a handler returning *Error has it written verbatim to the wire, and a client receiving an error response surfaces it unwrapped via errors.As.

func Errorf added in v1.3.0

func Errorf(code int, format string, args ...any) *Error

func HeaderMismatchError added in v1.3.0

func HeaderMismatchError(detail string) *Error

func MethodNotFoundError added in v1.3.0

func MethodNotFoundError(method string) *Error

func MissingCapabilityError added in v1.3.0

func MissingCapabilityError(required ClientCapabilities) *Error

func ResourceNotFoundError added in v1.3.0

func ResourceNotFoundError(uri string) *Error

ResourceNotFoundError reports a missing resource. Per 2026-07-28 this is -32602 (Invalid Params) with the URI in data; -32002 is retired.

func UnsupportedVersionError added in v1.3.0

func UnsupportedVersionError(requested string, supported []string) *Error

func (*Error) Error added in v1.3.0

func (e *Error) Error() string

func (*Error) HTTPStatus added in v1.3.0

func (e *Error) HTTPStatus() int

HTTPStatus returns the HTTP status an HTTP transport must use when carrying this error. Errors produced by request validation override the default per-code mapping.

func (*Error) MissingCapabilities added in v1.3.0

func (e *Error) MissingCapabilities() (*ClientCapabilities, bool)

MissingCapabilities decodes the data payload if this is a MissingRequiredClientCapability error.

func (*Error) UnsupportedVersion added in v1.3.0

func (e *Error) UnsupportedVersion() (*UnsupportedVersionData, bool)

UnsupportedVersion decodes the data payload if this is an UnsupportedProtocolVersion error.

func (*Error) WithData added in v1.3.0

func (e *Error) WithData(v any) *Error

WithData attaches a JSON-marshaled data payload. Marshal failures are silently dropped (data is auxiliary by design).

type ExtensionResult added in v1.3.0

type ExtensionResult struct{ R Result }

ExtensionResult carries an extension-defined Result (e.g. the tasks extension's CreateTaskResult) through the sealed response unions. The server unwraps it before finalizing, so only the inner result reaches the wire.

func (*ExtensionResult) ResultType added in v1.3.0

func (e *ExtensionResult) ResultType() string

type GetPromptParams

type GetPromptParams struct {
	Meta      RequestMeta       `json:"_meta"`
	Name      string            `json:"name"`
	Arguments map[string]string `json:"arguments,omitempty"`
	// InputResponses and RequestState are set only on an MRTR retry.
	InputResponses InputResponses `json:"inputResponses,omitempty"`
	RequestState   string         `json:"requestState,omitempty"`
}

type GetPromptResult

type GetPromptResult struct {
	WithMeta
	Description string          `json:"description,omitempty"`
	Messages    []PromptMessage `json:"messages"`
}

func NewGetPromptResult

func NewGetPromptResult(description string, messages ...PromptMessage) *GetPromptResult

func (*GetPromptResult) ResultType added in v1.3.0

func (*GetPromptResult) ResultType() string

type Icon added in v1.2.2

type Icon struct {
	Src      string   `json:"src"`
	MimeType string   `json:"mimeType,omitempty"`
	Sizes    []string `json:"sizes,omitempty"`
}

type ImageContent

type ImageContent struct {
	Data        string                     `json:"data"` // base64
	MimeType    string                     `json:"mimeType"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

func NewImageContent

func NewImageContent(data, mimeType string) ImageContent

func (ImageContent) MarshalJSON added in v1.3.0

func (c ImageContent) MarshalJSON() ([]byte, error)

type Implementation added in v1.3.0

type Implementation struct {
	Name    string `json:"name"`
	Title   string `json:"title,omitempty"`
	Version string `json:"version"`
}

Implementation identifies a client or server. Self-reported and unverified; never use it for security decisions.

type InputRequest added in v1.3.0

type InputRequest struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

InputRequest is a bare {method, params} pair — no JSON-RPC envelope, no ID. Elicitation is first-class; other methods (deprecated roots/sampling, future extensions) round-trip untouched.

func NewElicitFormRequest added in v1.3.0

func NewElicitFormRequest(message string, requestedSchema JSONSchema) InputRequest

NewElicitFormRequest builds a form-mode elicitation input request.

func NewElicitURLRequest added in v1.3.0

func NewElicitURLRequest(message, url string) InputRequest

NewElicitURLRequest builds a url-mode elicitation input request. There is no elicitationId in 2026-07-28; correlate via requestState instead.

func (InputRequest) Elicit added in v1.3.0

func (r InputRequest) Elicit() (*ElicitParams, error)

Elicit decodes the request params as ElicitParams; it fails if the request is not elicitation/create.

type InputRequests added in v1.3.0

type InputRequests map[string]InputRequest

type InputRequired added in v1.3.0

type InputRequired struct {
	WithMeta
	Requests InputRequests `json:"inputRequests,omitempty"`
	State    string        `json:"requestState,omitempty"`
}

InputRequired is the "input_required" interim result shared by tools/call, prompts/get and resources/read. At least one of Requests or State must be set; the server validates this before sending.

func RequireInput added in v1.3.0

func RequireInput(reqs InputRequests, state string) *InputRequired

RequireInput builds an interim MRTR result. state may be empty when reqs is non-empty and vice versa.

func (*InputRequired) ResultType added in v1.3.0

func (*InputRequired) ResultType() string

func (*InputRequired) Validate added in v1.3.0

func (r *InputRequired) Validate() error

Validate enforces the spec rule that an InputRequired carries at least one of inputRequests or requestState.

type InputResponses added in v1.3.0

type InputResponses map[string]json.RawMessage

InputResponses maps request keys to bare result bodies. Values stay raw on the wire because responses carry no discriminator; the reader always knows what it asked for and decodes by expectation.

func (InputResponses) Elicit added in v1.3.0

func (r InputResponses) Elicit(key string) (*ElicitResult, error)

Elicit decodes the response for key as an ElicitResult.

func (InputResponses) Set added in v1.3.0

func (r InputResponses) Set(key string, v any) error

Set marshals v as the response for key.

type JSONSchema

type JSONSchema map[string]any

JSONSchema is a JSON Schema document. 2026-07-28 permits any JSON Schema 2020-12 keywords; the default dialect when $schema is absent is 2020-12.

type Kind added in v1.3.0

type Kind int

Kind classifies a Message. It is the single source of truth for message classification; callers must not re-derive it from field presence.

const (
	KindInvalid Kind = iota
	KindRequest
	KindNotification
	KindResponse
	KindError
)

type ListPromptsParams

type ListPromptsParams struct {
	Meta   RequestMeta `json:"_meta"`
	Cursor string      `json:"cursor,omitempty"`
}

type ListPromptsResult

type ListPromptsResult struct {
	WithMeta
	CacheControl
	Prompts    []*Prompt `json:"prompts"`
	NextCursor string    `json:"nextCursor,omitempty"`
}

func (*ListPromptsResult) ResultType added in v1.3.0

func (*ListPromptsResult) ResultType() string

type ListResourceTemplatesParams added in v1.2.2

type ListResourceTemplatesParams struct {
	Meta   RequestMeta `json:"_meta"`
	Cursor string      `json:"cursor,omitempty"`
}

type ListResourceTemplatesResult

type ListResourceTemplatesResult struct {
	WithMeta
	CacheControl
	ResourceTemplates []*ResourceTemplate `json:"resourceTemplates"`
	NextCursor        string              `json:"nextCursor,omitempty"`
}

func (*ListResourceTemplatesResult) ResultType added in v1.3.0

func (*ListResourceTemplatesResult) ResultType() string

type ListResourcesParams

type ListResourcesParams struct {
	Meta   RequestMeta `json:"_meta"`
	Cursor string      `json:"cursor,omitempty"`
}

type ListResourcesResult

type ListResourcesResult struct {
	WithMeta
	CacheControl
	Resources  []*Resource `json:"resources"`
	NextCursor string      `json:"nextCursor,omitempty"`
}

func (*ListResourcesResult) ResultType added in v1.3.0

func (*ListResourcesResult) ResultType() string

type ListToolsParams

type ListToolsParams struct {
	Meta   RequestMeta `json:"_meta"`
	Cursor string      `json:"cursor,omitempty"`
}

type ListToolsResult

type ListToolsResult struct {
	WithMeta
	CacheControl
	Tools      []*Tool `json:"tools"`
	NextCursor string  `json:"nextCursor,omitempty"`
}

func (*ListToolsResult) ResultType added in v1.3.0

func (*ListToolsResult) ResultType() string

type ListenParams added in v1.3.0

type ListenParams struct {
	Meta          RequestMeta        `json:"_meta"`
	Notifications SubscriptionFilter `json:"notifications"`
}

type ListenResult added in v1.3.0

type ListenResult struct {
	WithMeta
}

ListenResult is the empty "complete" result a server sends to gracefully end a subscription stream. Its _meta must carry the subscription ID.

func (*ListenResult) ResultType added in v1.3.0

func (*ListenResult) ResultType() string

type Message added in v1.3.0

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      RequestID       `json:"id,omitzero"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Message is the JSON-RPC 2.0 envelope shared by requests, notifications, responses and error responses.

func NewErrorResponse added in v1.3.0

func NewErrorResponse(id RequestID, e *Error) *Message

func NewNotification added in v1.3.0

func NewNotification(method string, params any) (*Message, error)

func NewRequest added in v1.3.0

func NewRequest(id RequestID, method string, params any) (*Message, error)

func NewResponse added in v1.3.0

func NewResponse(id RequestID, r Result) (*Message, error)

func (*Message) Kind added in v1.3.0

func (m *Message) Kind() Kind

type MetaCarrier added in v1.3.0

type MetaCarrier interface {
	ResultMetaRef() *ResultMeta
}

MetaCarrier is satisfied by every result struct (via WithMeta).

type MissingCapabilityData added in v1.3.0

type MissingCapabilityData struct {
	RequiredCapabilities ClientCapabilities `json:"requiredCapabilities"`
}

MissingCapabilityData is the data payload of a MissingRequiredClientCapability error.

type NotificationMeta added in v1.3.0

type NotificationMeta struct {
	SubscriptionID RequestID
	Extra          map[string]json.RawMessage
}

NotificationMeta is the typed view of a notification's params._meta. Notifications delivered on a subscriptions/listen stream must carry the subscription ID.

func (NotificationMeta) IsZero added in v1.3.0

func (m NotificationMeta) IsZero() bool

func (NotificationMeta) MarshalJSON added in v1.3.0

func (m NotificationMeta) MarshalJSON() ([]byte, error)

func (*NotificationMeta) UnmarshalJSON added in v1.3.0

func (m *NotificationMeta) UnmarshalJSON(b []byte) error

type ProgressParams added in v1.3.0

type ProgressParams struct {
	Meta          NotificationMeta `json:"_meta,omitzero"`
	ProgressToken ProgressToken    `json:"progressToken"`
	Progress      float64          `json:"progress"`
	Total         float64          `json:"total,omitempty"`
	Message       string           `json:"message,omitempty"`
}

ProgressParams is the payload of notifications/progress. Progress notifications flow only on the response stream of the request that supplied the progressToken, never on a subscriptions/listen stream.

type ProgressToken added in v1.3.0

type ProgressToken = RequestID

ProgressToken shares the identifier shape of RequestID: string or integer.

type Prompt

type Prompt struct {
	Name        string                     `json:"name"`
	Title       string                     `json:"title,omitempty"`
	Description string                     `json:"description,omitempty"`
	Arguments   []PromptArgument           `json:"arguments,omitempty"`
	Icons       []Icon                     `json:"icons,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

type PromptArgument

type PromptArgument struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

type PromptMessage

type PromptMessage struct {
	Role    Role    `json:"role"`
	Content Content `json:"content"`
}

func NewPromptMessage

func NewPromptMessage(role Role, content Content) PromptMessage

func (*PromptMessage) UnmarshalJSON

func (m *PromptMessage) UnmarshalJSON(b []byte) error

type PromptResponse added in v1.3.0

type PromptResponse interface {
	Result
	// contains filtered or unexported methods
}

PromptResponse is the closed sum returned by prompt handlers: *GetPromptResult | *InputRequired.

type PromptsCapability

type PromptsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type ReadResourceParams

type ReadResourceParams struct {
	Meta RequestMeta `json:"_meta"`
	URI  string      `json:"uri"`
	// InputResponses and RequestState are set only on an MRTR retry.
	InputResponses InputResponses `json:"inputResponses,omitempty"`
	RequestState   string         `json:"requestState,omitempty"`
}

type ReadResourceResult

type ReadResourceResult struct {
	WithMeta
	CacheControl
	Contents []ResourceContents `json:"contents"`
}

func NewReadResourceResult

func NewReadResourceResult(contents ...ResourceContents) *ReadResourceResult

func (*ReadResourceResult) ResultType added in v1.3.0

func (*ReadResourceResult) ResultType() string

type RequestID added in v1.3.0

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

RequestID is a JSON-RPC request identifier: a string or an integer. The zero value means "absent" (notifications, error responses without id). It is comparable and usable as a map key.

func IntID added in v1.3.0

func IntID(i int64) RequestID

func StringID added in v1.3.0

func StringID(s string) RequestID

func (RequestID) IsZero added in v1.3.0

func (id RequestID) IsZero() bool

func (RequestID) MarshalJSON added in v1.3.0

func (id RequestID) MarshalJSON() ([]byte, error)

func (RequestID) String added in v1.3.0

func (id RequestID) String() string

func (*RequestID) UnmarshalJSON added in v1.3.0

func (id *RequestID) UnmarshalJSON(b []byte) error

type RequestMeta added in v1.3.0

type RequestMeta struct {
	ProgressToken      ProgressToken
	ProtocolVersion    string
	ClientInfo         *Implementation
	ClientCapabilities ClientCapabilities

	// Extra holds non-reserved keys (traceparent, tracestate, baggage,
	// vendor keys, ...) and round-trips them verbatim.
	Extra map[string]json.RawMessage
	// contains filtered or unexported fields
}

RequestMeta is the typed view of params._meta on every request. The protocol version and client capabilities are required on the wire; the stateless server reads all per-request context from here.

func (RequestMeta) IsZero added in v1.3.0

func (m RequestMeta) IsZero() bool

func (RequestMeta) MarshalJSON added in v1.3.0

func (m RequestMeta) MarshalJSON() ([]byte, error)

func (*RequestMeta) UnmarshalJSON added in v1.3.0

func (m *RequestMeta) UnmarshalJSON(b []byte) error

func (*RequestMeta) Validate added in v1.3.0

func (m *RequestMeta) Validate() *Error

Validate enforces the required _meta fields. A request missing any of them is malformed and must be rejected with -32602 (HTTP 400).

type Resource

type Resource struct {
	URI         string                     `json:"uri"`
	Name        string                     `json:"name"`
	Title       string                     `json:"title,omitempty"`
	Description string                     `json:"description,omitempty"`
	MimeType    string                     `json:"mimeType,omitempty"`
	Size        int64                      `json:"size,omitempty"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Icons       []Icon                     `json:"icons,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

type ResourceContents

type ResourceContents struct {
	URI      string                     `json:"uri"`
	MimeType string                     `json:"mimeType,omitempty"`
	Text     string                     `json:"text,omitempty"`
	Blob     string                     `json:"blob,omitempty"`
	Meta     map[string]json.RawMessage `json:"_meta,omitempty"`
}

ResourceContents is one content item of a resources/read result: text or base64 blob.

func NewBlobResourceContents

func NewBlobResourceContents(uri, mimeType, blob string) ResourceContents

func NewTextResourceContents

func NewTextResourceContents(uri, text string) ResourceContents
type ResourceLink struct {
	URI string `json:"uri"`
	// Name is required per BaseMetadata (no omitempty, matching Resource).
	Name        string                     `json:"name"`
	Title       string                     `json:"title,omitempty"`
	Description string                     `json:"description,omitempty"`
	MimeType    string                     `json:"mimeType,omitempty"`
	Size        int64                      `json:"size,omitempty"`
	Icons       []Icon                     `json:"icons,omitempty"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}
func NewResourceLink(uri, name string) ResourceLink

func (ResourceLink) MarshalJSON added in v1.3.0

func (c ResourceLink) MarshalJSON() ([]byte, error)

type ResourceResponse added in v1.3.0

type ResourceResponse interface {
	Result
	// contains filtered or unexported methods
}

ResourceResponse is the closed sum returned by resource handlers: *ReadResourceResult | *InputRequired.

type ResourceTemplate

type ResourceTemplate struct {
	URITemplate string                     `json:"uriTemplate"`
	Name        string                     `json:"name"`
	Title       string                     `json:"title,omitempty"`
	Description string                     `json:"description,omitempty"`
	MimeType    string                     `json:"mimeType,omitempty"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Icons       []Icon                     `json:"icons,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

type ResourceUpdatedParams added in v1.2.0

type ResourceUpdatedParams struct {
	Meta NotificationMeta `json:"_meta,omitzero"`
	URI  string           `json:"uri"`
}

ResourceUpdatedParams is the payload of notifications/resources/updated, delivered on subscriptions/listen streams for subscribed URIs.

type ResourcesCapability

type ResourcesCapability struct {
	Subscribe   bool `json:"subscribe,omitempty"`
	ListChanged bool `json:"listChanged,omitempty"`
}

type Result added in v1.3.0

type Result interface {
	ResultType() string
}

Result is implemented by every result body. ResultType returns the wire discriminator: "complete", "input_required", or an extension-defined value (e.g. "task"). The field itself is injected by MarshalResult; result structs must not declare their own resultType field.

type ResultMeta added in v1.3.0

type ResultMeta struct {
	ServerInfo     *Implementation
	SubscriptionID RequestID
	Extra          map[string]json.RawMessage
}

ResultMeta is the typed view of result._meta.

func (ResultMeta) IsZero added in v1.3.0

func (m ResultMeta) IsZero() bool

func (ResultMeta) MarshalJSON added in v1.3.0

func (m ResultMeta) MarshalJSON() ([]byte, error)

func (*ResultMeta) UnmarshalJSON added in v1.3.0

func (m *ResultMeta) UnmarshalJSON(b []byte) error

type Role

type Role string
const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
)

type ServerCapabilities

type ServerCapabilities struct {
	Completions  *struct{}                  `json:"completions,omitempty"`
	Prompts      *PromptsCapability         `json:"prompts,omitempty"`
	Resources    *ResourcesCapability       `json:"resources,omitempty"`
	Tools        *ToolsCapability           `json:"tools,omitempty"`
	Extensions   map[string]json.RawMessage `json:"extensions,omitempty"`
	Experimental map[string]json.RawMessage `json:"experimental,omitempty"`
}

ServerCapabilities is advertised via server/discover. Servers derive it from what is actually registered; it is never hand-negotiated.

type SubscriptionFilter added in v1.3.0

type SubscriptionFilter struct {
	ToolsListChanged      bool
	PromptsListChanged    bool
	ResourcesListChanged  bool
	ResourceSubscriptions []string
	Extra                 map[string]json.RawMessage
}

SubscriptionFilter selects which notification types a subscriptions/listen stream carries. Omitted fields mean "not subscribed"; the server must not send types the client did not request. Extra carries extension filter fields (e.g. the tasks extension's taskIds).

func (SubscriptionFilter) IsZero added in v1.3.0

func (f SubscriptionFilter) IsZero() bool

func (SubscriptionFilter) MarshalJSON added in v1.3.0

func (f SubscriptionFilter) MarshalJSON() ([]byte, error)

func (*SubscriptionFilter) UnmarshalJSON added in v1.3.0

func (f *SubscriptionFilter) UnmarshalJSON(b []byte) error

type TextContent

type TextContent struct {
	Text        string                     `json:"text"`
	Annotations *Annotations               `json:"annotations,omitempty"`
	Meta        map[string]json.RawMessage `json:"_meta,omitempty"`
}

func NewTextContent

func NewTextContent(text string) TextContent

func (TextContent) MarshalJSON added in v1.3.0

func (c TextContent) MarshalJSON() ([]byte, error)

type Tool

type Tool struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	// InputSchema must be an object schema at the root.
	InputSchema JSONSchema `json:"inputSchema"`
	// OutputSchema has no root type constraint (SEP-2106).
	OutputSchema JSONSchema                 `json:"outputSchema,omitempty"`
	Annotations  *ToolAnnotations           `json:"annotations,omitempty"`
	Icons        []Icon                     `json:"icons,omitempty"`
	Meta         map[string]json.RawMessage `json:"_meta,omitempty"`
}

type ToolAnnotations added in v1.3.0

type ToolAnnotations struct {
	Title           string `json:"title,omitempty"`
	ReadOnlyHint    *bool  `json:"readOnlyHint,omitempty"`
	DestructiveHint *bool  `json:"destructiveHint,omitempty"`
	IdempotentHint  *bool  `json:"idempotentHint,omitempty"`
	OpenWorldHint   *bool  `json:"openWorldHint,omitempty"`
}

ToolAnnotations are untrusted hints. Pointers distinguish "false" from "unset".

type ToolResponse added in v1.3.0

type ToolResponse interface {
	Result
	// contains filtered or unexported methods
}

ToolResponse is the closed sum returned by tool handlers: *CallToolResult | *InputRequired.

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type UnknownContent added in v1.3.0

type UnknownContent struct {
	Type string
	Raw  json.RawMessage
}

UnknownContent preserves a content block whose type this SDK does not recognize. It round-trips byte-for-byte instead of silently corrupting.

func (UnknownContent) MarshalJSON added in v1.3.0

func (c UnknownContent) MarshalJSON() ([]byte, error)

type UnsupportedVersionData added in v1.3.0

type UnsupportedVersionData struct {
	Supported []string `json:"supported"`
	Requested string   `json:"requested"`
}

UnsupportedVersionData is the data payload of an UnsupportedProtocolVersion error.

type WithMeta added in v1.3.0

type WithMeta struct {
	Meta ResultMeta `json:"_meta,omitzero"`
}

WithMeta is embedded by every result struct to carry result._meta and to give the server a uniform seam for stamping serverInfo.

func (*WithMeta) ResultMetaRef added in v1.3.0

func (w *WithMeta) ResultMetaRef() *ResultMeta

ResultMetaRef exposes the embedded meta for central stamping.

Jump to

Keyboard shortcuts

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