Documentation
¶
Overview ¶
Package requeststate seals the requestState an MCP server returns in an InputRequiredResult and the client echoes back on its retry (MCP 2026-07-28, multi round-trip requests).
MCP treats an echoed requestState as attacker-controlled input: the server must protect its integrity and should bind it to the authenticated principal, a short expiry and the originating request. A server must also bind an elicitation to the client and user identity. A sealed value is encrypted and authenticated with AES-256-GCM under a security.KeyRing, and bound to:
- the user and OAuth client of the validated token: the Issuer, ID and ClientID of its providers.UserInfo, and its current actor (ActorIssuer, ActorSubject) when the token is delegated;
- the originating request, such as the method, the tool name and a digest of its arguments;
- an expiry.
Seal and Open refuse a user without a ClientID: a token that does not name one client, such as a forwarded ID token with several audiences and no azp, cannot be given state.
Open refuses a value that was changed, sealed for another user, client, actor or request, expired, or sealed with a key the ring does not hold. A value can be opened more than once until it expires; a server whose state must be consumed at most once records that itself.
Each server seals with its own key ring, and a value is only ever opened by the server that sealed it.
Index ¶
Constants ¶
const ( // MaxSealedLength bounds what Open decodes, so a client cannot make the // server decode an arbitrarily large value. MaxSealedLength = 16 << 10 )
Variables ¶
var ( // ErrInvalid is a value that is malformed, was changed, or was sealed // for another user, client, actor or request or with a key the ring // does not hold. ErrInvalid = errors.New("requeststate: invalid state") // ErrExpired is an authentic value past its expiry. ErrExpired = errors.New("requeststate: expired state") )
Functions ¶
This section is empty.
Types ¶
type Sealer ¶
type Sealer struct {
// contains filtered or unexported fields
}
Sealer seals with its ring's active key and opens with any key the ring resolves.
func (*Sealer) Open ¶
Open returns the payload of a value Seal returned for the same user and request. It answers ErrInvalid or ErrExpired otherwise.
func (*Sealer) Seal ¶
func (s *Sealer) Seal(user *providers.UserInfo, request string, payload []byte, ttl time.Duration) (string, error)
Seal returns payload sealed for user and request, valid for ttl. user is the validated caller; request identifies the originating request. Open must be given the same user and request.