MCP Setup

Create a per-account MCP API key for external tools. You can rotate or revoke the key anytime.

1) Your MCP API key

Log in, then generate a key. The full secret is shown only once—copy it before leaving this page. Rotating replaces the old key immediately.

Status: No key yet—generate one to use MCP.

2) Server environment

The server no longer uses a global MCP_API_KEY. Ensure Better Auth and database settings are configured:

BETTER_AUTH_SECRET=...
BETTER_AUTH_URL=...
TURSO_DATABASE_URL=...
TURSO_AUTH_TOKEN=...
CLOUDFLARE_R2_ACCOUNT_ID=...
CLOUDFLARE_R2_ACCESS_KEY_ID=...
CLOUDFLARE_R2_SECRET_ACCESS_KEY=...
CLOUDFLARE_R2_BUCKET_NAME=...
OPENAI_API_KEY=...
GEMINI_API_KEY=...

3) MCP endpoint details

MCP JSON-RPC URL: https://your-domain.com/api/mcp?api_key=<YOUR_MCP_API_KEY>

SSE URL: https://your-domain.com/api/mcp/sse?sessionId=<SESSION_ID>&api_key=<YOUR_MCP_API_KEY>

Query param: api_key (preferred) or legacy mcp_api_key

Header: x-api-key: <key> or legacy x-mcp-api-key

4) Quick verification with curl

curl -X POST "https://your-domain.com/api/mcp?api_key=<YOUR_MCP_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc":"2.0",
    "id":1,
    "method":"tools/list",
    "params":{}
  }'

5) Claude MCP config values

URL: https://your-domain.com/api/mcp?api_key=<YOUR_MCP_API_KEY>
SSE URL: https://your-domain.com/api/mcp/sse?sessionId=<SESSION_ID>&api_key=<YOUR_MCP_API_KEY>

6) Apply database migration (new installs)

Per-user keys require the user_mcp_keys table. From any machine with Turso credentials set:

npm run db:migrate

Or run drizzle/0001_initial.sql manually in your SQL console. Verify with npm run db:check.