cursor-delegate-mcp 1.4.0 → 1.6.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/PRIVACY.md ADDED
@@ -0,0 +1,11 @@
1
+ # Privacy
2
+
3
+ Cursor Delegate MCP runs as a local stdio MCP server. The project author does not operate a backend for the plugin and does not receive your code, prompts, workspace contents, session identifiers, diagnostics, or usage telemetry.
4
+
5
+ Claude Code installs run the server bundled in the plugin cache. On first session, the plugin may run `npm install --omit=dev` inside that cache to fetch its open-source runtime dependencies; it does not install them into your project. Codex, Copilot, VS Code, and standalone MCP configurations start the published package through `npx`, so npm may apply its own registry logging under npm's policies.
6
+
7
+ When you delegate, the local server starts `cursor-agent`. Task prompts, selected workspace content, model requests, and Cursor account usage are handled by Cursor under [Cursor's terms and privacy policy](https://cursor.com/terms). Your MCP host may separately process the prompt and tool results under its own terms.
8
+
9
+ The MCP response can contain file paths, agent output, plan text, diagnostic information, and session identifiers. Review that output before sharing logs or bug reports. The plugin does not redact secrets found in prompts, files, agent output, or diagnostics.
10
+
11
+ For security issues, see [SECURITY.md](SECURITY.md) or open a [GitHub Security Advisory](https://github.com/andreilungeanu/cursor-delegate-mcp/security/advisories/new).
package/README.md CHANGED
@@ -1,55 +1,60 @@
1
1
  # Cursor Delegate MCP
2
2
 
3
- **Let Claude think. Let Cursor build.**
3
+ **Keep the brains. Delegate the build.**
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/cursor-delegate-mcp)](https://www.npmjs.com/package/cursor-delegate-mcp)
6
6
  [![npm downloads](https://img.shields.io/npm/dt/cursor-delegate-mcp)](https://www.npmjs.com/package/cursor-delegate-mcp)
7
7
  [![node](https://img.shields.io/node/v/cursor-delegate-mcp)](https://nodejs.org)
8
8
  [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
+ [![tests](https://github.com/andreilungeanu/cursor-delegate-mcp/actions/workflows/test.yml/badge.svg)](https://github.com/andreilungeanu/cursor-delegate-mcp/actions/workflows/test.yml)
9
10
 
10
- An MCP server that lets Claude Code (or any MCP client) delegate coding tasks to **Cursor's CLI agent** — and get structured results back, not a wall of terminal text.
11
+ <img src="assets/logo-light.png" alt="Cursor Delegate MCP logo" width="150" align="left" hspace="15">
12
+
13
+ Use your best coding agent where its judgment matters most: understanding the task, shaping the plan, and reviewing the result.
14
+
15
+ Cursor Delegate is the MCP bridge that lets Claude Code, ChatGPT/Codex, Copilot — or any MCP client — hand implementation to **Cursor's CLI agent**, then get a clean, structured result back for review.
16
+
17
+ <br clear="left">
11
18
 
12
19
  ![Demo](demo.gif)
13
20
 
14
- ## Why
21
+ ## 🧠 Frontier quality, kept
22
+
23
+ Your assistant does what frontier models are actually for: understands the task, writes a precise brief, reviews the finished diff. And **Composer 2.5** holds its own — a seriously capable coding model, just guided and checked by a smarter one. The result reads like frontier work, because a frontier model planned it and signed off on it.
24
+
25
+ ## ⚡ Done faster
15
26
 
16
- Frontier models like **Opus** and **Fable** are brilliant orchestrators — great at understanding intent, planning, and reviewing. Cursor's **Composer** is a fast, cheap workhorse for the actual edits, with its own generous usage pool.
27
+ Composer 2.5 is built for speed. It tears through multi-file edits while a frontier model would still be streaming the first file. You delegate, keep working with your assistant, and the diff shows up done.
17
28
 
18
- This bridge pairs them: the big brain writes the brief and reviews the diff; Cursor does the typing. Your Claude quota goes to thinking, not boilerplate.
29
+ ## 🔋 Your limits stop being the bottleneck
19
30
 
20
- ## How it works
31
+ Delegated work bills to Composer's **own usage pool** — separate from Cursor's API-priced main quota, and so generous most users never hit its ceiling. Your Claude or Codex subscription spends tokens only on the brief and the review, so the 5-hour window and weekly limits go a lot further. On API? That's the per-token grind moved off your bill.
21
32
 
22
33
  ```
23
- You → Claude (Opus / Fable — plans & reviews)
34
+ You → your agent (plans & reviews)
24
35
  │ MCP delegate tool
25
36
  ▼
26
37
  cursor-agent (Composer 2.5 — implements)
27
38
  │ edits your workspace
28
39
  ▼
29
- Structured result: files changed, session id, plan
40
+ Clean result: what changed, which files, the plan
30
41
  ```
31
42
 
32
- Delegation defaults to Cursor's **Composer 2.5**, which draws from the separate **Auto + Composer** usage pool — so implementation work doesn't eat into your API-model quota. Want a different model? Just say so: *"delegate with Opus"*.
33
-
34
- **Three modes:** `agent` (implement, default) · `plan` (draft a plan, review, resume to implement) · `ask` (read-only Q&A).
35
-
36
- > **Note:** delegation auto-approves file writes in the target workspace — review the diff afterward, like any teammate's work.
37
-
38
43
  ## Features
39
44
 
40
- - 🤝 **Perfect Claude Code integration** — ships as a plugin with a skill, slash command, and hooks. Just say *"delegate this to Cursor"* and it happens.
41
- - 💬 **Answers Cursor's questions** — when Cursor needs a clarification mid-run, the question surfaces in your client's normal prompt. No stalled sessions.
42
- - 📦 **Structured results** — final agent response, result source, session id, files changed, stop reason, and plan payload. Claude knows exactly what happened and what to review.
43
- - 📋 **Plan mode** — have Cursor draft a plan first, review it, then resume the same session to implement.
44
- - 🔍 **Ask mode** — read-only Q&A over the codebase, zero file changes.
45
- - 🩺 **Built-in diagnostics** — a `doctor` tool that tells you exactly what's missing if setup isn't right.
46
- - 🔌 **Works everywhere MCP does** — Claude Code, VS Code, Codex CLI, Kiro, Kilo Code, and more.
45
+ - 🤝 **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.
46
+ - 💬 **No stalled runs** — if Cursor asks a question mid-task, it pops up as a normal prompt in your client. In clients without that support, the recommended option is picked automatically and reported back, so nothing hangs.
47
+ - 📦 **Clean, typed results** — final answer, changed files, session id, and the plan, returned as validated structured output. Nothing to parse, nothing to guess.
48
+ - 📋 **Plan first** — `plan` mode: Cursor drafts a plan, you review it, then the same session implements it.
49
+ - 🔍 **Ask anything** — `ask` mode: read-only Q&A over your codebase, zero file changes.
50
+ - 🩺 **Self-diagnosing** — a `doctor` tool that tells you exactly what's missing if setup isn't right.
51
+ - 🔌 **Works everywhere MCP does** — VS Code, JetBrains, Windsurf, Visual Studio, and more.
47
52
 
48
53
  ## Quick start
49
54
 
50
- **Requirements:** [Node.js 22+](https://nodejs.org/) and [cursor-agent](https://cursor.com/docs/cli/overview) logged in (`cursor-agent login`).
55
+ You need [Node.js 22+](https://nodejs.org/) and the [Cursor CLI](https://cursor.com/docs/cli/overview), logged in (`cursor-agent login`).
51
56
 
52
- ### Claude Code (recommended)
57
+ ### Claude Code
53
58
 
54
59
  ```shell
55
60
  /plugin marketplace add andreilungeanu/cursor-delegate-mcp
@@ -60,22 +65,23 @@ Then just ask:
60
65
 
61
66
  > Delegate to Cursor: migrate src/api from callbacks to async/await and update the tests, then walk me through what changed.
62
67
 
63
- Claude writes the brief, Cursor grinds through the files, and Claude reviews the diff with you — that's the whole loop.
68
+ That's the whole loop — Claude writes the brief, Cursor grinds through the files, Claude walks you through the diff.
64
69
 
70
+ ### ChatGPT desktop / Codex
65
71
 
66
- ### Any other MCP client
72
+ ```shell
73
+ codex plugin marketplace add andreilungeanu/cursor-delegate-mcp
74
+ codex plugin add cursor-delegate-mcp@cursor-delegate-mcp
75
+ ```
67
76
 
68
- ```json
69
- {
70
- "mcpServers": {
71
- "cursor-delegate-mcp": {
72
- "command": "npx",
73
- "args": ["-y", "cursor-delegate-mcp"]
74
- }
75
- }
76
- }
77
+ ### GitHub Copilot CLI
78
+
79
+ ```shell
80
+ copilot plugin install andreilungeanu/cursor-delegate-mcp
77
81
  ```
78
82
 
83
+ ### More clients
84
+
79
85
  <details>
80
86
  <summary><strong>VS Code</strong> — <code>.vscode/mcp.json</code></summary>
81
87
 
@@ -91,21 +97,19 @@ Claude writes the brief, Cursor grinds through the files, and Claude reviews the
91
97
  }
92
98
  ```
93
99
 
100
+ Or run **Chat: Install Plugin From Source** with this repository's URL.
101
+
94
102
  </details>
95
103
 
96
104
  <details>
97
- <summary><strong>Codex CLI</strong> — <code>~/.codex/config.toml</code></summary>
105
+ <summary><strong>JetBrains AI Assistant</strong> — Settings → Tools → AI Assistant → MCP</summary>
98
106
 
99
- ```toml
100
- [mcp_servers.cursor-delegate-mcp]
101
- command = "npx"
102
- args = ["-y", "cursor-delegate-mcp"]
103
- ```
107
+ Under **Settings → Tools → AI Assistant → Model Context Protocol (MCP)**, add a server with command `npx` and arguments `-y cursor-delegate-mcp`.
104
108
 
105
109
  </details>
106
110
 
107
111
  <details>
108
- <summary><strong>Kiro</strong> — <code>~/.kiro/settings/mcp.json</code></summary>
112
+ <summary><strong>Windsurf</strong> — <code>~/.codeium/windsurf/mcp_config.json</code></summary>
109
113
 
110
114
  ```json
111
115
  {
@@ -118,27 +122,32 @@ args = ["-y", "cursor-delegate-mcp"]
118
122
  }
119
123
  ```
120
124
 
125
+ Heads-up: Cascade caps you at 100 tools across all servers.
126
+
121
127
  </details>
122
128
 
123
129
  <details>
124
- <summary><strong>Kilo Code</strong> — <code>~/.config/kilo/kilo.jsonc</code></summary>
130
+ <summary><strong>Visual Studio 2022</strong> — <code>%USERPROFILE%\.mcp.json</code></summary>
125
131
 
126
- ```jsonc
132
+ ```json
127
133
  {
128
- "mcp": {
134
+ "servers": {
129
135
  "cursor-delegate-mcp": {
130
- "type": "local",
131
- "command": ["npx", "-y", "cursor-delegate-mcp"],
132
- "enabled": true
136
+ "type": "stdio",
137
+ "command": "npx",
138
+ "args": ["-y", "cursor-delegate-mcp"]
133
139
  }
134
140
  }
135
141
  }
136
142
  ```
137
143
 
144
+ Requires 17.14+. Note the top-level key is `servers`, not `mcpServers`.
145
+
138
146
  </details>
139
147
 
140
- <details>
141
- <summary><strong>Antigravity 2.0</strong> — <code>~/.gemini/config/mcp_config.json</code></summary>
148
+ ### Kiro, Kilo Code, and any other MCP client
149
+
150
+ Add the following server to the client's MCP config:
142
151
 
143
152
  ```json
144
153
  {
@@ -151,10 +160,8 @@ args = ["-y", "cursor-delegate-mcp"]
151
160
  }
152
161
  ```
153
162
 
154
- </details>
155
-
156
- Call the **`delegate`** tool with your task; run **`doctor`** if anything seems off.
157
-
158
163
  ## License
159
164
 
160
165
  MIT © [Andrei Lungeanu](https://github.com/andreilungeanu)
166
+
167
+ <sub>[Security](SECURITY.md) · [Privacy](PRIVACY.md) · [Terms](TERMS.md) · [Changelog](CHANGELOG.md)</sub>
package/SECURITY.md ADDED
@@ -0,0 +1,26 @@
1
+ # Security
2
+
3
+ ## What this plugin does
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.
8
+
9
+ Treat every `delegate` call like handing an engineer write access to that tree.
10
+
11
+ ## Recommendations
12
+
13
+ - Point `workspace` at the smallest directory that contains the task (not `$HOME` or `/`).
14
+ - Review `touchedFiles` and the git diff before committing.
15
+ - Use `mode: "plan"` when you only want a plan, not file changes.
16
+ - Run verification (tests, lint) after delegation — the delegate skill asks Claude to do
17
+ this, but automated gates in CI are still your backstop.
18
+ - Do not commit secrets (`.env`, credentials, tokens). The bridge does not redact them from
19
+ agent context.
20
+
21
+ ## Reporting vulnerabilities
22
+
23
+ If you find a security issue in this bridge (not in cursor-agent or an MCP host),
24
+ please open a [GitHub Security Advisory](https://github.com/andreilungeanu/cursor-delegate-mcp/security/advisories/new)
25
+ or email the maintainer listed in `package.json` instead of filing a public issue with
26
+ exploit details.
package/TERMS.md ADDED
@@ -0,0 +1,9 @@
1
+ # Terms of Use
2
+
3
+ Cursor Delegate MCP is provided under the MIT License on an "as is" basis, without warranties or guarantees.
4
+
5
+ The plugin runs locally and starts `cursor-agent` with access to the workspace selected for a delegation. Delegated agent-mode tasks may create, modify, or delete files. You are responsible for choosing an appropriate workspace, reviewing changes, protecting credentials, and complying with the terms that apply to Cursor, your MCP host, and any model you select.
6
+
7
+ The project author does not operate the Cursor service, receive delegated source code, or control the behavior of third-party models and clients. Do not use the plugin for unlawful activity or in a way that violates third-party rights or service terms.
8
+
9
+ For support, open a [GitHub issue](https://github.com/andreilungeanu/cursor-delegate-mcp/issues). For security reports, follow [SECURITY.md](SECURITY.md).
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "cursor-delegate-mcp",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
- "description": "MCP server bridging Claude Code to cursor-agent over the Agent Client Protocol (ACP).",
5
+ "description": "MCP server bridging AI coding hosts to cursor-agent over the Agent Client Protocol (ACP).",
6
6
  "license": "MIT",
7
7
  "author": "Andrei Lungeanu <andrei@lungeanu.ro>",
8
8
  "repository": {
@@ -20,6 +20,10 @@
20
20
  "acp",
21
21
  "agent-client-protocol",
22
22
  "claude-code",
23
+ "codex",
24
+ "chatgpt",
25
+ "github-copilot",
26
+ "vscode",
23
27
  "composer"
24
28
  ],
25
29
  "main": "src/server.js",
@@ -32,14 +36,18 @@
32
36
  "files": [
33
37
  "src",
34
38
  "README.md",
39
+ "PRIVACY.md",
40
+ "SECURITY.md",
41
+ "TERMS.md",
35
42
  "LICENSE"
36
43
  ],
37
44
  "scripts": {
38
45
  "test": "node --test test/*.test.js",
46
+ "test:pack": "node test/npm-package-smoke.mjs",
39
47
  "start": "node src/server.js"
40
48
  },
41
49
  "dependencies": {
42
- "@modelcontextprotocol/sdk": "^1.12.0",
50
+ "@modelcontextprotocol/sdk": "^1.22.0",
43
51
  "zod": "^3.23.8"
44
52
  }
45
53
  }
package/src/acp-client.js CHANGED
@@ -57,7 +57,7 @@ export class AcpClient extends EventEmitter {
57
57
  });
58
58
  return new Promise((resolve, reject) => {
59
59
  this.child.once("error", (e) =>
60
- reject(new Error(`Failed to spawn agent (${command}): ${e.message}. Install Cursor CLI and run 'agent login'.`)));
60
+ reject(new Error(`Failed to spawn agent (${command}): ${e.message}. Install Cursor CLI and run 'cursor-agent login'.`)));
61
61
  this.child.once("spawn", () => resolve());
62
62
  });
63
63
  }
package/src/delegate.js CHANGED
@@ -26,7 +26,7 @@ async function openSession(client, resumeSessionId, workspace) {
26
26
  }
27
27
 
28
28
  // Composer bare ids (e.g. composer-2.5) expose standard vs fast via set_config_option.
29
- // Other models use separate ids (e.g. gpt-5-fast) — see agent --list-models.
29
+ // Other models use separate ids (e.g. gpt-5-fast) — see cursor-agent --list-models.
30
30
  function composerFastToggleApplies(model) {
31
31
  return /^composer-\d+(?:\.\d+)?$/i.test(model);
32
32
  }
@@ -44,7 +44,7 @@ export async function runDelegate({
44
44
  const recordQuestions = (q) => {
45
45
  if (q.kind !== "ask_question") return;
46
46
  for (const question of q.questions || []) {
47
- if (question?.prompt) questionsAsked.push(question.prompt);
47
+ if (typeof question?.prompt === "string" && question.prompt) questionsAsked.push(question.prompt);
48
48
  }
49
49
  };
50
50
  const wrappedElicit = onElicit
@@ -59,6 +59,41 @@ export async function runDelegate({
59
59
  if (body?.plan !== undefined) planDetail = body.plan;
60
60
  };
61
61
 
62
+ // ACP requires plan entry content to be a string and bounds priority/status to
63
+ // known values. Frames that violate that must not fail the MCP call after the
64
+ // work is done — drop the bad data and report it as a protocol diagnostic.
65
+ const PLAN_PRIORITIES = ["high", "medium", "low"];
66
+ const PLAN_STATUSES = ["pending", "in_progress", "completed"];
67
+ const sanitizePlan = (warnings) => {
68
+ const entries = [];
69
+ planEntries.forEach((raw, i) => {
70
+ if (typeof raw?.content !== "string") {
71
+ warnings.push(`plan entry ${i} dropped: ACP requires string content, got ${raw === null ? "null" : typeof raw?.content}`);
72
+ return;
73
+ }
74
+ const entry = { ...raw };
75
+ if (entry.priority !== undefined && !PLAN_PRIORITIES.includes(entry.priority)) {
76
+ warnings.push(`plan entry ${i}: non-ACP priority ${JSON.stringify(entry.priority)} removed`);
77
+ delete entry.priority;
78
+ }
79
+ if (entry.status !== undefined && !PLAN_STATUSES.includes(entry.status)) {
80
+ warnings.push(`plan entry ${i}: non-ACP status ${JSON.stringify(entry.status)} removed`);
81
+ delete entry.status;
82
+ }
83
+ entries.push(entry);
84
+ });
85
+ const plan = { entries };
86
+ if (planOverview !== undefined) {
87
+ if (typeof planOverview === "string") plan.overview = planOverview;
88
+ else warnings.push("plan overview dropped: expected string");
89
+ }
90
+ if (planDetail !== undefined) {
91
+ if (typeof planDetail === "string") plan.detail = planDetail;
92
+ else warnings.push("plan detail dropped: expected string");
93
+ }
94
+ return plan;
95
+ };
96
+
62
97
  const make = clientFactory || ((opts) => new AcpClient(opts));
63
98
  const client = make({ onElicit: wrappedElicit, mode, onCreatePlan: recordCreatePlan });
64
99
  const supervisor = new SessionSupervisor(client, { idleMs, hardCapMs: capMs, cancelGraceMs, killGraceMs });
@@ -218,11 +253,17 @@ export async function runDelegate({
218
253
  : "none";
219
254
  const gitAfter = gitChangedSet(workspace);
220
255
  const touchedResult = computeTouched({ before: gitBefore, after: gitAfter, diffTouched: [...touched], workspace });
256
+ const protocolWarnings = [];
257
+ let stopReason;
258
+ if (res?.stopReason !== undefined) {
259
+ if (typeof res.stopReason === "string") stopReason = res.stopReason;
260
+ else protocolWarnings.push("stopReason dropped: ACP requires a string stop reason");
261
+ }
221
262
  const out = {
222
263
  result,
223
264
  resultSource,
224
265
  finalMessageAvailable,
225
- stopReason: res?.stopReason,
266
+ stopReason,
226
267
  sessionId,
227
268
  touchedFiles: touchedResult.files,
228
269
  touchedFilesSource: touchedResult.source,
@@ -230,8 +271,9 @@ export async function runDelegate({
230
271
  resumed: !!resumeSessionId && sessionId === resumeSessionId,
231
272
  };
232
273
  if (planEntries.length > 0 || planOverview !== undefined || planDetail !== undefined) {
233
- out.plan = { entries: planEntries, overview: planOverview, detail: planDetail };
274
+ out.plan = sanitizePlan(protocolWarnings);
234
275
  }
276
+ if (protocolWarnings.length) out.protocolWarnings = protocolWarnings;
235
277
  return out;
236
278
  } catch (err) {
237
279
  try {
package/src/doctor.js CHANGED
@@ -86,6 +86,13 @@ export async function runDoctor({
86
86
  command: formatCommand(spawnSpec),
87
87
  version: agentProbe.version,
88
88
  },
89
+ runtime: {
90
+ node: process.versions.node,
91
+ platform: process.platform,
92
+ arch: process.arch,
93
+ cwd: process.cwd(),
94
+ transport: "stdio",
95
+ },
89
96
  env: {
90
97
  ACP_LOG_SIZE: process.env.ACP_LOG_SIZE !== undefined ? process.env.ACP_LOG_SIZE : DEFAULT_LOG_SIZE,
91
98
  },
package/src/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import process from "node:process";
3
- import path from "node:path";
3
+ import { realpathSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -17,6 +17,53 @@ if (nodeMajor < 22) {
17
17
 
18
18
  const inFlight = new Map();
19
19
 
20
+ export const SERVER_INSTRUCTIONS = `Delegate coding work to Cursor through the delegate tool. The delegate tool can create, modify, or delete files in its workspace, so scope workspace to the smallest relevant directory and review touchedFiles plus the git diff after every write-capable run. For approval-gated work, call delegate with mode="plan", review the returned plan and sessionId, then resume with mode="agent" and resumeSessionId. Use mode="ask" for read-only questions and doctor for setup diagnostics.`;
21
+
22
+ const planEntrySchema = z.object({
23
+ content: z.string(),
24
+ priority: z.enum(["high", "medium", "low"]).optional(),
25
+ status: z.enum(["pending", "in_progress", "completed"]).optional(),
26
+ }).passthrough();
27
+
28
+ const delegateOutputSchema = z.object({
29
+ result: z.string(),
30
+ resultSource: z.enum(["tool-free-stream", "post-tool", "none"]).optional(),
31
+ finalMessageAvailable: z.boolean().optional(),
32
+ stopReason: z.string().optional(),
33
+ sessionId: z.string(),
34
+ touchedFiles: z.array(z.string()),
35
+ touchedFilesSource: z.enum(["git", "diff-only"]).optional(),
36
+ questionsAsked: z.array(z.string()).optional(),
37
+ resumed: z.boolean().optional(),
38
+ autoAnswered: z.array(z.object({ prompt: z.string(), chosen: z.string() })).optional(),
39
+ fallbackAnswers: z.array(z.object({ prompt: z.string(), given: z.string(), chosen: z.string() })).optional(),
40
+ protocolWarnings: z.array(z.string()).optional(),
41
+ plan: z.object({
42
+ entries: z.array(planEntrySchema),
43
+ overview: z.string().optional(),
44
+ detail: z.string().optional(),
45
+ }).optional(),
46
+ }).passthrough();
47
+
48
+ const doctorOutputSchema = z.object({
49
+ plugin: z.object({ version: z.string() }).passthrough(),
50
+ client: z.object({
51
+ name: z.string().nullable(),
52
+ version: z.string().nullable(),
53
+ capabilities: z.record(z.unknown()),
54
+ supportsElicitation: z.boolean(),
55
+ }).passthrough(),
56
+ agent: z.object({ found: z.boolean() }).passthrough(),
57
+ runtime: z.object({
58
+ node: z.string(),
59
+ platform: z.string(),
60
+ arch: z.string(),
61
+ cwd: z.string(),
62
+ transport: z.literal("stdio"),
63
+ }),
64
+ env: z.record(z.unknown()),
65
+ }).passthrough();
66
+
20
67
  export async function runDelegateTool({ args, extra, server, runDelegate, inFlight }) {
21
68
  const { spec, mode, resumeSessionId, workspace, model, fast } = args;
22
69
 
@@ -45,7 +92,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
45
92
  if (!supportsElicitation) {
46
93
  const chosenOptionId = opts[0]?.id;
47
94
  const chosen = opts.find((o) => o.id === chosenOptionId)?.label || chosenOptionId || "";
48
- autoAnswered.push({ prompt: q.prompt, chosen });
95
+ autoAnswered.push({ prompt: String(q.prompt ?? ""), chosen: String(chosen) });
49
96
  answers.push({ questionId: q.id, selectedOptionIds: [chosenOptionId] });
50
97
  continue;
51
98
  }
@@ -78,7 +125,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
78
125
  }
79
126
  if (!matched && opts.length) {
80
127
  const chosen = opts.find((o) => o.id === chosenOptionId)?.label || chosenOptionId || "";
81
- fallbackAnswers.push({ prompt: q.prompt, given: choice, chosen });
128
+ fallbackAnswers.push({ prompt: String(q.prompt ?? ""), given: String(choice), chosen: String(chosen) });
82
129
  }
83
130
  answers.push({ questionId: q.id, selectedOptionIds: [chosenOptionId] });
84
131
  }
@@ -120,13 +167,16 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
120
167
  export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDoctorInjected } = {}) {
121
168
  const runDelegate = runDelegateInjected || runDelegateDefault;
122
169
  const runDoctor = runDoctorInjected || runDoctorDefault;
123
- const server = new McpServer({ name: "cursor-delegate-mcp", version: VERSION });
170
+ const server = new McpServer(
171
+ { name: "cursor-delegate-mcp", version: VERSION },
172
+ { instructions: SERVER_INSTRUCTIONS }
173
+ );
124
174
 
125
175
  server.registerTool(
126
176
  "delegate",
127
177
  {
128
178
  description:
129
- "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=composer-2.5, fast=false. Plan workflow: mode=plan, then resume with mode=agent and resumeSessionId. Auto-approves writes in workspace; surfaces clarifying questions via elicitation. Returns the final agent result selected after the last tool call, resultSource, finalMessageAvailable, stopReason, sessionId, touchedFiles, and plan (in plan mode). See plugin delegate skill for orchestration.",
179
+ "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=composer-2.5, fast=false. Plan workflow: mode=plan, then resume with mode=agent and resumeSessionId. Auto-approves writes in workspace; uses MCP elicitation for clarifying questions and selects the first option when the client lacks elicitation. Returns the final result, selection source, stop reason, session ID, changed files, and optional plan. See the delegate skill for orchestration.",
130
180
  inputSchema: {
131
181
  spec: z.string().describe("Inline task brief (default): goal, scope, acceptance criteria. Optional file path if the user wants a persisted spec."),
132
182
  mode: z.enum(["agent", "plan", "ask"]).default("agent"),
@@ -135,6 +185,14 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
135
185
  model: z.string().default("composer-2.5"),
136
186
  fast: z.boolean().default(false).describe("Fast speed tier — higher cost; enable only when the user asks"),
137
187
  },
188
+ outputSchema: delegateOutputSchema,
189
+ annotations: {
190
+ title: "Delegate coding task to Cursor",
191
+ readOnlyHint: false,
192
+ destructiveHint: true,
193
+ idempotentHint: false,
194
+ openWorldHint: true,
195
+ },
138
196
  },
139
197
  async (args, extra) => runDelegateTool({ args, extra, server, runDelegate, inFlight })
140
198
  );
@@ -142,15 +200,32 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
142
200
  // cancel is best-effort: MCP tool calls are serialized, so delegate must finish first.
143
201
  server.registerTool(
144
202
  "cancel",
145
- { description: "Cancel an in-flight ACP delegation by sessionId.", inputSchema: { sessionId: z.string() } },
203
+ {
204
+ description: "Cancel an in-flight ACP delegation by sessionId.",
205
+ inputSchema: { sessionId: z.string() },
206
+ outputSchema: z.object({ status: z.enum(["cancelled", "not-found"]), sessionId: z.string() }),
207
+ annotations: {
208
+ title: "Cancel Cursor delegation",
209
+ readOnlyHint: false,
210
+ destructiveHint: true,
211
+ idempotentHint: true,
212
+ openWorldHint: false,
213
+ },
214
+ },
146
215
  async ({ sessionId }) => {
147
216
  const client = inFlight.get(sessionId);
148
217
  if (client) {
149
218
  await client.cancel(sessionId).catch(() => {});
150
219
  inFlight.delete(sessionId);
151
- return { content: [{ type: "text", text: `cancelled ${sessionId}` }] };
220
+ return {
221
+ content: [{ type: "text", text: `cancelled ${sessionId}` }],
222
+ structuredContent: { status: "cancelled", sessionId },
223
+ };
152
224
  }
153
- return { content: [{ type: "text", text: `no in-flight session ${sessionId}` }] };
225
+ return {
226
+ content: [{ type: "text", text: `no in-flight session ${sessionId}` }],
227
+ structuredContent: { status: "not-found", sessionId },
228
+ };
154
229
  }
155
230
  );
156
231
 
@@ -165,6 +240,14 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
165
240
  .default(false)
166
241
  .describe("When true, run a lightweight ACP handshake (start → initialize → newSession) to verify the agent is usable"),
167
242
  },
243
+ outputSchema: doctorOutputSchema,
244
+ annotations: {
245
+ title: "Diagnose Cursor delegation setup",
246
+ readOnlyHint: true,
247
+ destructiveHint: false,
248
+ idempotentHint: true,
249
+ openWorldHint: false,
250
+ },
168
251
  },
169
252
  async ({ deep }) => {
170
253
  const out = await runDoctor({
@@ -174,7 +257,10 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
174
257
  version: server.server.getClientVersion(),
175
258
  }),
176
259
  });
177
- return { content: [{ type: "text", text: JSON.stringify(out, null, 2) }] };
260
+ return {
261
+ content: [{ type: "text", text: JSON.stringify(out, null, 2) }],
262
+ structuredContent: out,
263
+ };
178
264
  }
179
265
  );
180
266
 
@@ -182,7 +268,14 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
182
268
  }
183
269
 
184
270
  const __filename = fileURLToPath(import.meta.url);
185
- const isMain = process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename);
271
+ let isMain = false;
272
+ if (process.argv[1]) {
273
+ try {
274
+ isMain = realpathSync(process.argv[1]) === realpathSync(__filename);
275
+ } catch {
276
+ // An imported module must not fail just because argv[1] is not a file.
277
+ }
278
+ }
186
279
 
187
280
  if (isMain) {
188
281
  const server = buildServer();
package/src/spawn.js CHANGED
@@ -10,7 +10,7 @@ export function splitArgs(raw) {
10
10
  }
11
11
 
12
12
  export function resolveAcpSpawn() {
13
- const command = process.env.ACP_AGENT_COMMAND || "agent";
13
+ const command = process.env.ACP_AGENT_COMMAND || "cursor-agent";
14
14
  const args = process.env.ACP_AGENT_ARGS
15
15
  ? splitArgs(process.env.ACP_AGENT_ARGS)
16
16
  : ["acp"];