ISessionStore Interface
All session stores implement theISessionStore interface:
SessionData
DynamoDBSessionStore
DynamoDB-backed session store for production Lambda deployments.Constructor
Example
DynamoDB Table Schema
The DynamoDB table must have the following schema: Primary Key:sessionId(String) - Partition key
createdAt(String) - ISO timestampupdatedAt(String) - ISO timestampttl(Number) - Unix timestamp for TTLdata(Map) - Custom session data
- Enable TTL on the
ttlattribute
Creating the Table
Using AWS CLI
Using CloudFormation
Constants
Methods
sessionExists()
Check if a session exists in DynamoDB.createSession()
Create a new session in DynamoDB.getSession()
Get session data from DynamoDB.updateSession()
Update session data and refresh TTL.deleteSession()
Delete a session from DynamoDB.InMemorySessionStore
In-memory session store for local development and testing.Constructor
Example
Methods
sessionExists()
createSession()
getSession()
updateSession()
deleteSession()
clear()
Clear all sessions (useful for testing).size
Get the number of sessions.Limitations
- Sessions are lost on server restart
- Not suitable for production or multi-instance deployments
- No TTL support (sessions persist until manually deleted or cleared)
Auto-Configuration
When running on LeanMCP Lambda (LEANMCP_LAMBDA=true env var), the server automatically configures a DynamoDB session store in stateful mode:
Usage Patterns
Local Development
UseInMemorySessionStore for fast local development:
Production (Lambda)
UseDynamoDBSessionStore with TTL for production:
Conditional Store Selection
Custom Session Store
Implement theISessionStore interface for custom backends (Redis, PostgreSQL, etc.):
Related
- createHTTPServer - HTTP server with session support
- MCPServer - Core server class