Skip to main content

AI Agents, API Keys, and MCP

Nexus supports AI agents through either:

  1. Self-registration for a new free-tier agent-owned organization.
  2. A human organization admin creating an agent API key for an existing organization.
  3. The agent exchanging that API key for a short-lived agent JWT.

The short-lived agent JWT is then used to access:

  • the Nexus MCP server
  • Supabase PostgREST endpoints protected by agent-aware RLS
  • Nexus edge functions that accept bearer tokens

Deployed endpoints

PurposeMethodURL
Self-register a new agent-owned orgPOSThttps://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-register
Create agent API keyPOSThttps://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-api-key-create
Exchange API key for agent JWTPOSThttps://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-auth
Inspect plan and usageGEThttps://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-usage
Nexus MCP serverPOSThttps://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/mcp-server

Authentication model

Human users

Human users authenticate with Supabase Auth and receive a standard user JWT.

Human JWTs are used for:

  • frontend access
  • admin operations
  • creating agent API keys

Agent API keys

Agent API keys are long-lived credentials for autonomous agents.

Properties:

  • format: nxs_ak_ + 48 random alphanumeric characters
  • the raw key is returned once only
  • Nexus stores only a bcrypt hash
  • keys are organization-scoped
  • keys can be revoked by setting is_active = false

Agent JWTs

Agents do not use the raw API key for normal operations. They first exchange it for a short-lived bearer token:

  • max lifetime: 1 hour
  • contains organization_id
  • contains org_role = agent
  • contains agent_scopes

The agent JWT is the bearer token used with the MCP server and API requests.

Scopes

Nexus agent scopes are intentionally simple:

ScopeAccess
readSELECT-style read access only
writeread + create + update
adminfull access including delete/admin operations

admin implies all lower scopes. write implies read.

Pricing

PlanPriceSummary
free$0/moread-only MCP, 50 contacts, 25 orders, no outbound messaging, 500 API calls/day, 30-day retention
starter$99/moread+write MCP, 500 contacts, 200 orders/month, 1,000 outbound messages, 5,000 API calls/day
growth$199/mofull MCP, 5,000 contacts, unlimited orders, 5,000 outbound messages, 25,000 API calls/day, VoIP + automation
scale$599/mohighest limits, full AI suite, custom integrations, SLA, priority onboarding

Additional agents are billed separately on paid plans:

  • Starter: $10/agent/month
  • Growth and Scale: $5/agent/month

Step 0: self-register a free agent-owned organization

For brand-new agents without an existing Nexus organization, call agent-register first.

Request:

curl -X POST "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-register" \
-H "Content-Type: application/json" \
-d '{
"agent_name": "Bahig",
"agent_platform": "cursor",
"owner_email": "karim@example.com",
"organization_name": "Bahig - Personal Assistant",
"plan": "free"
}'

Response:

{
"success": true,
"organization_id": "org-uuid",
"api_key": "nxs_ak_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12",
"api_key_expires_at": "2026-06-23T01:00:00.000Z",
"mcp_endpoint": "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/mcp-server",
"auth_endpoint": "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-auth",
"plan": "free",
"plan_limits": {
"contacts": 50,
"orders": 25,
"inventory_items": 30,
"outbound_messages": 0,
"api_calls_per_day": 500,
"warehouses": 1,
"ai_annotations": 0,
"agents": 1,
"mcp_scopes": ["read"],
"data_retention_days": 30
},
"message": "Store your API key securely. It cannot be retrieved again."
}

Rate limits:

  • max 3 registrations per owner_email per day
  • max 10 registrations per IP per hour
  • paid plans require human-led upgrade; self-registration is free only

Step 1: create an agent API key

Only organization owner and admin users can create agent API keys.

Request:

curl -X POST "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-api-key-create" \
-H "Authorization: Bearer <human-user-jwt>" \
-H "Content-Type: application/json" \
-d '{
"name": "Bahig - Karim assistant",
"scopes": ["read", "write"],
"expires_at": "2026-12-31T23:59:59Z"
}'

Response:

{
"api_key": "nxs_ak_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12",
"key_prefix": "nxs_ak_ab12CD34",
"organization_id": "org-uuid",
"name": "Bahig - Karim assistant",
"scopes": ["read", "write"],
"expires_at": "2026-12-31T23:59:59.000Z",
"message": "Store this API key now. It is only returned once."
}

Important:

  • The raw API key cannot be retrieved later.
  • Store it in a secure secret manager.
  • Never log it in plaintext.

Step 2: exchange API key for agent JWT

Request:

curl -X POST "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-auth" \
-H "Content-Type: application/json" \
-d '{
"api_key": "nxs_ak_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12"
}'

Response:

{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"expires_in": 3600,
"organization_id": "org-uuid"
}

Security behavior:

  • invalid/revoked/expired keys are rejected
  • the endpoint is rate limited to 10 attempts per minute per IP
  • every auth attempt is logged
  • last_used_at is updated on success

Step 3: check usage and plan status

Agents and human admins can inspect current usage:

curl "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/agent-usage" \
-H "Authorization: Bearer <agent-or-human-jwt>"

The response includes:

  • current plan slug and name
  • usage counters and limits
  • remaining capacity
  • warnings when a resource is at or above 80%
  • upgrade guidance

Step 4: call the MCP server

Use the returned agent JWT:

curl -X POST "https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/mcp-server" \
-H "Authorization: Bearer <agent-jwt>" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {},
"clientInfo": {
"name": "my-agent",
"version": "1.0.0"
}
}
}'

The endpoint uses MCP Streamable HTTP, not the legacy SSE transport.

This implementation currently runs in JSON response mode over Streamable HTTP, which works well for hosted remote agents and API-style MCP clients.

MCP tools

The Nexus MCP server exposes these tools:

ToolDescription
nexus_list_contactsList or search contacts with filters
nexus_get_contactGet full contact details
nexus_create_contactCreate a contact
nexus_update_contactUpdate contact fields
nexus_list_ordersList orders with filters
nexus_get_orderGet an order with line items
nexus_create_orderCreate an order
nexus_update_order_statusMove order through lifecycle
nexus_list_inventoryList inventory items
nexus_check_stockCheck stock by item or SKU
nexus_list_conversationsList conversations
nexus_send_messageSend WhatsApp/Facebook/Instagram messages
nexus_searchSearch contacts, orders, and inventory

MCP resources

The Nexus MCP server also exposes these resources:

ResourceDescription
nexus://organization/infoCurrent organization details and auth context
nexus://schema/contactsContact schema
nexus://schema/ordersOrder schema
nexus://schema/inventoryInventory schema

Non-MCP access

Agents can also use the agent JWT directly against:

  • https://lgwvoomgrwpsgpxwyaec.supabase.co/rest/v1/...
  • https://lgwvoomgrwpsgpxwyaec.supabase.co/functions/v1/...

For PostgREST requests, include both:

Authorization: Bearer <agent-jwt>
apikey: <anon-key>

The database layer enforces organization isolation and agent scope checks through RLS.

Agent-friendly edge functions

These deployed edge functions are especially relevant to AI agents:

FunctionPurpose
agent-registerSelf-register a free agent-owned organization and receive an initial API key
agent-api-key-createHuman admin creates agent API keys
agent-authExchange API key for short-lived agent JWT
agent-usageRead current plan, usage counters, and upgrade warnings
mcp-serverRemote MCP endpoint for Nexus
whatsapp-send-messageSend WhatsApp message
facebook-send-messageSend Messenger message
instagram-send-messageSend Instagram DM

Best practices

  1. Prefer the MCP server for agent integrations because it gives a stable tool surface.
  2. Use the raw API key only with agent-auth.
  3. Rotate or revoke keys immediately if they are exposed.
  4. Request the smallest scope needed for the agent.
  5. Refresh the agent JWT by calling agent-auth again when it expires.
  6. Treat plan limits as hard ceilings. MCP scopes are capped by the organization's current plan even if an older API key requested broader scopes.