npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tmcp/session-manager

v0.2.1

Published

Session management for TMCP (TypeScript Model Context Protocol) transport implementations. This package provides the base classes and in-memory implementations for both streaming session coordination and session metadata persistence.

Downloads

125,889

Readme

@tmcp/session-manager

Session management for TMCP (TypeScript Model Context Protocol) transport implementations. This package provides the base classes and in-memory implementations for both streaming session coordination and session metadata persistence.

Installation

pnpm add @tmcp/session-manager

Overview

Session management is split into two concerns:

  • Stream session managers handle the storage of long-lived streaming connections (SSE/HTTP) and the fan-out of notifications back to the right session.
  • Info session managers persist metadata that MCP transports need across requests, such as client capabilities, client info, requested log level, and resource subscriptions.

Together they manage:

  • Session Creation: Establishing new client sessions with stream controllers
  • Session Deletion: Cleaning up disconnected sessions and metadata
  • Session Queries: Checking whether a given session is still attached
  • Message Delivery: Sending messages to specific sessions or everyone
  • Client Metadata: Persisting capabilities, clientInfo, and log level between requests
  • Resource Subscriptions: Tracking which sessions subscribed to which URIs

Usage

In-Memory Session Managers (Default)

The package ships with InMemoryStreamSessionManager and InMemoryInfoSessionManager. Together they are suitable for single-server deployments or tests:

import {
	InMemoryStreamSessionManager,
	InMemoryInfoSessionManager,
} from '@tmcp/session-manager';

const sessionManagers = {
	streams: new InMemoryStreamSessionManager(),
	info: new InMemoryInfoSessionManager(),
};

Custom Session Managers

You can implement your own managers by extending the base classes that ship with this package.

Stream session manager

import { StreamSessionManager } from '@tmcp/session-manager';

class CustomStreamSessionManager extends StreamSessionManager {
	create(id, controller) {
		// Persist the ReadableStream controller for later notifications
	}

	delete(id) {
		// Clean up the controller and any associated timers
	}

	async has(id) {
		// Return whether a controller for the session exists
	}

	send(sessions, data) {
		// Fan out the payload to the targeted sessions (or everyone if sessions is undefined)
	}
}

Info session manager

import { InfoSessionManager } from '@tmcp/session-manager';

class CustomInfoSessionManager extends InfoSessionManager {
	async getClientInfo(id) {
		// Return the last clientInfo payload for the session
	}

	setClientInfo(id, info) {
		// Persist clientInfo for later requests
	}

	async getClientCapabilities(id) {
		// Retrieve cached client capabilities
	}

	setClientCapabilities(id, capabilities) {
		// Persist the negotiated capabilities
	}

	async getLogLevel(id) {
		// Return the log level requested by the client
	}

	setLogLevel(id, level) {
		// Store the latest log level
	}

	async getSubscriptions(uri) {
		// Return all session ids subscribed to the URI
	}

	addSubscription(id, uri) {
		// Track that the session subscribed to the URI
	}

	delete(id) {
		// Remove all metadata for the session (client info, capabilities, subscriptions, etc.)
	}
}

API

StreamSessionManager (Abstract Base Class)

Responsible for creating and managing streaming controllers.

  • create(id, controller) – register a session and associate its stream controller
  • delete(id) – remove the controller and clean up resources
  • has(id) – resolve to true when a controller for the session exists
  • send(sessions, data) – push a payload to selected sessions (or everyone when sessions is undefined)

InfoSessionManager (Abstract Base Class)

Stores session metadata that needs to survive across HTTP requests or reconnects.

  • getClientInfo(id) / setClientInfo(id, info)
  • getClientCapabilities(id) / setClientCapabilities(id, capabilities)
  • getLogLevel(id) / setLogLevel(id, level)
  • getSubscriptions(uri) – return all session IDs that subscribed to a resource
  • addSubscription(id, uri) – record a new resource subscription
  • delete(id) – remove all metadata for a session when it disconnects

InMemoryStreamSessionManager & InMemoryInfoSessionManager

Concrete in-memory implementations that cover both responsibilities. Combine them when configuring a transport:

import { HttpTransport } from '@tmcp/transport-http';
import { SseTransport } from '@tmcp/transport-sse';
import {
	InMemoryStreamSessionManager,
	InMemoryInfoSessionManager,
} from '@tmcp/session-manager';

const sessionManagers = {
	streams: new InMemoryStreamSessionManager(),
	info: new InMemoryInfoSessionManager(),
};

const httpTransport = new HttpTransport(server, { sessionManager: sessionManagers });
const sseTransport = new SseTransport(server, { sessionManager: sessionManagers });

Related Packages

License

MIT