cursor-delegate-mcp 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,7 +24,7 @@ Cursor Delegate is the MCP bridge that lets Claude Code, ChatGPT/Codex, Copilot
24
24
 
25
25
  ## 🧠 Frontier quality, kept
26
26
 
27
- Your assistant does what frontier models are actually for: understands the task, writes a precise brief, reviews the finished diff. **Composer 2.5** runs the implementation loop under that brief. Nothing lands unreviewed — the agent that scoped the work reads the changed files back before you see them.
27
+ Your assistant does what frontier models are for: understands the task, writes a precise brief, reviews the finished diff. **Composer 2.5** runs the implementation loop under that brief. The bundled skill puts the review step in the loop — the agent that scoped the work reads the changed files back before reporting.
28
28
 
29
29
  ## ⚡ Done faster
30
30
 
@@ -42,12 +42,14 @@ Composer and Grok run on their **own usage allowance** on every Cursor plan —
42
42
 
43
43
  - 🤝 **Native plugins** — install into Claude Code, ChatGPT/Codex, or GitHub Copilot CLI and just say *"delegate this to Cursor"*. The shared skill teaches your agent how to delegate well.
44
44
  - 💬 **No stalled runs** — if Cursor needs to clarify, it ends the turn and returns the question as a normal result. Your agent reads it and answers by resuming the same session — nothing blocks on a modal waiting for input.
45
- - 📦 **Clean, named results** — final answer, changed files, session id, and the plan, returned as one compact JSON payload. Nothing to scrape, nothing to guess.
45
+ - 📦 **Clean, named results** — final answer, changed files, session id, and the plan, returned as one compact JSON payload. Nothing to scrape.
46
46
  - 📋 **Plan first** — `plan` mode: Cursor drafts a plan, you review it, then the same session implements it.
47
- - 🔍 **Ask anything** — `ask` mode: read-only Q&A over your codebase.
47
+ - 🔍 **Ask anything** — `ask` mode: Q&A over your codebase.
48
48
  - 🩺 **Self-diagnosing** — a `doctor` tool that tells you exactly what's missing if setup isn't right.
49
49
  - 🔌 **Portable** — plain stdio MCP, so it runs anywhere: VS Code, JetBrains, Windsurf, Visual Studio, and more.
50
50
 
51
+ `plan` and `ask` are instructions to the agent, and `workspace` is its working directory — [Security](SECURITY.md) and the [delegate reference](skills/delegate/reference.md) spell out what the bridge enforces and what it reports back.
52
+
51
53
  ## Install
52
54
 
53
55
  You need [Node.js 20+](https://nodejs.org/) and the [Cursor CLI](https://cursor.com/docs/cli/overview), logged in (`cursor-agent login`).
package/SECURITY.md CHANGED
@@ -2,17 +2,25 @@
2
2
 
3
3
  ## What this plugin does
4
4
 
5
- `cursor-delegate-mcp` spawns **cursor-agent** in your workspace and **auto-approves file
6
- write and permission requests** over ACP (`allow-always`). Delegated tasks can modify,
7
- create, or delete files under the chosen `workspace` directory.
5
+ `cursor-delegate-mcp` spawns **cursor-agent** in your workspace and **auto-approves every
6
+ permission it requests** over ACP, in every mode — `agent`, `plan` and `ask`. Each request is
7
+ answered with the broadest allow option the agent offered (`allow_always`, else `allow_once`).
8
8
 
9
- Treat every `delegate` call like handing an engineer write access to that tree.
9
+ `workspace` is the agent's working directory, and a run can reach outside it. `mode` is
10
+ passed to the agent as an instruction, so `plan` and `ask` describe how it behaves rather
11
+ than what it is permitted to do. Delegated tasks can create, modify, or delete files
12
+ anywhere your user account can reach, and reach the network.
13
+
14
+ Treat every `delegate` call like handing an engineer a shell on your machine. Your MCP host
15
+ is the orchestrator: it should scope the brief, then review `filesReportedByEditTools` and
16
+ the git diff. That field lists what the agent's edit tools reported touching; the git diff
17
+ is authoritative.
10
18
 
11
19
  ## Recommendations
12
20
 
13
21
  - Point `workspace` at the smallest directory that contains the task (not `$HOME` or `/`).
14
- - Review `filesReportedByEditTools` and the git diff before committing.
15
- - Use `mode: "plan"` when you only want a plan, not file changes.
22
+ It scopes what the agent works on, not what it can reach.
23
+ - Review the git diff before committing, after every run — including `plan` and `ask` ones.
16
24
  - Run verification (tests, lint) after delegation — the delegate skill asks Claude to do
17
25
  this, but automated gates in CI are still your backstop.
18
26
  - Do not commit secrets (`.env`, credentials, tokens). The bridge does not redact them from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursor-delegate-mcp",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "mcpName": "io.github.andreilungeanu/cursor-delegate-mcp",
5
5
  "type": "module",
6
6
  "description": "Delegate multi-file coding work from Claude Code, Codex, or Copilot to Cursor's CLI agent — structured results, plan mode, and changed files.",
package/src/acp-client.js CHANGED
@@ -61,8 +61,9 @@ export class AcpClient extends EventEmitter {
61
61
  this.child.stderr.on("error", () => {});
62
62
  // A supervisor trip writes session/cancel, which can land after the agent is already gone.
63
63
  // Without a handler that surfaces as an unhandled 'error' event on some platforms, taking
64
- // the whole MCP server down with it.
64
+ // the whole MCP server down with it. stdout needs the same guard; readline adds none.
65
65
  this.child.stdin.on("error", () => {});
66
+ this.child.stdout.on("error", () => {});
66
67
  const emitExit = (code, signal) => {
67
68
  if (this._exitEmitted) return;
68
69
  this._exitEmitted = true;
@@ -80,7 +81,11 @@ export class AcpClient extends EventEmitter {
80
81
  this.router = null; // set before first stdout line
81
82
  this.peer = new JsonRpcPeer(this.child.stdout, this.child.stdin, {
82
83
  onNotification: (method, params) => { if (method === "session/update") this.emit("update", params); },
83
- onRequest: (id, method, params) => { if (this.router) this.router(id, method, params); },
84
+ // The router is async and its result discarded, so a throw from its own catch would reject
85
+ // unobserved and exit the process. Promise.resolve covers a sync router in tests.
86
+ onRequest: (id, method, params) => {
87
+ if (this.router) Promise.resolve(this.router(id, method, params)).catch(() => {});
88
+ },
84
89
  onActivity: () => this.emit("activity"),
85
90
  });
86
91
  this.router = createRequestRouter({
package/src/delegate.js CHANGED
@@ -143,12 +143,32 @@ async function buildContextBlocks(contextFiles, workspace, client, warnings) {
143
143
  return blocks;
144
144
  }
145
145
 
146
+ // Only a session the agent does not have justifies a fresh one; falling back on anything else
147
+ // runs the task without the context the caller asked for. Code and wording together, never
148
+ // either: 2026.08.11 returns -32602 `Session "<id>" not found` when it is missing, but -32603
149
+ // `Failed to load session "<id>": <cause>` when restore fails, and that cause can carry the
150
+ // same words. A missed match costs a recoverable resume-failed; a false match costs a silent turn.
151
+ function isMissingSession(err) {
152
+ const message = err?.message || "";
153
+ return err?.code === -32602
154
+ && /\bsession\b/i.test(message)
155
+ && /\bnot found\b|\bdoes not exist\b|\bunknown session\b|\bno such session\b/i.test(message);
156
+ }
157
+
146
158
  async function openSession(client, resumeSessionId, workspace) {
147
159
  if (!resumeSessionId) return client.newSession(workspace);
148
160
  try {
149
161
  await client.loadSession(resumeSessionId, workspace);
150
162
  return { sessionId: resumeSessionId }; // load does not echo sessionId
151
163
  } catch (err) {
164
+ if (!isMissingSession(err)) {
165
+ throw makeError(
166
+ "resume-failed",
167
+ `session ${resumeSessionId} could not be loaded: ${err?.message || String(err)}.`
168
+ + ` The session was not resumed and no fresh session was started — retry, or omit`
169
+ + ` resumeSessionId to start fresh deliberately.`
170
+ );
171
+ }
152
172
  // Starting fresh is right, but silently doing so leaves the caller unable to tell a
153
173
  // stale id from a typo'd one — keep why the load failed.
154
174
  const fresh = await client.newSession(workspace);
@@ -225,6 +245,12 @@ export async function runDelegate({
225
245
  // Before the spawn: validating later costs a process, a handshake and a billed turn.
226
246
  assertWorkspace(workspace);
227
247
  const promptText = await resolveSpec(spec);
248
+ // addEventListener does not replay an abort that already fired, and the listener is registered
249
+ // below, so an abort during the await above is otherwise lost. Throwing, not supervisor.abort():
250
+ // tripping before supervise() installs its reject settles the supervisor with nothing listening.
251
+ if (signal?.aborted) {
252
+ throw makeError("aborted", "delegation aborted by MCP host");
253
+ }
228
254
  const capMs = hardCapMs ?? timeoutMs ?? envMs("CURSOR_DELEGATE_HARD_CAP_MS", 3600000);
229
255
  const shakeMs = handshakeMs ?? envMs("CURSOR_DELEGATE_HANDSHAKE_MS", DEFAULT_HANDSHAKE_MS);
230
256
  const turnIdleMs = idleMs ?? envMs("CURSOR_DELEGATE_IDLE_MS", 0);
@@ -495,8 +521,7 @@ export async function runDelegate({
495
521
  // outstanding — it also lets a retry resume the work already done.
496
522
  const isTimeout = err?.reason === "hard-cap" || err?.reason === "idle-timeout";
497
523
  // A handshake timeout gets the forensics but not the long-command advice: no prompt was sent,
498
- // so no shell command explains the silence. The session may still exist (it is set before
499
- // set_model/set_config_option/set_mode, any of which can hang), so the resume hint applies.
524
+ // so no shell command explains the silence.
500
525
  const isStall = isTimeout || err?.reason === "handshake-timeout";
501
526
  if (isStall || err?.reason === "aborted" || err?.reason === "agent-exit") {
502
527
  const age = fmtDuration(supervisor.msSinceActivity());
@@ -510,20 +535,23 @@ export async function runDelegate({
510
535
  }
511
536
  const files = normalizeAgentReportedFiles([...state.touched], workspace);
512
537
  if (files.length) err.message += ` Files reported edited: ${files.join(", ")}.`;
513
- // Without this the resume hint below reads as "carry on from where you were", when the
514
- // requested session was never loaded.
515
- if (resumeError) {
516
- err.message += ` Note: resuming ${resumeSessionId} had already failed (${resumeError}),`
517
- + ` so this ran as a fresh session and none of that earlier work was in context.`;
518
- }
519
- if (sessionId) err.message += ` Resume with resumeSessionId ${sessionId}.`;
520
- if (isTimeout) {
521
- // Name the knob that actually fired: raising the hard cap does nothing for an
522
- // idle-timeout, whose ceiling is CURSOR_DELEGATE_IDLE_MS.
523
- const knob = err.reason === "idle-timeout" ? "CURSOR_DELEGATE_IDLE_MS" : "CURSOR_DELEGATE_HARD_CAP_MS";
524
- err.message += " cursor-agent does not stream shell output over ACP, so a long-running command emits"
525
- + ` nothing until it exits. Split the command, run it in the background and poll, or raise ${knob}.`;
526
- }
538
+ }
539
+ // Every failure after session/new leaves a live session, not just the stalls: the id is set
540
+ // before set_model/set_config_option/set_mode, so unknown-model and a rejected config value
541
+ // land here too and are abandoned without it.
542
+ if (resumeError) {
543
+ // Without this the resume hint reads as "carry on from where you were", when the requested
544
+ // session was never loaded.
545
+ err.message += ` Note: resuming ${resumeSessionId} had already failed (${resumeError}),`
546
+ + ` so this ran as a fresh session and none of that earlier work was in context.`;
547
+ }
548
+ if (sessionId) err.message += ` Resume with resumeSessionId ${sessionId}.`;
549
+ if (isTimeout) {
550
+ // Name the knob that actually fired: raising the hard cap does nothing for an
551
+ // idle-timeout, whose ceiling is CURSOR_DELEGATE_IDLE_MS.
552
+ const knob = err.reason === "idle-timeout" ? "CURSOR_DELEGATE_IDLE_MS" : "CURSOR_DELEGATE_HARD_CAP_MS";
553
+ err.message += " cursor-agent does not stream shell output over ACP, so a long-running command emits"
554
+ + ` nothing until it exits. Split the command, run it in the background and poll, or raise ${knob}.`;
527
555
  }
528
556
  // Opt-in: the frames land in the caller's context and nothing there is actionable — the
529
557
  // forensics above already carry that. Raw frames only help someone debugging the bridge.
package/src/server.js CHANGED
@@ -50,7 +50,7 @@ function rememberSession(set, id) {
50
50
  // Loaded at connect, before any tool schema is, so this carries only pre-call facts: what a
51
51
  // caller needs to decide whether to delegate at all. Call-time facts belong on the parameter
52
52
  // descriptions, read while the call is being written.
53
- export const SERVER_INSTRUCTIONS = `Delegate coding work to Cursor through the delegate tool. Every permission the agent requests is auto-approved, in every mode: mode="plan" and mode="ask" are instructions to the agent, not limits the bridge enforces, and the bridge cannot detect one being ignored. So scope workspace to the smallest relevant directory and review the git diff after every run, not only write-capable ones; filesReportedByEditTools lists what the agent's edit tools reported changing (absent when they reported none) but the diff is authoritative.`;
53
+ export const SERVER_INSTRUCTIONS = `Delegate coding work to Cursor through the delegate tool. Every permission the agent requests is auto-approved, in every mode: agent/plan/ask reach any file the user account can, and mode instructs the agent rather than limiting it. Scope workspace tightly and review the git diff after every run — filesReportedByEditTools carries only what the agent's edit tools reported; the diff is authoritative.`;
54
54
 
55
55
  const planEntrySchema = z.object({
56
56
  content: z.string(),
@@ -141,22 +141,17 @@ export const doctorOutputShape = {
141
141
  };
142
142
 
143
143
  export const delegateInputSchema = z.object({
144
- spec: z.string().trim().min(1, "spec must not be blank").describe("Inline task brief (default): goal, scope, decisions already made (constraints and fixed choices — quote the user's exact values verbatim), acceptance criteria. Point at files to read or mimic rather than pasting code. Optional file path if the user wants a persisted spec."),
145
- mode: z.enum(["agent", "plan", "ask"]).default("agent").describe("Requested agent mode. plan and ask are passed to the agent as instructions, not enforced by the bridge — the agent may write in any of them, so review the git diff after every run. ask held on every model tested while plan compliance varies by model, so prefer ask when you need the stricter read-only instruction."),
146
- resumeSessionId: z.string().optional().describe("Resume an existing ACP session instead of a new one"),
147
- workspace: z.string().optional().describe("Working directory for the agent. Optional; defaults to the server process cwd. Must already exist — never create one for the call."),
144
+ spec: z.string().trim().min(1, "spec must not be blank").describe("Task brief: goal, scope, fixed decisions quoted exactly, acceptance criteria. Point at files to read rather than pasting code. A lone file path is read as the brief."),
145
+ mode: z.enum(["agent", "plan", "ask"]).default("agent").describe("agent implements; plan and ask are instructions to the agent, not limits."),
146
+ resumeSessionId: z.string().optional().describe("Continue an existing ACP session."),
147
+ workspace: z.string().optional().describe("The agent's working directory, not a limit. Defaults to the server process cwd, which under npx is often not your project root — pass it explicitly. Must already exist; never create one for the call."),
148
148
  model: z.string().trim().min(1, "model must be a non-empty string").default(DEFAULT_MODEL).describe("Bare ACP family id, version included: composer-2.5, grok-4.5, claude-opus-5, gpt-5.6-sol. doctor deep:true lists every id."),
149
- fast: z.boolean().default(false).describe("Fast speed tier — higher cost; enable only when the user asks"),
149
+ fast: z.boolean().default(false).describe("Fast tier; higher cost — only when the user asks."),
150
150
  // Which options a model offers, and their valid values, are only knowable by asking the
151
151
  // agent, so these stay open strings and the agent rejects what it does not accept.
152
- effort: z.string().trim().min(1).optional().describe("Thinking effort. Not offered by every model, and the values differ; gpt-5.x accepts none, low, medium, high, extra-high. doctor deep:true lists the current model's options."),
153
- // Declared only to be rejected: an undeclared key is stripped silently, which would lose the
154
- // requested effort without a word. Rejection costs a retry and no spawn.
155
- reasoning: z.string().trim().min(1).optional()
156
- .refine((v) => v === undefined, { message: "reasoning was renamed to effort; pass effort instead" })
157
- .describe("Removed — use effort."),
158
- context: z.string().trim().min(1).optional().describe("Context window size. Not offered by every model; gpt-5.x accepts 272k and 1m."),
159
- contextFiles: z.array(z.string()).optional().describe("Paths to attach instead of pasting file contents into spec. Text files are passed as references the agent may open; images (png, jpg, gif, webp, under 5MB) are sent inline. Relative paths resolve against workspace, and paths outside it are allowed — attach only files the agent should read. Anything skipped is reported in protocolWarnings, never fatal."),
152
+ effort: z.string().trim().min(1).optional().describe("Thinking effort; ids and values differ per model, and some offer none. gpt-5.x: none, low, medium, high, extra-high. doctor deep:true lists the current model's."),
153
+ context: z.string().trim().min(1).optional().describe("Context window size; gpt-5.x accepts 272k and 1m. Do not pass speculatively."),
154
+ contextFiles: z.array(z.string()).optional().describe("Paths to attach instead of pasting contents into spec. Text becomes references the agent may open; images (png/jpg/gif/webp, <5MB) are sent inline. Relative paths resolve against workspace but are not limited to it. Skips are reported in protocolWarnings, never fatal."),
160
155
  });
161
156
 
162
157
  /**
@@ -177,11 +172,13 @@ export async function runDelegateTool({ args, extra, runDelegate, inFlight, seen
177
172
  if (progressToken != null) {
178
173
  let progress = 0;
179
174
  onProgress = (message) => {
175
+ // sendNotification is async: its rejection settles outside this try and would exit the
176
+ // server. The try stays for a sync throw, which lands before Promise.resolve can wrap it.
180
177
  try {
181
- extra.sendNotification({
178
+ Promise.resolve(extra.sendNotification({
182
179
  method: "notifications/progress",
183
180
  params: { progressToken, progress: ++progress, message },
184
- });
181
+ })).catch(() => {});
185
182
  } catch {}
186
183
  };
187
184
  }
@@ -248,7 +245,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
248
245
  "delegate",
249
246
  {
250
247
  description:
251
- `Delegate a coding task to cursor-agent over ACP. Never shell out to cursor-agent — use this tool only. Pass structured task text inline in spec (default); a file path is optional when the user wants a persisted brief. Defaults: mode=agent, model=${DEFAULT_MODEL}, fast=false. Plan workflow: mode=plan, then resume with mode=agent and resumeSessionId. Auto-approves every permission the agent requests, in any mode and anywhere on disk. Clarifying questions arrive as prose in result — resume with resumeSessionId to answer. Returns the final result, selection source, stop reason, session ID, agent-reported files, and optional plan. See the delegate skill for orchestration.`,
248
+ `Delegate a coding task to cursor-agent over ACP. Never shell out to cursor-agent — use this tool only. Auto-approves every permission the agent requests, in any mode and anywhere on disk. Clarifying questions arrive as prose in result — resume with resumeSessionId to answer. Keep model (${DEFAULT_MODEL}), fast and effort at their defaults unless the user asks. See the delegate skill.`,
252
249
  inputSchema: delegateInputSchema,
253
250
  annotations: {
254
251
  title: "Delegate coding task to Cursor",
@@ -265,10 +262,10 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
265
262
  "cancel",
266
263
  {
267
264
  description:
268
- "Best-effort cancel of an in-flight ACP delegation by sessionId. Sends session/cancel; the agent may finish the turn anyway. The delegate result carries cancelRequested: true when the turn was cancelled mid-run. MCP hosts that serialize tool calls cannot run this while delegate is in flight. With force: true, the agent process is killed if the turn is still running after a short grace period. Returns not-running for a session whose turn already ended (it is still resumable), and not-found for an id never seen this process.",
265
+ "Best-effort cancel of an in-flight delegation by sessionId. session/cancel is advisory — the agent may finish the turn anyway, and the delegate result then carries cancelRequested. Status: cancelled, killed, not-running (turn already ended, still resumable), not-found (id never seen this process).",
269
266
  inputSchema: {
270
267
  sessionId: z.string(),
271
- force: z.boolean().default(false).describe("After the cancel notify, wait a short grace period and kill the agent process if the delegation is still running"),
268
+ force: z.boolean().default(false).describe("Kill the agent process if the turn is still running after a short grace period."),
272
269
  },
273
270
  annotations: {
274
271
  title: "Cancel Cursor delegation",
@@ -310,12 +307,12 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
310
307
  "doctor",
311
308
  {
312
309
  description:
313
- "Report setup and health diagnostics: plugin version, MCP client capabilities, cursor-agent launcher resolution, and optional deep ACP handshake. Use when delegation fails or agent.found is false.",
310
+ "Setup diagnostics: plugin version, MCP client capabilities, cursor-agent launcher resolution. Run when delegation fails or agent.found is false.",
314
311
  inputSchema: {
315
312
  deep: z
316
313
  .boolean()
317
314
  .default(false)
318
- .describe("When true, run a lightweight ACP handshake (start → initialize → newSession) to verify the agent is usable"),
315
+ .describe("Run an ACP handshake (start → initialize → newSession) to verify the agent is usable; adds models, modes and the current model's options."),
319
316
  },
320
317
  annotations: {
321
318
  title: "Diagnose Cursor delegation setup",