Resource

session

MCP session resource for request-scoped context storage

resource session;

F id

id: func() -> string;

Get the session ID.

F is-active

is-active: func() -> result​<bool, session-error>;

Check if the session is still active. Returns false if the session has been terminated.

F get

get: func(key: string) -> result​<option​<list​<u8>>, session-error>;

Get a persistent session context value by key.

F set

set: func(key: string, value: list​<u8>) -> result​<_, session-error>;

Set a persistent session context value by key.

F attach

attach: func(ctx: borrow​<message-context>);

Attach this session to an MCP request context. This allows downstream handlers to retrieve the session.

F elicit

elicit: func(out: borrow​<output-stream>, elicitation: elicit-request) -> result​<elicit-result, stream-error>;

Elicit information from the client. Blocks until the elicitation is complete.

https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation

F terminate

terminate: func(reason: option​<string>) -> result​<_, session-error>;

Terminate the session, optionally providing a reason. is-active will return false after termination.

Data associated with the terminated session is NOT deleted. Use delete() to remove all session data.

Subsequent calls will have no effect.

F initialize

initialize: func() -> result​<session, session-error>;

Create a new session with a globally unique and cryptographically secure ID. The session is initially empty and can be populated with persistent context values.

F delete

delete: func(this: session) -> result​<_, session-error>;

Deletes all data associated with the session. After deleting, the session is invalid and cannot be used.