Skip to content

Deployment Patterns

mcp-lite is designed to grow with your needs. Start simple and add complexity only when required.

Run the transport with no adapters. Every request is stateless and there is nothing to clean up.

const transport = new StreamableHttpTransport()

Use when:

  • Building and testing locally
  • Tools don’t need state between requests
  • Quick prototypes and experiments

Add InMemorySessionAdapter (and optionally InMemoryClientRequestAdapter) so progress notifications and elicitations can span multiple requests from the same client.

const transport = new StreamableHttpTransport({
sessionAdapter: new InMemorySessionAdapter({
maxEventBufferSize: 1024
}),
clientRequestAdapter: new InMemoryClientRequestAdapter({
defaultTimeoutMs: 30000
})
})

Use when:

  • Running on a single server instance
  • Need sessions but don’t need distributed state
  • Development or staging environments

Implement the adapters against shared infrastructure (Redis, SQL, message queues, Durable Objects, etc.).

const transport = new StreamableHttpTransport({
sessionAdapter: new RedisSessionAdapter(redisClient),
clientRequestAdapter: new RedisClientRequestAdapter(redisClient)
})

Use when:

  • Multiple server instances
  • Serverless deployments (Cloudflare Workers, AWS Lambda)
  • Need session persistence across instances
EnvironmentSession StorageState StorageTransport Configuration
DevelopmentNoneN/AStreamableHttpTransport()
Single serverIn-memoryIn-memoryInMemorySessionAdapter
DistributedRedis/KVRedis/KVCustom adapters
ServerlessDurable Objects/KVDurable Objects/KVCustom adapters

For serverless deployments, use persistent storage:

import { McpServer, StreamableHttpTransport } from "mcp-lite"
import { KvSessionAdapter, KvClientRequestAdapter } from "./adapters"
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const server = new McpServer({
name: "worker-server",
version: "1.0.0"
})
// ... define tools
const transport = new StreamableHttpTransport({
sessionAdapter: new KvSessionAdapter(env.KV),
clientRequestAdapter: new KvClientRequestAdapter(env.KV)
})
return transport.bind(server)(request)
}
}

See examples/cloudflare-worker-kv for the complete KV adapter implementation.

Begin without adapters until you actually need sessions or elicitation.

Enable sessions when you need:

  • Progress notifications
  • SSE streaming
  • Event replay for reconnections

Only implement custom adapters when:

  • Running multiple instances
  • Deploying to serverless platforms
  • Need cross-instance session persistence
  • Track session count and memory usage
  • Set appropriate maxEventBufferSize
  • Implement session cleanup/expiry
  • Use timeouts for client requests