Skip to main content
Sessions group related events together. mcp-tap uses two strategies.

Automatic session detection

When init() is called, a SessionManager is created that tracks sessions via message fingerprinting. For LLM requests, it hashes the first user message content (SHA-256, first 12 hex chars). If the fingerprint changes between requests, a new session ID is generated.

Explicit sessions

import { session } from "mcp-tap";

const result = await session("checkout-flow", async () => {
  const a = await llm.create(...);
  const b = await llm.create(...);
  return b;
});
Sessions nest correctly — when an outer session is active, starting an inner session overrides it for the duration of the inner function, then restores the outer.If called with only a function (no name), a random session ID is generated:
const result = await session(async () => {
  // auto-generated session ID
});