API Key Actions
Server actions for creating, listing, and revoking API keys. API keys enable programmatic access to the MCP endpoint without browser sessions.createApiKey
Creates a new API key for the authenticated user. The plaintext key is returned only once and must be stored securely by the caller. Source:src/features/api-keys/actions.ts:26
Parameters
A descriptive label for the API key (1-100 characters). Used to identify the key in the UI.
Returns
Whether the operation succeeded
Error message if
success is falseExample
Behavior
- Validation: Label must be 1-100 characters
- Authentication: Requires active session (uses cookies)
- Limit Enforcement: Maximum 10 active (non-revoked) keys per user
- Plaintext Exposure: The plaintext key is returned exactly once and never stored
- Hash Storage: Only the SHA-256 hash is stored in
user_api_keys.key_hash
Errors
| Error | Cause |
|---|---|
Unauthorized | No authenticated session |
Invalid label | Label validation failed |
You may only have 10 active API keys... | User has reached the limit |
Failed to create API key | Database insertion error |
listApiKeys
Returns all API keys (active and revoked) for the authenticated user, ordered by creation date descending. Source:src/features/api-keys/actions.ts:113
Parameters
None.Returns
Whether the operation succeeded
Array of API key records (without
key_hash)Error message if
success is falseExample
Behavior
- Authentication: Requires active session
- Ordering: Newest keys first (descending
created_at) - Security: The
key_hashcolumn is never selected or exposed - Includes Revoked: Returns both active and revoked keys
revokeApiKey
Revokes an API key by settingrevoked_at to the current timestamp. The operation is idempotent — revoking an already-revoked key succeeds without error.
Source: src/features/api-keys/actions.ts:155
Parameters
UUID of the API key to revoke
Returns
Whether the operation succeeded
Error message if
success is falseExample
Behavior
- Authentication: Requires active session
- Authorization: Users can only revoke their own keys (enforced by
user_idfilter) - Idempotent: Revoking an already-revoked key returns
success: true - Soft Delete: The key record remains in the database with
revoked_atset - Immediate Effect: Revoked keys are rejected by the MCP endpoint immediately
Security
Revoked keys:- Cannot be used to authenticate MCP requests
- Remain visible in the UI with a “Revoked” badge
- Cannot be un-revoked (deletion is permanent in effect)
Authentication
All API key actions require session-based authentication. They use the standard Supabase client created from cookies:Database Schema
API keys are stored in theuser_api_keys table:
RLS Policies
- Users can SELECT their own keys
- Users can INSERT their own keys
- Users can UPDATE (revoke) their own keys
- The
key_hashcolumn is never exposed to clients
Security Best Practices
API keys are hashed with SHA-256 before storage. The plaintext key is never persisted and cannot be recovered if lost.
Next Steps
- API Authentication — Understanding session-based vs API key authentication
- MCP Overview — Using API keys with the MCP endpoint
- MCP Configuration — Setting up AI clients with API keys