MCP Hub
Back to servers

snapstate

Requires Setup

Persistent state for AI agent workflows. Save, resume, and replay multi-step workflows.

Registry
Stars
3
Updated
Apr 13, 2026
Validated
Apr 15, 2026

Quick Install

npx -y snapstate-sdk

SnapState

A production-ready checkpoint and state-persistence API that AI agents use to save and resume multi-step workflows. Agents write checkpoints at each step; if a workflow is interrupted, it resumes from the last saved state rather than restarting.

Phase 1 — Core API, Redis state store, JavaScript SDK
Phase 2 — MCP server, Cloudflare R2 cold storage, Postgres accounts + billing, admin dashboard
Phase 3 — Agent identity + analytics, Python SDK, public docs site, production hardening


Quick start

1. Start infrastructure

docker-compose up -d
# Starts Redis 7 (port 6379) + Postgres 16 (port 5432)

2. Install server dependencies

cd server && npm install

3. Configure environment

cp .env.example .env
# Edit .env — defaults work with Docker Compose for local dev

4. Run database migrations

npm run migrate
# Applies all migrations (001 through 007)

5. Create an admin account + API key

npm start &

curl -X POST https://snapstate.dev/admin/accounts \
  -H "Authorization: Bearer admin_dev_secret_change_me" \
  -H "Content-Type: application/json" \
  -d '{"email": "you@example.com", "name": "Your Name"}'

# Generate API key (save it — shown once)
curl -X POST https://snapstate.dev/admin/accounts/1/keys \
  -H "Authorization: Bearer admin_dev_secret_change_me" \
  -H "Content-Type: application/json" \
  -d '{"label": "development"}'

6. Start the dashboard (optional)

cd dashboard && npm install && npm run dev
# Opens at http://localhost:5173

7. View the docs site (optional)

cd docs && npm install && npm run dev
# Opens at http://localhost:5174

Architecture

HTTP request
  → Fastify (v3.0.0)
    → Auth middleware (Postgres key lookup + Redis 5-min cache)
    → Rate limit (Redis sliding window)
    → Route handler
      → checkpoint-writer  (Redis pipeline: HASH + STREAM + meta)
          ↳ usageTracker.track      (setImmediate, non-blocking)
          ↳ analyticsService.update (setImmediate, non-blocking)
          ↳ agentService.updateLastSeen (setImmediate, non-blocking)
          ↳ emitEvent               (fire-and-forget webhooks)
      → resume-engine  (Redis → Postgres → R2 fallback chain)

TTL Manager (background, every 60 s)
  → Scan wf:*:latest keys with TTL < 1 hour
  → archiver: read stream + gzip + R2 upload + Postgres record + delete Redis keys

Graceful shutdown (SIGTERM / SIGINT)
  → 10-second hard timeout
  → ttlManager.stop → app.close → Redis.quit → Postgres pool close

Redis key structure

KeyTypeContents
auth_cache:{key_hash}STRINGCached auth result (5-min TTL)
cp:{checkpoint_id}STRINGCompressed checkpoint record
wf:{workflow_id}:latestHASHLatest checkpoint state
wf:{workflow_id}:logSTREAMOrdered checkpoint event log
wf:{workflow_id}:metaHASHWorkflow metadata
webhooks:{api_key}HASHRegistered webhooks
rate_limit:{api_key}ZSETSliding-window timestamps

API reference

All endpoints require:

Authorization: Bearer <api_key>
Content-Type: application/json

All responses include X-Request-Id (UUID v4).

Core checkpoint endpoints

MethodPathDescription
POST/checkpointsSave a checkpoint
GET/checkpoints/:idGet a checkpoint
GET/workflows/:id/resumeResume (latest checkpoint)
GET/workflows/:id/replayFull checkpoint history

Save a checkpoint

curl -X POST https://snapstate.dev/checkpoints \
  -H "Authorization: Bearer $SNAPSTATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_id": "wf_001",
    "step": 1,
    "label": "research_complete",
    "state": {"findings": []},
    "agent_id": "research-bot"
  }'

Optional headers: X-Checkpoint-TTL: 3600, If-Match: "<etag>" (optimistic concurrency).

Agent identity endpoints

MethodPathDescription
POST/agentsRegister an agent (upsert)
GET/agentsList all agents
GET/agents/:agent_idGet agent details
PATCH/agents/:agent_idUpdate agent metadata
DELETE/agents/:agent_idDelete agent

Analytics endpoints

MethodPathDescription
GET/analytics/overviewAccount-level workflow stats
GET/analytics/workflows/:idPer-workflow checkpoint timeline
GET/analytics/failuresFailure pattern breakdown
GET/analytics/agentsPer-agent performance metrics

Webhook endpoints

MethodPathDescription
POST/webhooksRegister a webhook
GET/webhooksList webhooks
DELETE/webhooks/:idDelete a webhook

Health endpoints

curl https://snapstate.dev/health
# { status, version, uptime_seconds, redis, postgres, r2, timestamp }

curl https://snapstate.dev/ready
# 200 { status: "ready" } or 503 { status: "not_ready", redis, postgres }

Admin API

All admin routes require Authorization: Bearer <ADMIN_SECRET>.

MethodPathDescription
POST/admin/accountsCreate account
GET/admin/accountsList accounts
GET/admin/accounts/:idAccount + usage summary
POST/admin/accounts/:id/keysGenerate API key
GET/admin/accounts/:id/keysList API keys
DELETE/admin/accounts/:id/keys/:key_idRevoke API key
GET/admin/accounts/:id/usageUsage + free tier
GET/admin/accounts/:id/invoicesStripe invoices
GET/admin/statsDashboard overview
GET/admin/workflowsPaginated workflow list
GET/admin/activityRecent usage events
GET/admin/analytics/overviewGlobal analytics (all accounts)
GET/admin/analytics/failuresGlobal failure patterns
POST/billing/stripe-webhookStripe webhook receiver

SDKs

JavaScript SDK

npm install @snapstate/sdk
import { SnapStateClient } from '@snapstate/sdk';

const cp = new SnapStateClient({ apiKey: 'snp_...', baseUrl: 'https://snapstate.dev' });

// Register an agent (upsert — safe to call every startup)
await cp.registerAgent({
  agentId: 'research-bot',
  name: 'Research Bot',
  capabilities: ['web_search', 'summarization'],
  metadata: { model: 'claude-sonnet-4-6', version: '2.1.0' },
});

// Save a checkpoint
await cp.save({ workflowId: 'wf_001', step: 1, state: { query: 'hello' }, agentId: 'research-bot' });

// Resume from last checkpoint
const { latestCheckpoint } = await cp.resume('wf_001');

// Replay history
const { checkpoints } = await cp.replay('wf_001', { fromStep: 1 });

See sdk/ for source.

Python SDK

pip install snapstate-sdk
from snapstate_sdk import SnapStateClient

with SnapStateClient(api_key="snp_...", base_url="https://snapstate.dev") as client:
    result = client.save(workflow_id="wf_001", step=1, state={"query": "hello"}, agent_id="research-bot")
    resumed = client.resume("wf_001")
    history = client.replay("wf_001", from_step=1)

Async support via async_save / async_resume / async_replay and async with context manager.

See sdk-python/ for source and sdk-python/examples/ for usage examples.


MCP Server

Exposes checkpoint tools to any MCP-compatible agent (Claude Desktop, Cline, Cursor) without requiring SDK installation.

cd mcp-server && npm install

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "snapstate": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-server/src/index.js"],
      "env": {
        "SNAPSTATE_API_URL": "https://snapstate.dev",
        "SNAPSTATE_API_KEY": "snp_your_key_here"
      }
    }
  }
}
ToolDescription
save_checkpointSave state after each workflow step
resume_workflowRetrieve last checkpoint to resume from
get_workflow_historyFull ordered checkpoint history
register_agentRegister this agent with the service

Documentation site

The public docs site (docs/) is a React + Vite + Tailwind app with 8 documentation pages:

  • Getting Started — quickstart guide, first checkpoint in 5 minutes
  • API Reference — all endpoints with interactive Try It playground
  • JavaScript SDK — full method reference with code examples
  • Python SDK — sync + async usage, error handling, typed dataclasses
  • MCP Setup — Claude Desktop, Cline, and Cursor configuration
  • Agent Identity — multi-agent coordination walkthrough
  • Webhooks — event types, signature verification, best practices
  • Pricing — free tier details, usage rates, interactive cost calculator

Build for production:

cd docs && npm install && npm run build
# Output: docs/dist/ (served at /docs/ by the API server)

Environment variables

VariableDefaultDescription
PORT3000Server port
REDIS_URLredis://localhost:6379/0Redis connection
DATABASE_URLpostgres://checkpoint:checkpoint_dev@localhost:5432/snapstatePostgres connection
ADMIN_SECRETadmin_dev_secret_change_meAdmin API bearer token
DEFAULT_TTL_SECONDS604800Checkpoint TTL (7 days)
RATE_LIMIT_MAX100Requests/minute per key
R2_ACCOUNT_IDCloudflare R2 account ID
R2_ACCESS_KEY_IDR2 access key
R2_SECRET_ACCESS_KEYR2 secret key
R2_BUCKET_NAMEcheckpoint-archivesR2 bucket name
R2_ENDPOINTR2 S3-compatible endpoint URL
STRIPE_SECRET_KEYStripe secret key
STRIPE_WEBHOOK_SECRETStripe webhook signing secret
JWT_SECRETJWT signing secret (auth)
SMTP_HOSTSMTP host for email
SMTP_PORT587SMTP port
SMTP_USERSMTP username
SMTP_PASSSMTP password
SMTP_FROMFrom address for emails
FRONTEND_URLhttp://localhost:5173Dashboard URL (email links)

Running tests

cd server
npm test                                    # Full test suite
node --test tests/checkpoints.test.js       # Core checkpoint tests
node --test tests/agents.test.js            # Agent identity tests
node --test tests/analytics.test.js         # Analytics tests
cd sdk-python
pip install -e ".[dev]"
pytest                                      # Python SDK tests (18 tests, no server needed)

Tests use Redis db 1 for isolation. Postgres tests require a running database.

Reviews

No reviews yet

Sign in to write a review