cursor-delegate-mcp 1.1.0 → 1.3.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 +66 -76
- package/package.json +3 -3
- package/src/acp-client.js +11 -9
- package/src/delegate.js +45 -9
- package/src/doctor.js +4 -8
- package/src/proc.js +18 -0
- package/src/server.js +16 -10
- package/src/session-supervisor.js +1 -16
- package/src/spawn.js +18 -9
- package/src/version.js +7 -0
package/README.md
CHANGED
|
@@ -1,89 +1,69 @@
|
|
|
1
1
|
# Cursor Delegate MCP
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Let Claude think. Let Cursor build.**
|
|
4
4
|
|
|
5
|
-
](https://www.npmjs.com/package/cursor-delegate-mcp)
|
|
6
|
+
[](https://www.npmjs.com/package/cursor-delegate-mcp)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](LICENSE)
|
|
18
9
|
|
|
19
|
-
|
|
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.
|
|
20
11
|
|
|
21
|
-
|
|
12
|
+

|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
- [cursor-agent](https://cursor.com/docs/cli/overview) installed and logged in (`cursor-agent login`)
|
|
14
|
+
## Why
|
|
25
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
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
19
|
|
|
30
|
-
|
|
20
|
+
## How it works
|
|
31
21
|
|
|
32
|
-
```
|
|
33
|
-
/
|
|
34
|
-
|
|
22
|
+
```
|
|
23
|
+
You → Claude (Opus / Fable — plans & reviews)
|
|
24
|
+
│ MCP delegate tool
|
|
25
|
+
▼
|
|
26
|
+
cursor-agent (Composer 2.5 — implements)
|
|
27
|
+
│ edits your workspace
|
|
28
|
+
▼
|
|
29
|
+
Structured result: files changed, session id, plan
|
|
35
30
|
```
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Use it
|
|
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"*.
|
|
40
33
|
|
|
41
|
-
|
|
34
|
+
**Three modes:** `agent` (implement, default) · `plan` (draft a plan, review, resume to implement) · `ask` (read-only Q&A).
|
|
42
35
|
|
|
43
|
-
>
|
|
36
|
+
> **Note:** delegation auto-approves file writes in the target workspace — review the diff afterward, like any teammate's work.
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
## Features
|
|
46
39
|
|
|
47
|
-
|
|
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** — 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.
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
/cursor-delegate-mcp:delegate Add input validation to the signup form and a test for it
|
|
51
|
-
```
|
|
48
|
+
## Quick start
|
|
52
49
|
|
|
53
|
-
**
|
|
50
|
+
**Requirements:** [Node.js 22+](https://nodejs.org/) and [cursor-agent](https://cursor.com/docs/cli/overview) logged in (`cursor-agent login`).
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Use the same server in **any** MCP-compatible client via npx — no Claude Code plugin required:
|
|
52
|
+
### Claude Code (recommended)
|
|
58
53
|
|
|
59
54
|
```shell
|
|
60
|
-
|
|
55
|
+
/plugin marketplace add andreilungeanu/cursor-delegate-mcp
|
|
56
|
+
/plugin install cursor-delegate-mcp@cursor-delegate-mcp
|
|
61
57
|
```
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Clarifying-question prompts are interactive only on elicitation-capable clients (Claude Code, Cursor, VS Code). On other clients the recommended option is auto-selected and reported in the delegate result's `autoAnswered`.
|
|
66
|
-
|
|
67
|
-
### Client configuration
|
|
59
|
+
Then just ask:
|
|
68
60
|
|
|
69
|
-
|
|
61
|
+
> Delegate to Cursor: migrate src/api from callbacks to async/await and update the tests, then walk me through what changed.
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```json
|
|
74
|
-
{
|
|
75
|
-
"mcpServers": {
|
|
76
|
-
"cursor-delegate-mcp": {
|
|
77
|
-
"command": "npx",
|
|
78
|
-
"args": ["-y", "cursor-delegate-mcp"]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
```
|
|
63
|
+
Claude writes the brief, Cursor grinds through the files, and Claude reviews the diff with you — that's the whole loop.
|
|
83
64
|
|
|
84
|
-
#### Cursor
|
|
85
65
|
|
|
86
|
-
|
|
66
|
+
### Any other MCP client
|
|
87
67
|
|
|
88
68
|
```json
|
|
89
69
|
{
|
|
@@ -96,9 +76,8 @@ Clarifying-question prompts are interactive only on elicitation-capable clients
|
|
|
96
76
|
}
|
|
97
77
|
```
|
|
98
78
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
`.vscode/mcp.json`:
|
|
79
|
+
<details>
|
|
80
|
+
<summary><strong>VS Code</strong> — <code>.vscode/mcp.json</code></summary>
|
|
102
81
|
|
|
103
82
|
```json
|
|
104
83
|
{
|
|
@@ -112,9 +91,10 @@ Clarifying-question prompts are interactive only on elicitation-capable clients
|
|
|
112
91
|
}
|
|
113
92
|
```
|
|
114
93
|
|
|
115
|
-
|
|
94
|
+
</details>
|
|
116
95
|
|
|
117
|
-
|
|
96
|
+
<details>
|
|
97
|
+
<summary><strong>Codex CLI</strong> — <code>~/.codex/config.toml</code></summary>
|
|
118
98
|
|
|
119
99
|
```toml
|
|
120
100
|
[mcp_servers.cursor-delegate-mcp]
|
|
@@ -122,9 +102,10 @@ command = "npx"
|
|
|
122
102
|
args = ["-y", "cursor-delegate-mcp"]
|
|
123
103
|
```
|
|
124
104
|
|
|
125
|
-
|
|
105
|
+
</details>
|
|
126
106
|
|
|
127
|
-
|
|
107
|
+
<details>
|
|
108
|
+
<summary><strong>Kiro</strong> — <code>~/.kiro/settings/mcp.json</code></summary>
|
|
128
109
|
|
|
129
110
|
```json
|
|
130
111
|
{
|
|
@@ -137,9 +118,10 @@ args = ["-y", "cursor-delegate-mcp"]
|
|
|
137
118
|
}
|
|
138
119
|
```
|
|
139
120
|
|
|
140
|
-
|
|
121
|
+
</details>
|
|
141
122
|
|
|
142
|
-
|
|
123
|
+
<details>
|
|
124
|
+
<summary><strong>Kilo Code</strong> — <code>~/.config/kilo/kilo.jsonc</code></summary>
|
|
143
125
|
|
|
144
126
|
```jsonc
|
|
145
127
|
{
|
|
@@ -153,18 +135,26 @@ args = ["-y", "cursor-delegate-mcp"]
|
|
|
153
135
|
}
|
|
154
136
|
```
|
|
155
137
|
|
|
156
|
-
|
|
138
|
+
</details>
|
|
157
139
|
|
|
158
|
-
|
|
140
|
+
<details>
|
|
141
|
+
<summary><strong>Antigravity 2.0</strong> — <code>~/.gemini/config/mcp_config.json</code></summary>
|
|
159
142
|
|
|
160
|
-
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"mcpServers": {
|
|
146
|
+
"cursor-delegate-mcp": {
|
|
147
|
+
"command": "npx",
|
|
148
|
+
"args": ["-y", "cursor-delegate-mcp"]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
161
153
|
|
|
162
|
-
|
|
163
|
-
- **Plan** — Cursor drafts a plan first; review it, then resume and implement.
|
|
164
|
-
- **Ask** — Read-only Q&A over the codebase; no file changes.
|
|
154
|
+
</details>
|
|
165
155
|
|
|
166
|
-
|
|
156
|
+
Call the **`delegate`** tool with your task; run **`doctor`** if anything seems off.
|
|
167
157
|
|
|
168
158
|
## License
|
|
169
159
|
|
|
170
|
-
MIT © Andrei Lungeanu
|
|
160
|
+
MIT © [Andrei Lungeanu](https://github.com/andreilungeanu)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server bridging Claude Code to cursor-agent over the Agent Client Protocol (ACP).",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"author": "Andrei Lungeanu <
|
|
7
|
+
"author": "Andrei Lungeanu <andrei@lungeanu.ro>",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/andreilungeanu/cursor-delegate-mcp.git"
|
|
10
|
+
"url": "git+https://github.com/andreilungeanu/cursor-delegate-mcp.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/andreilungeanu/cursor-delegate-mcp/issues"
|
package/src/acp-client.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
3
|
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
7
4
|
import { createRequestRouter } from "./request-router.js";
|
|
8
5
|
import { resolveAcpSpawn } from "./spawn.js";
|
|
6
|
+
import { isChildAlive, treeKill } from "./proc.js";
|
|
7
|
+
import { VERSION } from "./version.js";
|
|
9
8
|
|
|
10
9
|
const STDERR_CAP = 64 * 1024;
|
|
11
10
|
|
|
12
|
-
const VERSION = JSON.parse(
|
|
13
|
-
readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8")
|
|
14
|
-
).version;
|
|
15
|
-
|
|
16
11
|
export class AcpClient extends EventEmitter {
|
|
17
12
|
constructor({ spawnSpec, onElicit, mode, onCreatePlan } = {}) {
|
|
18
13
|
super();
|
|
@@ -71,12 +66,19 @@ export class AcpClient extends EventEmitter {
|
|
|
71
66
|
newSession(cwd) { return this.peer.request("session/new", { cwd, mcpServers: [] }); }
|
|
72
67
|
loadSession(sessionId, cwd) { return this.peer.request("session/load", { sessionId, cwd, mcpServers: [] }); }
|
|
73
68
|
setModel(sessionId, modelId) { return this.peer.request("session/set_model", { sessionId, modelId }); }
|
|
74
|
-
setFast(sessionId, value) { return this.peer.request("session/set_config_option", { sessionId, configId: "fast", value }); } // configId, not optionId
|
|
69
|
+
setFast(sessionId, value) { return this.peer.request("session/set_config_option", { sessionId, configId: "fast", value: String(value) }); } // configId, not optionId; ACP wants a string value
|
|
75
70
|
setMode(sessionId, modeId) { return this.peer.request("session/set_mode", { sessionId, modeId }); }
|
|
76
71
|
prompt(sessionId, text) { return this.peer.request("session/prompt", { sessionId, prompt: [{ type: "text", text }] }); }
|
|
77
72
|
cancel(sessionId) { this.peer.notify("session/cancel", { sessionId }); return Promise.resolve(); }
|
|
78
73
|
|
|
79
74
|
getTranscript(n) { return this.peer ? this.peer.formatLog(n) : ""; }
|
|
80
75
|
|
|
81
|
-
stop() {
|
|
76
|
+
stop() {
|
|
77
|
+
try { this.peer?.close(); } catch {}
|
|
78
|
+
if (isChildAlive(this.child) && process.platform === "win32" && this.child.pid) {
|
|
79
|
+
treeKill(this.child.pid).catch(() => {});
|
|
80
|
+
} else {
|
|
81
|
+
try { this.child?.kill(); } catch {}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
82
84
|
}
|
package/src/delegate.js
CHANGED
|
@@ -33,9 +33,9 @@ function composerFastToggleApplies(model) {
|
|
|
33
33
|
|
|
34
34
|
export async function runDelegate({
|
|
35
35
|
spec, mode = "agent", resumeSessionId, workspace,
|
|
36
|
-
model = "composer-2.5", fast =
|
|
36
|
+
model = "composer-2.5", fast = false, clientFactory, onElicit,
|
|
37
37
|
idleMs = 90000, hardCapMs, timeoutMs, cancelGraceMs = 10000, killGraceMs = 5000,
|
|
38
|
-
onSessionReady, onProgress, gitChangedSet = gitChangedSetReal,
|
|
38
|
+
onSessionReady, onProgress, progressThrottleMs = 2000, gitChangedSet = gitChangedSetReal,
|
|
39
39
|
} = {}) {
|
|
40
40
|
const capMs = hardCapMs ?? timeoutMs ?? 3600000;
|
|
41
41
|
const MAX_OUTPUT = 10 * 1024 * 1024;
|
|
@@ -67,19 +67,52 @@ export async function runDelegate({
|
|
|
67
67
|
let textLength = 0;
|
|
68
68
|
let truncated = false;
|
|
69
69
|
const touched = new Set();
|
|
70
|
+
|
|
71
|
+
// Each stream reports its newest complete sentence, at most one per throttle window.
|
|
72
|
+
// Capital-letter boundary: cursor-agent thoughts arrive as sentences with no separator.
|
|
73
|
+
const SENTENCE_END = /[.!?](?=\s|[A-Z])|\n/;
|
|
74
|
+
const MARKDOWN_LINE = /^(?:[|#>`~*_=+-]|\d+[.)]\s)/;
|
|
75
|
+
const progressStream = (prefix) => {
|
|
76
|
+
let buf = "", pending = null, lastEmit = 0;
|
|
77
|
+
const flush = (force) => {
|
|
78
|
+
if (pending === null || (!force && Date.now() - lastEmit < progressThrottleMs)) return;
|
|
79
|
+
lastEmit = Date.now();
|
|
80
|
+
try { onProgress?.(prefix + pending); } catch {}
|
|
81
|
+
pending = null;
|
|
82
|
+
};
|
|
83
|
+
const take = (s) => {
|
|
84
|
+
const line = s.replace(/\s+/g, " ").trim().slice(0, 200);
|
|
85
|
+
if (line.length > 3 && !MARKDOWN_LINE.test(line)) pending = line;
|
|
86
|
+
flush(false);
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
push(text) {
|
|
90
|
+
buf += text;
|
|
91
|
+
for (let m; (m = SENTENCE_END.exec(buf)); buf = buf.slice(m.index + 1)) {
|
|
92
|
+
take(buf.slice(0, m.index + 1));
|
|
93
|
+
}
|
|
94
|
+
if (buf.length > 300) { take(buf); buf = ""; }
|
|
95
|
+
},
|
|
96
|
+
end() { take(buf); buf = ""; flush(true); },
|
|
97
|
+
reset() { buf = ""; pending = null; },
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const thoughtProgress = progressStream("thinking: ");
|
|
101
|
+
const messageProgress = progressStream("Cursor: ");
|
|
102
|
+
|
|
70
103
|
client.on("update", (u) => {
|
|
71
104
|
const up = u?.update || {};
|
|
72
105
|
if (up.sessionUpdate === "plan") {
|
|
73
106
|
planEntries = up.entries || [];
|
|
74
107
|
}
|
|
75
108
|
if (up.sessionUpdate === "agent_thought_chunk" && up.content?.text) {
|
|
76
|
-
|
|
77
|
-
const tail = text.length > 200 ? text.slice(-200) : text;
|
|
78
|
-
try { onProgress?.("thinking: " + (tail.trim() || text.slice(0, 200))); } catch {}
|
|
109
|
+
thoughtProgress.push(up.content.text);
|
|
79
110
|
}
|
|
80
111
|
if (up.sessionUpdate === "tool_call") {
|
|
81
112
|
const label = up.title || up.kind || "tool";
|
|
82
|
-
|
|
113
|
+
const path = up.locations?.[0]?.path;
|
|
114
|
+
const line = "running: " + String(label) + (path ? " — " + path : "");
|
|
115
|
+
try { onProgress?.(line.slice(0, 200)); } catch {}
|
|
83
116
|
}
|
|
84
117
|
if (up.sessionUpdate === "agent_message_chunk" && up.content?.text) {
|
|
85
118
|
const text = up.content.text;
|
|
@@ -96,8 +129,7 @@ export async function runDelegate({
|
|
|
96
129
|
truncated = true;
|
|
97
130
|
}
|
|
98
131
|
}
|
|
99
|
-
|
|
100
|
-
try { onProgress?.(tail.trim() || text.slice(0, 200)); } catch {}
|
|
132
|
+
messageProgress.push(text);
|
|
101
133
|
}
|
|
102
134
|
if (up.sessionUpdate === "tool_call_update") {
|
|
103
135
|
for (const c of up.content || []) {
|
|
@@ -111,7 +143,7 @@ export async function runDelegate({
|
|
|
111
143
|
|
|
112
144
|
try {
|
|
113
145
|
let sessionId;
|
|
114
|
-
const gitBefore = gitChangedSet(workspace);
|
|
146
|
+
const gitBefore = gitChangedSet(workspace);
|
|
115
147
|
const res = await supervisor.supervise(async () => {
|
|
116
148
|
await client.start();
|
|
117
149
|
await client.initialize();
|
|
@@ -125,12 +157,16 @@ export async function runDelegate({
|
|
|
125
157
|
textChunks.length = 0;
|
|
126
158
|
textLength = 0;
|
|
127
159
|
truncated = false;
|
|
160
|
+
thoughtProgress.reset();
|
|
161
|
+
messageProgress.reset();
|
|
128
162
|
planEntries = [];
|
|
129
163
|
planOverview = undefined;
|
|
130
164
|
planDetail = undefined;
|
|
131
165
|
touched.clear();
|
|
132
166
|
return client.prompt(sessionId, resolveSpec(spec));
|
|
133
167
|
});
|
|
168
|
+
thoughtProgress.end();
|
|
169
|
+
messageProgress.end();
|
|
134
170
|
let result = textChunks.join("");
|
|
135
171
|
if (truncated) result += TRUNCATION_MARKER;
|
|
136
172
|
const gitAfter = gitChangedSet(workspace);
|
package/src/doctor.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
1
|
import process from "node:process";
|
|
5
2
|
import { spawn } from "node:child_process";
|
|
6
3
|
import { AcpClient } from "./acp-client.js";
|
|
7
4
|
import { resolveAcpSpawn } from "./spawn.js";
|
|
5
|
+
import { VERSION } from "./version.js";
|
|
8
6
|
|
|
9
7
|
const HANDSHAKE_TIMEOUT_MS = 15_000;
|
|
10
8
|
const DEFAULT_LOG_SIZE = "2000";
|
|
11
9
|
|
|
12
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
const pluginVersion = JSON.parse(readFileSync(path.join(__dirname, "..", "package.json"), "utf8")).version;
|
|
14
|
-
|
|
15
10
|
function formatCommand({ command, args }) {
|
|
16
11
|
return args?.length ? `${command} ${args.join(" ")}` : command;
|
|
17
12
|
}
|
|
@@ -73,12 +68,13 @@ export async function runDoctor({
|
|
|
73
68
|
spawnSpec = resolveAcpSpawn(),
|
|
74
69
|
clientFactory = (opts) => new AcpClient(opts),
|
|
75
70
|
workspace,
|
|
71
|
+
handshakeTimeoutMs = HANDSHAKE_TIMEOUT_MS,
|
|
76
72
|
} = {}) {
|
|
77
73
|
const { capabilities, version } = getClientInfo();
|
|
78
74
|
const agentProbe = await probeAgentVersion(spawnSpec);
|
|
79
75
|
|
|
80
76
|
const out = {
|
|
81
|
-
plugin: { version:
|
|
77
|
+
plugin: { version: VERSION },
|
|
82
78
|
client: {
|
|
83
79
|
name: version?.name ?? null,
|
|
84
80
|
version: version?.version ?? null,
|
|
@@ -100,7 +96,7 @@ export async function runDoctor({
|
|
|
100
96
|
spawnSpec,
|
|
101
97
|
clientFactory,
|
|
102
98
|
workspace,
|
|
103
|
-
timeoutMs:
|
|
99
|
+
timeoutMs: handshakeTimeoutMs,
|
|
104
100
|
});
|
|
105
101
|
}
|
|
106
102
|
|
package/src/proc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
export function isChildAlive(child) {
|
|
5
|
+
return child && child.exitCode === null && child.signalCode === null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// On win32 a plain child.kill() only reaches the shell wrapper (spawn uses shell: true);
|
|
9
|
+
// taskkill /T takes the whole tree so the agent itself dies too.
|
|
10
|
+
export async function treeKill(pid) {
|
|
11
|
+
if (process.platform === "win32") {
|
|
12
|
+
await new Promise((resolve) => {
|
|
13
|
+
execFile("taskkill", ["/PID", String(pid), "/T", "/F"], () => resolve());
|
|
14
|
+
});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
try { process.kill(pid, "SIGKILL"); } catch {}
|
|
18
|
+
}
|
package/src/server.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
4
|
import { fileURLToPath } from "node:url";
|
|
6
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
6
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
7
|
import { z } from "zod";
|
|
9
8
|
import { runDelegate as runDelegateDefault } from "./delegate.js";
|
|
10
9
|
import { runDoctor as runDoctorDefault } from "./doctor.js";
|
|
10
|
+
import { VERSION } from "./version.js";
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
)
|
|
12
|
+
const nodeMajor = Number(process.versions.node.split(".")[0]);
|
|
13
|
+
if (nodeMajor < 22) {
|
|
14
|
+
console.error(`cursor-delegate-mcp requires Node 22+ (found ${process.versions.node})`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
const inFlight = new Map();
|
|
17
19
|
|
|
@@ -22,11 +24,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
22
24
|
let onProgress = () => {};
|
|
23
25
|
if (progressToken != null) {
|
|
24
26
|
let progress = 0;
|
|
25
|
-
let lastSent = 0;
|
|
26
27
|
onProgress = (message) => {
|
|
27
|
-
const now = Date.now();
|
|
28
|
-
if (progress > 0 && now - lastSent < 100) return;
|
|
29
|
-
lastSent = now;
|
|
30
28
|
try {
|
|
31
29
|
extra.sendNotification({
|
|
32
30
|
method: "notifications/progress",
|
|
@@ -38,6 +36,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
38
36
|
|
|
39
37
|
const supportsElicitation = !!server.server.getClientCapabilities?.()?.elicitation;
|
|
40
38
|
const autoAnswered = [];
|
|
39
|
+
const fallbackAnswers = [];
|
|
41
40
|
|
|
42
41
|
const onElicit = async ({ title, questions }) => {
|
|
43
42
|
const answers = [];
|
|
@@ -66,15 +65,21 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
66
65
|
if (result.action !== "accept") return null;
|
|
67
66
|
const choice = result.content?.choice || "";
|
|
68
67
|
let chosenOptionId = opts[0]?.id;
|
|
68
|
+
let matched = false;
|
|
69
69
|
for (const o of opts) {
|
|
70
70
|
if (
|
|
71
71
|
choice.toLowerCase() === String(o.id || "").toLowerCase() ||
|
|
72
72
|
choice.toLowerCase() === String(o.label || "").toLowerCase()
|
|
73
73
|
) {
|
|
74
74
|
chosenOptionId = o.id;
|
|
75
|
+
matched = true;
|
|
75
76
|
break;
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
if (!matched && opts.length) {
|
|
80
|
+
const chosen = opts.find((o) => o.id === chosenOptionId)?.label || chosenOptionId || "";
|
|
81
|
+
fallbackAnswers.push({ prompt: q.prompt, given: choice, chosen });
|
|
82
|
+
}
|
|
78
83
|
answers.push({ questionId: q.id, selectedOptionIds: [chosenOptionId] });
|
|
79
84
|
}
|
|
80
85
|
return { answers };
|
|
@@ -97,6 +102,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
97
102
|
},
|
|
98
103
|
});
|
|
99
104
|
if (autoAnswered.length) out.autoAnswered = autoAnswered;
|
|
105
|
+
if (fallbackAnswers.length) out.fallbackAnswers = fallbackAnswers;
|
|
100
106
|
return {
|
|
101
107
|
content: [{ type: "text", text: JSON.stringify(out, null, 2) }],
|
|
102
108
|
structuredContent: out,
|
|
@@ -114,7 +120,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
114
120
|
export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDoctorInjected } = {}) {
|
|
115
121
|
const runDelegate = runDelegateInjected || runDelegateDefault;
|
|
116
122
|
const runDoctor = runDoctorInjected || runDoctorDefault;
|
|
117
|
-
const server = new McpServer({ name: "cursor-delegate-mcp", version:
|
|
123
|
+
const server = new McpServer({ name: "cursor-delegate-mcp", version: VERSION });
|
|
118
124
|
|
|
119
125
|
server.registerTool(
|
|
120
126
|
"delegate",
|
|
@@ -127,7 +133,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
127
133
|
resumeSessionId: z.string().optional().describe("Resume an existing ACP session instead of a new one"),
|
|
128
134
|
workspace: z.string().optional().describe("Working directory for the agent (defaults to cwd)"),
|
|
129
135
|
model: z.string().default("composer-2.5"),
|
|
130
|
-
fast: z.
|
|
136
|
+
fast: z.boolean().default(false).describe("Fast speed tier — higher cost; enable only when the user asks"),
|
|
131
137
|
},
|
|
132
138
|
},
|
|
133
139
|
async (args, extra) => runDelegateTool({ args, extra, server, runDelegate, inFlight })
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
1
|
+
import { isChildAlive, treeKill } from "./proc.js";
|
|
3
2
|
|
|
4
3
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5
4
|
|
|
@@ -9,20 +8,6 @@ function makeError(reason, message) {
|
|
|
9
8
|
return err;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
function isChildAlive(child) {
|
|
13
|
-
return child && child.exitCode === null && child.signalCode === null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function treeKill(pid) {
|
|
17
|
-
if (process.platform === "win32") {
|
|
18
|
-
await new Promise((resolve) => {
|
|
19
|
-
execFile("taskkill", ["/PID", String(pid), "/T", "/F"], () => resolve());
|
|
20
|
-
});
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
try { process.kill(pid, "SIGKILL"); } catch {}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
11
|
export class SessionSupervisor {
|
|
27
12
|
constructor(client, {
|
|
28
13
|
idleMs = 90000,
|
package/src/spawn.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
|
|
3
|
-
export function
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
|
|
3
|
+
export function splitArgs(raw) {
|
|
4
|
+
const args = [];
|
|
5
|
+
const re = /"([^"]*)"|'([^']*)'|(\S+)/g;
|
|
6
|
+
for (const m of String(raw || "").matchAll(re)) {
|
|
7
|
+
args.push(m[1] ?? m[2] ?? m[3]);
|
|
8
|
+
}
|
|
9
|
+
return args;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function resolveAcpSpawn() {
|
|
13
|
+
const command = process.env.ACP_AGENT_COMMAND || "agent";
|
|
14
|
+
const args = process.env.ACP_AGENT_ARGS
|
|
15
|
+
? splitArgs(process.env.ACP_AGENT_ARGS)
|
|
16
|
+
: ["acp"];
|
|
17
|
+
return { command, args, options: { shell: process.platform === "win32" } };
|
|
18
|
+
}
|
package/src/version.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export const VERSION = JSON.parse(
|
|
6
|
+
readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8")
|
|
7
|
+
).version;
|