cursor-coordinator-mcp
README.md
# cursor-coordinator-mcp
A remote MCP server on one Cloudflare Worker. It lets Claude read your Cursor cloud agents (mainly each Project's coordinator) and send instructions to coordinators, behind OAuth, an allowlist and a daily cap.
```
Claude --OAuth bearer--> Worker (/mcp, 9 tools) --Bearer user API key--> Cloud Agents API (api.cursor.com/v1)
```
## Tools
| Tool | What it does | Cursor call |
| --- | --- | --- |
| `list_projects` | Projects with their `coordinatorAgentId` | `GET /v1/projects` |
| `get_project` | One Project | `GET /v1/projects/{id}` |
| `list_project_agents` | Agents in a Project | `GET /v1/projects/{id}/agents` |
| `list_runs` | An agent's runs, newest first | `GET /v1/agents/{id}/runs` |
| `get_run` | Status, result, branches and PR links | `GET /v1/agents/{id}/runs/{runId}` |
| `list_artifacts` | Files an agent produced (list only) | `GET /v1/agents/{id}/artifacts` |
| `read_coordinator_messages` | Listens to the coordinator's stream for up to `maxSeconds` (max 25), returns assistant, status, tool-call and error events plus `lastEventId` to resume | `GET /v1/agents/{coord}/stream` |
| `send_to_coordinator` | **The only write.** New run, or `steer: true` into the run in progress | `POST /v1/agents/{coord}/runs` |
| `list_sends` | Audit log of sends and today's count | (KV only) |
All read tools are marked read-only. Every result that carries agent text tells Claude to treat it as data, not instructions.
## Guardrails on `send_to_coordinator`
- **Allowlist:** only Project ids in `ALLOWED_PROJECT_IDS`. `*` allows every Project your Cursor key can see (the ones you're part of). Empty means sending is off.
- **Daily cap:** `DAILY_SEND_CAP` (default 20), reset at midnight `CAP_TIME_ZONE` (default America/Los_Angeles). Only successful sends count.
- **Length cap:** `MAX_TEXT_LENGTH` (default 4,000 characters).
- **Audit log:** every attempt (sent, refused, error) is stored for 90 days with time, Project, coordinator, SHA-256 of the text (not the text), HTTP status and outcome.
- **No retries:** a 5xx or network error is reported with a warning that it may have been delivered (Cursor says a retried steer can deliver twice). A 429 passes `Retry-After` back.
- The coordinator is always looked up with `get_project`, never assumed to equal the Project id.
- The tool description tells Claude to send only after you've approved the exact text and target.
## Set up and deploy
Prerequisites: Node 20+, the Cloudflare account, and a Cursor **user** API key (a service-account key gets `403 user_required` on Projects). Keys are made on the API keys page of the Cursor (Grok Build) dashboard.
```sh
npm ci
npx wrangler login # or export CLOUDFLARE_API_TOKEN=...
```
The Worker needs two KV namespaces. Create them once with `npx wrangler kv namespace create <name>`:
- `cursor-coordinator-mcp-oauth` → `OAUTH_KV` (grants, clients, tokens; hashed or encrypted by the library)
- `cursor-coordinator-mcp-state` → `STATE_KV` (daily counter, audit log, failed sign-in counter)
Their ids stay out of the repo: `wrangler.jsonc` has the placeholders `__OAUTH_KV_ID__` and `__STATE_KV_ID__`, and `npm run deploy` fills them in from the `OAUTH_KV_ID` and `STATE_KV_ID` environment variables. Local `wrangler dev` uses local storage, so it works with the placeholders.
Set the secrets (each command prompts for the value; nothing goes in the repo):
```sh
npx wrangler secret put CURSOR_API_KEY # Cursor user API key
npx wrangler secret put AUTHORIZE_PASSPHRASE # what you type when connecting Claude
npx wrangler secret put ALLOWED_PROJECT_IDS # * for all your Projects, or e.g. bc-xxxx,bc-yyyy
```
Deploy:
```sh
OAUTH_KV_ID=<id> STATE_KV_ID=<id> npm run deploy
```
Wrangler prints the URL, `https://cursor-coordinator-mcp.<your-subdomain>.workers.dev`. Optionally pin it as the OAuth issuer by adding `"PUBLIC_URL": "https://…workers.dev"` to `vars` and deploying again (without it the Worker uses the hostname it was reached on).
Or deploy from GitHub: add repo secrets `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID`, `OAUTH_KV_ID` and `STATE_KV_ID`, then run the **Deploy** workflow by hand. Worker secrets still come from `wrangler secret put`.
### Connect Claude
1. In claude.ai, Settings → Connectors → Add custom connector, URL `https://<worker>/mcp`. (On an organization account an Owner may have to add it.)
2. Claude opens the Worker's sign-in page. It shows the app name and where access is sent. Enter the passphrase and press Allow.
3. Smoke test: list Projects, read a coordinator, then send one steer to a throwaway allowlisted Project.
Wrong passphrases are limited to 10 per hour.
## Develop and test
```sh
cp .dev.vars.example .dev.vars # fill in for wrangler dev
npm run typecheck
npm test # unit tests (fake Cursor API, in-memory KV)
npm run e2e # wrangler dev + fake Cursor API: full OAuth flow (register, passphrase, PKCE token) and real MCP calls
npm run check # typecheck + tests + bundle dry run
```
`scripts/wrangler.e2e.jsonc` is only for the e2e run. It points the Worker at a local fake API, so it leaves out `global_fetch_strictly_public`; the real config keeps it.
## Configuration
| Name | Kind | Default | Notes |
| --- | --- | --- | --- |
| `CURSOR_API_KEY` | secret | | Cursor user key. Never returned or logged. |
| `AUTHORIZE_PASSPHRASE` | secret | | Sign-in page passphrase. |
| `ALLOWED_PROJECT_IDS` | secret | empty (no sends) | `*` for all Projects the key can see, or ids separated by commas, spaces or newlines. Kept as a secret so Project ids aren't in the repo. |
| `CURSOR_API_BASE` | var | `https://api.cursor.com` | Change here if the API host moves after the rebrand. |
| `DAILY_SEND_CAP` | var | `20` | |
| `MAX_TEXT_LENGTH` | var | `4000` | |
| `CAP_TIME_ZONE` | var | `America/Los_Angeles` | |
| `PUBLIC_URL` | var | request origin | Optional. |
## Design notes
- **OAuth:** `@cloudflare/workers-oauth-provider` 1.x. The library's README recommends separate authorization and resource Workers, and keeps `OAuthProvider` fully supported for one Worker that is its own only resource, which is this case. It handles discovery, Dynamic Client Registration, Client ID Metadata Documents, S256 PKCE, form-encoded token requests, refresh tokens and the 401 `resource_metadata` challenge. We write only `/authorize` (`src/authorize.ts`).
- **MCP:** `McpServer` from `@modelcontextprotocol/server` 2.x, served with `createMcpHandler` from `agents/mcp/server` (stateless Streamable HTTP). No `McpAgent`.
- **Counter:** KV isn't atomic, so two sends in the same instant could count once. Fine for one user; use a Durable Object before going multi-user.
- **Stream reads:** waiting on the network doesn't count toward the free plan's 10 ms CPU limit; thinking, heartbeat and interaction events are dropped, tool calls are reduced to name and status, and assistant text is clipped at 8,000 characters per event.
## API facts checked (Dec 3, 2026)
From the Cloud Agents API endpoints and overview pages (cursor.com docs now redirect to docs.grok.com):
- Examples still use `https://api.cursor.com/v1`; no host change is documented.
- Basic (`key:`) and Bearer auth behave the same. This server uses Bearer.
- Artifacts list: 300/min, 6,000/hr, no pagination documented.
- Lists end when `nextCursor` is absent (not `null`).
- Steer body may hold only `prompt` and `delivery: "steer"`; answers `202` with `delivery` `steered` (with `runId` when a run took it) or `queued`.
## Not in v1
Creating, archiving or cancelling agents or Projects; messaging subagents; environments and secrets; downloading artifact contents; usage/cost; multi-user (see the spec's multi-user section before sharing).
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues