Prerequisites
- Node.js >= 22
- PostgreSQL (direct or via Supabase)
- Docker (optional, for local Postgres)
Quick start with Docker
The monorepo includes a Docker Compose setup for local PostgreSQL:Database schema
Create these tables in your PostgreSQL database:SQL
Storage adapters
The Context API uses a storage adapter pattern to abstract database operations. You can choose between two backends:- Direct PostgreSQL — Drizzle ORM with a direct connection
- Supabase — Supabase REST client for managed PostgreSQL
Direct PostgreSQL
.env
Supabase
.env
Permanent delete operations (
uc.delete(..., {permanent: true}) and uc.deleteMany(...)) run as sequential REST calls on this provider — a mid-operation failure may leave partially-deleted state. Use the postgres provider for atomic permanent delete.1
Create a Supabase project
Go to supabase.com and create a new project.
2
Create the tables
Run the SQL schema above in the Supabase SQL editor.
3
Get your credentials
In your Supabase dashboard, go to Settings > API. Copy:
- Project URL — your
SUPABASE_URL - service_role key — your
SUPABASE_SERVICE_ROLE_KEY
4
Set environment variables
Add the Supabase env vars shown above to your
.env file.Environment variables
Deploy to Cloudflare Workers
The Context API ships with a Workers entrypoint (src/worker.ts) that runs on Cloudflare’s edge network. Only the Supabase storage adapter is supported on Workers (no direct TCP to PostgreSQL).
Prerequisites
- A Supabase project with the schema applied
- Wrangler CLI installed
Configure
Create awrangler.jsonc in apps/api:
wrangler.jsonc
wrangler secret put:
Optional: API key caching with KV
You can cache API key lookups using Workers KV to reduce Supabase calls:- Create a KV namespace:
wrangler kv namespace create ULTRACONTEXT_API_KEYS_CACHE - Add the binding to
wrangler.jsonc:
wrangler.jsonc
Deploy
MCP endpoint
Self-hosted APIs include a built-in MCP endpoint at/mcp. No extra setup needed — it uses the same Bearer token authentication as the REST API. See MCP Server for details.