ReadonlyabortAbortSignal that triggers when the request is cancelled.
MCP Protocol: Triggered when client sends notifications/cancelled
with a matching requestId. This is the SDK's native AbortSignal,
created per-request and managed by the MCP protocol layer.
Tools SHOULD check this signal periodically during long-running operations and abort gracefully when triggered.
Optional ReadonlyauthAuthentication context for the current request.
Available when auth middleware is configured on the server.
Contains the verified token info (authInfo) and optional
consumer-provided data (extra) from the onAuthenticated hook.
undefined when no auth is configured (anonymous access).
ReadonlyauthInfo: AuthInfoVerified auth info from the Bearer token
Optional Readonlyextra?: Record<string, unknown>Consumer-provided extra data from onAuthenticated hook
Optional ReadonlycreateRequest LLM sampling from the client.
MCP Protocol: Sends a sampling/createMessage request to the client,
which returns an LLM-generated response. This enables server-initiated
LLM interactions (e.g., asking the LLM to summarize data for the user).
Availability: Only present when the client declares sampling capability
AND the session is stateful. In stateless mode or when the client doesn't
support sampling, this will be undefined.
Sampling request parameters (messages, model preferences, etc.)
The LLM's response with model info and stop reason
Optional ReadonlyelicitRequest user input via the client's elicitation UI.
MCP Protocol: Sends an elicitation/create request to the client,
which presents a form or URL to the user and returns their input.
Availability: Only present when the client declares elicitation capability
AND the session is stateful. In stateless mode or when the client doesn't
support elicitation, this will be undefined.
Elicitation parameters (form schema or URL)
User's response (accept/decline/cancel with optional content)
if (context.elicitInput) {
const result = await context.elicitInput({
message: 'Please confirm the deployment target',
requestedSchema: {
type: 'object',
properties: {
confirmed: { type: 'boolean', title: 'Confirm deployment' },
},
},
});
if (result.action === 'accept') {
// result.content contains the form values
}
}
Optional ReadonlylistList the client's root URIs.
MCP Protocol: Sends a roots/list request to the client, which returns
the set of root URIs (workspace folders, project roots, etc.) the client
has made available to the server.
Availability: Only present when the client declares roots capability
AND the session is stateful. In stateless mode or when the client doesn't
support roots, this will be undefined.
Array of root objects with URI and optional name
Optional ReadonlyreportReports progress for long-running operations.
MCP Protocol: Sends notifications/progress to the client.
Only available if the MCP client requested progress tracking by
including _meta.progressToken in the tools/call request.
If not requested, this will be undefined.
The framework applies rate-limiting (100ms minimum interval) to prevent flooding the client with notifications.
ReadonlyrequestThe JSON-RPC request ID for this tool call.
Useful for logging, tracing, and correlating requests. This is the real protocol-level request ID from the MCP client.
Optional ReadonlysessionThe session ID from the transport, if available.
Identifies which MCP client session invoked this tool. Available in HTTP transport mode (Streamable HTTP, SSE), not in stdio.
ReadonlystatelessWhether this tool is executing in stateless mode.
In stateless mode, the server creates a fresh session per request — no persistent state is maintained between calls.
Per-request features (work normally in stateless):
Cross-request features (unavailable in stateless by design):
notifications/cancelled) — needs routing to original sessionsampling/createMessage) — server→client requires persistent channelelicitation/create) — server→client requires persistent channelroots/list) — server→client requires persistent channelTools MAY use this flag to adapt behavior for cross-request limitations, e.g., avoiding operations that rely on server-initiated client requests.
Context passed to tool handlers during execution.
Provides MCP-compliant mechanisms for:
All features are sourced from the SDK's
RequestHandlerExtraand mapped to this clean interface by the framework. Cancellation uses the SDK's native AbortSignal (per-request, automatically aborted onnotifications/cancelled).Example