Creates a new McpSession instance.
Cancellation is handled natively by the SDK's Protocol layer (per-request AbortController, keyed by real JSON-RPC request ID). Progress reporting uses the SDK's extra.sendNotification with rate-limiting applied by createProgressReporter().
Session configuration options
ReadonlyoptionsSession options
ReadonlysdkThe underlying MCP SDK server instance
Server name
Server version
Clean up session resources.
Closes the underlying SDK McpServer, releasing protocol-level resources
(pending requests, open streams, registered handlers). This is the
counterpart to sdk.connect(transport) — every connected session
should be disposed when no longer needed.
Called by:
Safe to call multiple times — sdk.close() is idempotent.
Registers all prompts with the MCP SDK server. Delegates to PromptRegistry.bindToSdk().
Registers all resources (static + templates) with the MCP SDK server. Delegates to ResourceRegistry.bindToSdk().
Overrides tools/list, resources/list, resources/templates/list, and prompts/list
handlers to filter out entries whose requiredScopes are not satisfied by the
requesting user's token scopes.
This wraps the SDK's original handlers — the full list is constructed by the SDK, then filtered before being returned to the client.
Call this AFTER all tools/resources/prompts have been registered via registerTools() etc.
All registered definitions (used to build scope lookup maps)
Registers a request handler for logging/setLevel.
Per MCP Spec: When the server declares logging: {} capability, clients
can send logging/setLevel to control which log notifications they receive.
The handler updates the McpNotificationLogger's minimum level so that
only messages at or above the requested level are forwarded.
Callback to apply the requested level (typically mcpLogger.setMinLevel)
Registers request handlers for resources/subscribe and resources/unsubscribe.
— The SDK's high-level McpServer does not handle subscription
requests. This uses the low-level Server.setRequestHandler() API to register
handlers for the subscribe/unsubscribe JSON-RPC methods.
Subscription tracking is per-session (this McpSession instance).
When notifyResourceUpdated(uri) is called, only sessions that
subscribed to the given URI receive notifications/resources/updated.
In stateless mode, subscriptions are not meaningful (no persistent session), so this method should not be called for stateless sessions.
ExperimentalRegisters task tools with the MCP SDK's experimental tasks API. Delegates to TaskToolRegistry.bindToSdk().
MCP Tasks is an experimental SDK feature
Registers all tools with the MCP SDK server. Delegates to ToolRegistry.bindToSdk().
Sends a log notification to the connected MCP client. Implements LogNotificationHandler so this session can be registered directly with the MCP notification logger.
Sends a notifications/resources/updated notification to this session's client
if the session has subscribed to the given URI.
The resource URI that was updated
A managed MCP client session.
Each session wraps an SDK McpServer instance. Cancellation and progress are handled natively by the SDK — no additional tracking layer needed.
Example