MCP Server with Durable History
An MCP server that provides a chat tool with stateless instances and external session state, enabling durable conversation history and concurrent client handling.
README
MCP server — stateless instances, external session state, durable history
Run it
npm install
npm run dev # starts the server on :3000
npm run simulate # in another terminal: runs the traffic simulation
Files
src/session-store.ts— the "hot" tier. Stands in for Redis: active session state, TTL-expired. Swap the internals forioredislater; the interface (get/create/update) doesn't change.src/history-store.ts— the "durable" tier. Stands in for Postgres: append-only conversation log, idempotency-key guarded so client retries under load never duplicate a turn.src/mcp-instance.ts— the actual MCP server: registers achattool that resolvessession_id→ cache-or-rebuild-from-history → append turn → reply → update session.src/server.ts— Express + Streamable HTTP transport. Note the comment block distinguishing MCP protocol session (transport handshake, kept in an in-memoryMap, dies with the process) from application conversation session (your data, lives in the stores above, survives a restart/rescale).src/simulate-traffic.ts— a real MCP client (not curl) that (a) runs one user through several turns on the same session to prove continuity, and (b) fires 25 concurrent new conversations to prove the server handles concurrent load without cross-talk.
What's simulated vs. real here
Real: the MCP protocol handshake, tool registration/invocation, the client↔server wire format, concurrency handling.
Simulated (by design, so you can run this with zero external infra):
SessionStore/HistoryStore are in-memory. To go to production:
- Replace
Mapinsession-store.tswith anioredisclient — same method signatures. - Replace the array in
history-store.tswithpg(or Drizzle/Prisma) queries against aturnstable — same method signatures. - Run multiple instances of
server.tsbehind a load balancer. Because step 4 in the design notes still applies — the MCP protocol session (theMapinserver.ts) is per-process — route byMcp-Session-Idwith sticky sessions, OR terminate the client connection per-request (stateless mode) if your client library supports it. The application conversation state (step 1–2) has no such constraint; it's already externalized and safe to hit from any instance. - Add a queue in front for burst absorption once traffic exceeds what autoscaling can react to in time (see architecture diagram earlier in the conversation).
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.