Source File
result.go
Belonging Package
github.com/mark3labs/mcp-go/mcp
package mcp// ResultType indicates how a client should interpret a result, as introduced// by protocol version 2026-07-28 (SEP-2322).type ResultType stringconst (// ResultTypeComplete indicates an ordinary, final result.//// Clients MUST treat a result from an earlier-protocol server that omits// the resultType field as complete.ResultTypeComplete ResultType = "complete"// ResultTypeInputRequired indicates the server needs additional input from// the client before it can finish the request. The client fulfils the// [InputRequiredResult.InputRequests] and retries the original request with// the answers attached. See the multi round-trip request pattern.ResultTypeInputRequired ResultType = "input_required")// IsComplete reports whether the result type denotes a final result. An empty// result type is treated as complete for backwards compatibility with servers// implementing protocol versions earlier than 2026-07-28.func ( ResultType) () bool {return == "" || == ResultTypeComplete}// CacheScope indicates the intended scope of a cached response, analogous to// the HTTP Cache-Control public and private directives (SEP-2549).type CacheScope stringconst (// CacheScopePublic indicates the response contains no user-specific data,// so any client or shared intermediary may cache and reuse it across// authorization contexts.CacheScopePublic CacheScope = "public"// CacheScopePrivate indicates the response may only be cached and reused// within the same authorization context.CacheScopePrivate CacheScope = "private")// CacheableResult carries the caching hints required on results from// tools/list, prompts/list, resources/list, resources/templates/list,// resources/read, and server/discover in protocol version 2026-07-28 and later// (SEP-2549).//// Both fields are omitted when responding to a request that used an earlier// protocol version.type CacheableResult struct {Result// TTLMs is a hint indicating how long, in milliseconds, the client may// cache this response before re-fetching. Semantics are analogous to HTTP// Cache-Control max-age. Zero means the response should be considered// immediately stale.//// It is a pointer so that an explicit zero can be distinguished from an// unset value; use [CacheableResult.SetCacheHints] to populate it.TTLMs *int64 `json:"ttlMs,omitempty"`// CacheScope controls whether shared intermediaries may cache the// response.CacheScope CacheScope `json:"cacheScope,omitempty"`}// SetCacheHints populates the caching hints on the result.//// An empty scope defaults to [CacheScopePrivate], so a result is never shared// across authorization contexts unless the caller asks for it: list and read// results are frequently scoped to the caller's identity, and a shared// intermediary honouring a public scope would serve one principal's data to// another. A nil receiver is a no-op.func ( *CacheableResult) ( int64, CacheScope) {if == nil {return}if == "" {= CacheScopePrivate}.TTLMs = &.CacheScope =}// TTL returns the cache freshness hint in milliseconds and whether the server// supplied one.func ( *CacheableResult) () (int64, bool) {if == nil || .TTLMs == nil {return 0, false}return *.TTLMs, true}// ResultMetadata is implemented by every MCP result type through its embedded// [Result]. It allows transports and servers to decorate a result generically,// without knowing its concrete type.type ResultMetadata interface {// SetResultType records how the client should interpret the result.SetResultType(ResultType)// GetResultType returns the recorded result type.GetResultType() ResultType// SetResultMeta replaces the result's _meta.SetResultMeta(*Meta)// GetResultMeta returns the result's _meta, which may be nil.GetResultMeta() *Meta// EnsureResultMeta returns the result's _meta, allocating it when absent.EnsureResultMeta() *Meta}// SetResultType records how the client should interpret the result.func ( *Result) ( ResultType) {if == nil {return}.ResultType =}// GetResultType returns the recorded result type.func ( *Result) () ResultType {if == nil {return ""}return .ResultType}// SetResultMeta replaces the result's _meta.func ( *Result) ( *Meta) {if == nil {return}.Meta =}// GetResultMeta returns the result's _meta, which may be nil.func ( *Result) () *Meta {if == nil {return nil}return .Meta}// EnsureResultMeta returns the result's _meta, allocating it when absent.func ( *Result) () *Meta {if == nil {return nil}if .Meta == nil {.Meta = &Meta{}}return .Meta}// CacheHintSetter is implemented by result types that carry the SEP-2549// caching hints through an embedded [CacheableResult].type CacheHintSetter interface {SetCacheHints(ttlMs int64, scope CacheScope)}// Compile-time checks that the base result types satisfy the decoration// interfaces, and therefore so does every type embedding them.var (_ ResultMetadata = (*Result)(nil)_ ResultMetadata = (*CacheableResult)(nil)_ CacheHintSetter = (*CacheableResult)(nil))
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |