stateless-mcp-starter
An Express + TypeScript starter for building stateless MCP servers with explicit, typed application state, featuring a shopping-cart domain example and support for multiple state store adapters.
README
Stateless MCP Starter
An Express + TypeScript starter for building stateless MCP servers with explicit, typed application state.
This repo demonstrates a simple production-oriented pattern:
- Keep MCP protocol handling stateless.
- Store application state behind a
StateStore<TState>. - Return opaque handles like
cart_...,booking_..., ordraft_...from tools. - Require later tool calls to pass those handles back as normal arguments.
The included shopping-cart tools are just an example domain. The important idea is not ecommerce; it is the explicit state-handle pattern. The same shape works for bookings, support tickets, onboarding flows, insurance quotes, approvals, drafts, and other multi-turn workflows.
Why This Exists
Remote MCP servers should be easy to scale horizontally. A later request should not need to find the same process, protocol session, or in-memory object that handled the first request.
Instead, the model receives an application handle from one tool call:
{
"cart_id": "cart_abc123"
}
Then it passes that handle into the next tool call:
{
"cart_id": "cart_abc123",
"sku": "ceramic-mug",
"quantity": 2
}
Any server instance can handle either request because the state lives in the configured StateStore, not in MCP protocol/session state.
Quickstart
Generate a new project:
pnpm dlx create-stateless-mcp my-server
cd my-server
pnpm install
pnpm dev
The server starts on http://127.0.0.1:3000 by default.
curl http://127.0.0.1:3000/health
Expected response:
{
"status": "ok",
"service": "stateless-mcp-starter"
}
You can also run this checkout directly:
pnpm install
pnpm dev
Generator
This package provides a create-stateless-mcp CLI:
pnpm dlx create-stateless-mcp my-server
For local development from this repo:
node bin/create-stateless-mcp.js my-server --yes
Options:
node bin/create-stateless-mcp.js my-server \
--state-adapter memory \
--auth-mode dev \
--example-domain shopping-cart \
--yes
Supported choices:
--state-adapter memory|dynamodb|postgres--auth-mode dev|bearer--example-domain shopping-cart|minimal
Use shopping-cart when you want a concrete working example. Use minimal when you want the MCP server scaffold without example domain code.
Included MCP Tools
The shopping-cart example exposes these tools over /mcp:
list_products: returns available product SKUs.create_cart: creates a cart and returnscart_id.add_cart_item: adds an item usingcart_id,sku, andquantity.get_cart: fetches the cart usingcart_id.
The tool names and cart types are intentionally replaceable. They exist to make the handle flow obvious.
State Model
StateStore<TState> is the application state boundary. Records include:
- handle
- type
- tenant/user scope
- status
- version
- timestamps
- TTL
- typed value
Handles are opaque identifiers, not authorization. Every state read or write also receives tenant/user scope.
Included adapters:
InMemoryStateStorefor local development and tests.DynamoStateStorefor shared production-style state.PostgresStateStorefor shared production-style state in Postgres.
Memory mode is zero setup:
STATE_ADAPTER=memory
DynamoDB mode:
STATE_ADAPTER=dynamodb
DYNAMODB_TABLE_NAME=stateless-mcp-state
AWS_REGION=us-east-1
Postgres mode:
STATE_ADAPTER=postgres
POSTGRES_CONNECTION_STRING=postgres://postgres:postgres@127.0.0.1:5432/stateless_mcp
POSTGRES_TABLE_NAME=mcp_state
See docs/adapters.md for adapter details and the Postgres schema.
Auth And Context
Local development defaults to permissive dev auth:
AUTH_MODE=dev
Production should use the bearer-token stub or replace it with your own auth layer:
NODE_ENV=production
AUTH_MODE=bearer
AUTH_BEARER_TOKEN=replace-with-a-real-secret
Every MCP request gets a typed context with requestId, tenantId, userId, and scopes. In dev mode, x-tenant-id, x-user-id, and x-user-scopes headers are optional. In bearer mode, tenant/user headers are required and state operations remain scoped by both values.
MCP SDK Compatibility
This starter uses the production-ready v1 @modelcontextprotocol/sdk package and Streamable HTTP transport. The HTTP transport is configured without server-side session IDs, so application continuity comes from explicit handles and the configured StateStore.
Protocol-specific wiring is isolated in src/http/app.ts and src/mcp/createServer.ts, so future SDK changes should not require rewriting your state model, tools, or auth boundary.
Project Structure
src/
auth/ request auth and typed request context
cart/ example shopping-cart domain
http/ Express app, /health, and /mcp route
mcp/ MCP server and tool registration
state/ StateStore interface and adapters
test/ focused unit and flow tests
docs/ deployment, adapters, and explicit-handle notes
bin/ create-stateless-mcp generator
Scripts
pnpm dev
pnpm test
pnpm build
What This Is
- A starter for stateless remote MCP servers.
- A concrete example of explicit multi-turn application state.
- A TypeScript/Express scaffold with tests, Docker support, and a generator.
- A place to swap in your own domain tools and state types.
What This Is Not
- A complete auth solution.
- A hosted deployment platform.
- A framework that hides MCP concepts from you.
- An ecommerce product. The cart domain is only an example.
Deployment
See docs/deployment.md for Docker, required environment variables, and no-sticky-session guidance.
Future Milestones
- Redis
StateStoreadapter. - JWT auth hardening.
- More deployment examples.
- More generated templates.
Release
This project is prepared for npm publishing as create-stateless-mcp, but no publish or release action should happen without explicit approval. See RELEASE_CHECKLIST.md.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。