MCP Server Framework - v1.0.0
    Preparing search index...

    Class McpSession

    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.

    const session = new McpSession({
    name: 'my-server',
    version: '1.0.0',
    capabilities: { tools: {} },
    });

    // Access underlying SDK server for transport connection
    await session.sdk.connect(transport);

    Implements

    Index

    Constructors

    • 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().

      Parameters

      Returns McpSession

    Properties

    options: Readonly<McpSessionOptions>

    Session options

    sdk: McpServer

    The underlying MCP SDK server instance

    Accessors

    Methods

    • 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:

      • SessionManager (stateful sessions — on close/closeAll)
      • StreamableHttpTransport (stateless sessions — on response close)

      Safe to call multiple times — sdk.close() is idempotent.

      Returns Promise<void>

    • 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.

      Parameters

      • onSetLevel: (level: McpLogLevel) => void

        Callback to apply the requested level (typically mcpLogger.setMinLevel)

      Returns void

    • Registers request handlers for resources/subscribe and resources/unsubscribe.

      Returns void

      — 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.

    • Sends a notifications/resources/updated notification to this session's client if the session has subscribed to the given URI.

      Parameters

      • uri: string

        The resource URI that was updated

      Returns Promise<void>