Skip to main content
Self-hosting You can self-host the Context API instead of using the managed service at ultracontext.ai.

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
Both produce identical API behavior.

Direct PostgreSQL

.env
Best for self-hosted deployments where you manage your own database. Lower latency via direct TCP connection.

Supabase

.env
Best for managed hosting and quick setup. Scaling handled by Supabase.
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.
Use the service role key, not the anon key. The service role key bypasses Row Level Security, which the API needs to manage data across projects.
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

Configure

Create a wrangler.jsonc in apps/api:
wrangler.jsonc
Set your secrets via wrangler secret put:

Optional: API key caching with KV

You can cache API key lookups using Workers KV to reduce Supabase calls:
  1. Create a KV namespace: wrangler kv namespace create ULTRACONTEXT_API_KEYS_CACHE
  2. Add the binding to wrangler.jsonc:
wrangler.jsonc
When the binding is present, key lookups are cached for 1 hour. Without it, every request queries Supabase directly (same behavior as Node.js).

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.