cursor-dispatcher
An MCP server that lets Claude spawn Cursor subagents as async, bounded workers, enabling non-blocking task delegation with asynchronous completion notifications.
README
cursor-dispatcher
An MCP server + Claude Code plugin that lets Claude spawn Cursor subagents as async, bounded workers.
Claude delegates a task, gets a run_id back immediately, and continues talking to the user. When the subagent finishes, a plugin hook injects the outcome into Claude's next turn — no polling, no blocked chat.
The original design spec lives in
PRD.md.
What it does
- Spawn Cursor subagents on demand (
spawn_subagent). - Message them mid-run via
--resume=<chat_id>(send_subagent_message). - Stream their NDJSON events to disk as they run (readable via
get_subagent_eventsor thesubagent://<run_id>/eventsMCP resource). - Synthesize a structured completion payload — status, summary, artifacts (file edits + shell tool calls with stdout/stderr) — via
get_subagent_result. - Cancel, list, prune.
- Retain run history under
~/.claude-cursor-harness/with tiered compression (7d → gzip, 14d → delete) and an LRU cap. - Notify Claude asynchronously via an
UserPromptSubmithook so subagent completions surface without polling. - Preflight cursor-agent auth on startup + every spawn; refuses with an actionable error if not logged in.
Requirements
- Node ≥ 20 (for the MCP server)
cursor-agentinstalled on$PATH, authenticated viacursor-agent loginorCURSOR_API_KEYenv var- Claude Code (for the plugin — hooks, skill, slash command)
Install
Public (via GitHub marketplace)
From inside Claude Code:
/plugin marketplace add ppetko98/cursor-dispatcher
/plugin install cursor-dispatcher@cursor-dispatcher
/reload-plugins
That's it — Claude Code clones the repo, wires up the MCP server, hook, skill, and slash command. You still need cursor-agent installed on $PATH and authenticated (see /cursor-login).
Local (for dev)
git clone https://github.com/ppetko98/cursor-dispatcher.git
cd cursor-dispatcher
npm install
npm run build
# From Claude Code:
/plugin marketplace add /absolute/path/to/cursor-dispatcher
/plugin install cursor-dispatcher@cursor-dispatcher
/reload-plugins
Then verify:
/mcp # cursor-dispatcher should be listed
/hooks # UserPromptSubmit → on-user-prompt.mjs
Skill: cursor-dispatcher:cursor-subagent
Slash: /cursor-login
Without the plugin (MCP-only)
If you only want the MCP tools without the hook + skill:
claude mcp add cursor-dispatcher -- node /absolute/path/to/cursor-dispatcher/dist/server.js
Usage (from Claude)
Typical delegation flow, driven by the shipped cursor-subagent skill:
- You: "have cursor scaffold a fastify server under
./demo." - Claude: calls
spawn_subagent({ prompt: "...", cwd: "...", permission: "auto" })→ returnsrun_idinstantly. Tells you it's running and moves on. - Subagent runs
cursor-agent -p --output-format stream-json --resume-supportin the background, streaming NDJSON events to~/.claude-cursor-harness/runs/<run_id>/events.ndjson. - You send any next message — the
UserPromptSubmithook scans for terminal transitions and prependsSUBAGENT <id> → completed — <summary>to your prompt. - Claude sees the update inline in the very next turn and reports back with the outcome (files edited, shell output, etc.).
Follow-ups on the same run use send_subagent_message — it re-invokes cursor-agent --resume=<chat_id> so the subagent picks up where it left off.
Permission model
The harness maps the parent Claude session's own posture to Cursor's approval flags:
permission value |
Cursor flags | When to pick |
|---|---|---|
read |
--mode ask (no --trust) |
Parent Claude is in plan / read-only mode. Subagent cannot write files or run shell commands. |
auto (default) |
--trust --auto-review |
Default. Server-side classifier auto-approves safe tool calls; unsafe ones would prompt (and effectively hang in headless mode). |
trust |
--trust --yolo |
Fully autonomous. Use only when the user has explicitly said "let it rip." |
Model must come from an allowlist (default: auto, gpt-5.2, claude-opus-5-thinking-high, claude-opus-4-8-thinking-high, composer-2.5). Working directory must live under a configured root (default ~/workspace).
MCP tools
All tools live under the cursor-dispatcher MCP server.
| Tool | Purpose |
|---|---|
spawn_subagent |
Launch a new subagent. Returns { run_id, chat_id?, status } immediately. |
send_subagent_message |
Send a follow-up message to a run (resumes the same Cursor chat). |
get_subagent_status |
Cheap poll: status + last event id + current turn. |
get_subagent_events |
Fetch NDJSON events since a given event_id. |
get_subagent_result |
Terminal-run completion payload: { status, summary, artifacts: [{ type, ref, metadata }] }. |
list_subagents |
Filterable list of runs known to the harness. |
cancel_subagent |
SIGTERM the child. |
prune_subagents |
Manual cleanup: { compress_after_days?, max_age_days?, keep_last?, dry_run? }. |
Resources are exposed at subagent://<run_id>/status and subagent://<run_id>/events, with notifications/resources/updated fired on each new batch of events.
Configuration
Precedence: env var > ~/.claude-cursor-harness/config.json > built-in defaults.
Example config file:
{
"runtime": { "cursorBin": "cursor-agent" },
"policy": {
"models": ["auto", "gpt-5.2"],
"defaultModel": "auto",
"cwdRoot": "/Users/you/workspace",
"sandbox": "enabled"
},
"retention": {
"compressAfterDays": 7,
"maxAgeDays": 14,
"maxRuns": 200,
"pruneOnStartup": true,
"pruneOnSpawn": true
}
}
Env-var overrides:
| Env | Config path |
|---|---|
CURSOR_HARNESS_HOME |
root data dir (default ~/.claude-cursor-harness) |
CURSOR_HARNESS_BIN |
runtime.cursorBin |
CURSOR_HARNESS_MODELS |
policy.models (comma-separated) |
CURSOR_HARNESS_DEFAULT_MODEL |
policy.defaultModel |
CURSOR_HARNESS_CWD_ROOT |
policy.cwdRoot |
CURSOR_HARNESS_SANDBOX |
policy.sandbox |
CURSOR_HARNESS_COMPRESS_AFTER_DAYS |
retention.compressAfterDays |
CURSOR_HARNESS_MAX_AGE_DAYS |
retention.maxAgeDays |
CURSOR_HARNESS_MAX_RUNS |
retention.maxRuns |
CURSOR_HARNESS_PRUNE_ON_STARTUP |
retention.pruneOnStartup |
CURSOR_HARNESS_PRUNE_ON_SPAWN |
retention.pruneOnSpawn |
CURSOR_API_KEY |
cursor-agent auth (bypasses login) |
Retention
Each run's data lives under ~/.claude-cursor-harness/runs/<run_id>/:
runs/<run_id>/
├── meta.json # RunMeta (status, model, chat_id, session, summary, retention state)
├── events.ndjson # NDJSON of every parsed cursor-agent event
├── messages.ndjson # Parent ↔ subagent message log
└── artifacts/ # Reserved for future materialized outputs
Lifecycle:
- 0–7 days: kept fully.
- 7–14 days:
events.ndjsonandmessages.ndjsongzipped in place.meta.jsongainsretentionState: "compressed",compressedAt, and a materializedsummaryso it stays self-describing.get_subagent_resultstill works —readEventstransparently gunzips. - >14 days: entire run dir deleted.
- LRU: if more than
maxRunsterminal survivors remain, the oldest (byendedAt) are deleted regardless of age. - Non-terminal runs are never touched.
Triggers: startup (registry.load), after every spawn_subagent, and on-demand via prune_subagents.
The plugin bundle
Under plugin/:
- MCP server — same code that ships as
dist/server.js. - Skill
cursor-subagent(plugin/skills/cursor-subagent/SKILL.md) — teaches Claude the non-blocking pattern, permission mapping, and follow-up flow. - Slash command
/cursor-login(plugin/commands/cursor-login.md) — walks the user through interactive login orCURSOR_API_KEYsetup. - Hook
UserPromptSubmit(plugin/hooks/on-user-prompt.mjs) — before each of your prompts, scans for new terminal transitions and injects a summary block. Filters to this Claude Code session where possible; falls back to reporting mismatched-session runs as[unlinked]so nothing is silently missed.
Development
npm install
npm run build # tsc
npm test # vitest (34 tests)
npm run lint # tsc --noEmit
Repo layout:
src/
├── server.ts # MCP stdio entrypoint
├── config.ts # Config layer (env + config.json)
├── session.ts # Per-server session id resolver
├── types.ts
├── runtime/
│ ├── runner.ts # Cursor CLI child process
│ ├── registry.ts # In-memory + disk-backed run registry
│ ├── storage.ts # ~/.claude-cursor-harness/ layout + gzip helpers
│ ├── events.ts # NDJSON parser, summary + artifact synthesis
│ ├── cleanup.ts # Retention engine (compress/delete/LRU)
│ ├── auth.ts # cursor-agent status preflight
│ └── notifier.ts # MCP notifications helpers
├── tools/ # One file per MCP tool
└── policy/ # Model allowlist, sandbox, cwd whitelist
plugin/
├── .claude-plugin/plugin.json
├── skills/cursor-subagent/SKILL.md
├── commands/cursor-login.md
└── hooks/on-user-prompt.mjs
tests/
Known limitations
- Session linking is loose. Claude Code doesn't expose a shared session id to child MCP servers, so runs stamped with the MCP server's random UUID rarely match the session id Claude Code injects into the hook. The hook falls back to reporting these as
[unlinked]so nothing is missed — noisy if you run concurrent Claude sessions. - True mid-silence wake-up isn't possible. MCP notifications reach the client but Claude Code doesn't (currently) auto-invoke the model on them. Subagent completions surface on your next prompt, not asynchronously.
spawn_subagentrequires a working cursor-agent + auth. No queueing, no retry. If cursor-agent isn't installed or not authenticated, the tool call fails with a clear message pointing at/cursor-login.
License
PolyForm Noncommercial 1.0.0 — free for personal, research, educational, hobbyist, and other noncommercial use (including noncommercial open-source projects, charities, and government/academic institutions). Commercial use, hosting-as-a-service, and repackaging for resale are not permitted. If you want to use this in a for-profit setting, open an issue to discuss a commercial license.
Note: "noncommercial" here does not meet the OSI's Open Source Definition (which forbids field-of-use restrictions); this is a source-available license.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.