cursor-delegate-mcp 1.12.0 → 1.14.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 +1 -1
- package/package.json +7 -2
- package/src/acp-client.js +45 -12
- package/src/acp-enums.js +15 -0
- package/src/delegate.js +128 -341
- package/src/doctor.js +34 -3
- package/src/errors.js +20 -0
- package/src/jsonrpc.js +38 -9
- package/src/proc.js +2 -2
- package/src/request-router.js +16 -11
- package/src/server.js +108 -113
- package/src/session-supervisor.js +1 -5
- package/src/spawn.js +5 -0
- package/src/turn-state.js +193 -0
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ You → your agent (plans & reviews)
|
|
|
43
43
|
## Features
|
|
44
44
|
|
|
45
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
|
|
46
|
+
- 💬 **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.
|
|
47
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
48
|
- 📋 **Plan first** — `plan` mode: Cursor drafts a plan, you review it, then the same session implements it.
|
|
49
49
|
- 🔍 **Ask anything** — `ask` mode: read-only Q&A over your codebase, zero file changes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server bridging AI coding hosts to cursor-agent over the Agent Client Protocol (ACP).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,10 +44,15 @@
|
|
|
44
44
|
"scripts": {
|
|
45
45
|
"test": "node --test test/*.test.js",
|
|
46
46
|
"test:pack": "node test/npm-package-smoke.mjs",
|
|
47
|
-
"start": "node src/server.js"
|
|
47
|
+
"start": "node src/server.js",
|
|
48
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"@modelcontextprotocol/sdk": "^1.22.0",
|
|
51
52
|
"zod": "^3.23.8"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^26.1.1",
|
|
56
|
+
"typescript": "^7.0.2"
|
|
52
57
|
}
|
|
53
58
|
}
|
package/src/acp-client.js
CHANGED
|
@@ -1,41 +1,76 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
4
|
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
4
5
|
import { createRequestRouter } from "./request-router.js";
|
|
5
6
|
import { resolveAcpSpawn } from "./spawn.js";
|
|
6
7
|
import { isChildAlive, treeKill } from "./proc.js";
|
|
7
8
|
import { VERSION } from "./version.js";
|
|
9
|
+
import { makeError } from "./errors.js";
|
|
8
10
|
|
|
9
11
|
const STDERR_CAP = 64 * 1024;
|
|
10
12
|
|
|
11
13
|
export class AcpClient extends EventEmitter {
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @param {{
|
|
16
|
+
* spawnSpec?: { command: string, args: string[], options?: object },
|
|
17
|
+
* mode?: string,
|
|
18
|
+
* onCreatePlan?: (body: any) => void,
|
|
19
|
+
* onTodos?: (body: any) => void,
|
|
20
|
+
* }} [opts]
|
|
21
|
+
*/
|
|
22
|
+
constructor({ spawnSpec, mode, onCreatePlan, onTodos } = {}) {
|
|
13
23
|
super();
|
|
14
24
|
this.spawnSpec = spawnSpec || resolveAcpSpawn();
|
|
15
|
-
this.onElicit = onElicit;
|
|
16
25
|
this.mode = mode;
|
|
17
26
|
this.onCreatePlan = onCreatePlan;
|
|
18
27
|
this.onTodos = onTodos;
|
|
28
|
+
this._stderrChunks = [];
|
|
29
|
+
this._stderrLength = 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The tail of stderr, which is what an exit error quotes. Kept as chunks and joined on read:
|
|
33
|
+
// rebuilding a 64KB string per chunk was the whole cost of a noisy agent. A StringDecoder
|
|
34
|
+
// holds partial UTF-8 across chunk boundaries, so a multi-byte character split by the pipe
|
|
35
|
+
// does not land in the error message as a replacement char.
|
|
36
|
+
get stderrBuffer() {
|
|
37
|
+
const joined = this._stderrChunks.join("");
|
|
38
|
+
return joined.length > STDERR_CAP ? joined.slice(-STDERR_CAP) : joined;
|
|
19
39
|
}
|
|
20
40
|
|
|
21
41
|
start() {
|
|
22
42
|
const { command, args, options } = this.spawnSpec;
|
|
23
|
-
this.
|
|
43
|
+
this._stderrChunks = [];
|
|
44
|
+
this._stderrLength = 0;
|
|
45
|
+
const stderrDecoder = new StringDecoder("utf8");
|
|
24
46
|
this._exitEmitted = false;
|
|
25
47
|
this.child = spawn(command, args, { ...options, stdio: ["pipe", "pipe", "pipe"] });
|
|
26
48
|
this.child.stderr.on("data", (chunk) => {
|
|
27
|
-
|
|
49
|
+
const text = stderrDecoder.write(chunk);
|
|
50
|
+
if (text) {
|
|
51
|
+
this._stderrChunks.push(text);
|
|
52
|
+
this._stderrLength += text.length;
|
|
53
|
+
// Drop whole chunks from the front only once well past the cap, so the common case
|
|
54
|
+
// costs one push. The joined tail is trimmed exactly on read.
|
|
55
|
+
while (this._stderrChunks.length > 1 && this._stderrLength - this._stderrChunks[0].length >= STDERR_CAP) {
|
|
56
|
+
this._stderrLength -= this._stderrChunks.shift().length;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
28
59
|
this.emit("activity");
|
|
29
60
|
});
|
|
30
61
|
this.child.stderr.on("error", () => {});
|
|
62
|
+
// A supervisor trip writes session/cancel, which can land after the agent is already gone.
|
|
63
|
+
// Without a handler that surfaces as an unhandled 'error' event on some platforms, taking
|
|
64
|
+
// the whole MCP server down with it.
|
|
65
|
+
this.child.stdin.on("error", () => {});
|
|
31
66
|
const emitExit = (code, signal) => {
|
|
32
67
|
if (this._exitEmitted) return;
|
|
33
68
|
this._exitEmitted = true;
|
|
34
69
|
const stderr = this.stderrBuffer;
|
|
35
|
-
const err =
|
|
70
|
+
const err = makeError(
|
|
71
|
+
"agent-exit",
|
|
36
72
|
`agent exited (code=${code}${signal ? ", signal=" + signal : ""})${stderr ? ": " + String(stderr).slice(-2000) : ""}`
|
|
37
73
|
);
|
|
38
|
-
err.reason = "agent-exit";
|
|
39
74
|
// exit + rejectAllPending both settle the same Promise.race; second rejection is intentional.
|
|
40
75
|
this.peer?.rejectAllPending(err);
|
|
41
76
|
this.emit("exit", { code, signal, stderr });
|
|
@@ -45,28 +80,26 @@ export class AcpClient extends EventEmitter {
|
|
|
45
80
|
this.router = null; // set before first stdout line
|
|
46
81
|
this.peer = new JsonRpcPeer(this.child.stdout, this.child.stdin, {
|
|
47
82
|
onNotification: (method, params) => { if (method === "session/update") this.emit("update", params); },
|
|
48
|
-
onRequest: (id, method, params) => this.router
|
|
83
|
+
onRequest: (id, method, params) => { if (this.router) this.router(id, method, params); },
|
|
49
84
|
onActivity: () => this.emit("activity"),
|
|
50
85
|
});
|
|
51
86
|
this.router = createRequestRouter({
|
|
52
87
|
respond: (id, r) => this.peer.respond(id, r),
|
|
53
88
|
respondError: (id, c, m) => this.peer.respondError(id, c, m),
|
|
54
|
-
onElicit: this.onElicit,
|
|
55
89
|
onCreatePlan: this.onCreatePlan,
|
|
56
90
|
onTodos: this.onTodos,
|
|
57
91
|
mode: this.mode,
|
|
58
92
|
log: (e) => this.emit("ack", e),
|
|
59
93
|
});
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
94
|
+
return /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
|
|
61
95
|
this.child.once("error", (e) => {
|
|
62
96
|
// Tagged like every other failure class so the caller gets
|
|
63
97
|
// "delegate failed [spawn-failed]: ..." instead of the one untagged prose error.
|
|
64
|
-
const err =
|
|
65
|
-
err.reason = "spawn-failed";
|
|
98
|
+
const err = makeError("spawn-failed", `Failed to spawn agent (${command}): ${e.message}. Install Cursor CLI and run 'cursor-agent login'.`);
|
|
66
99
|
reject(err);
|
|
67
100
|
});
|
|
68
101
|
this.child.once("spawn", () => resolve());
|
|
69
|
-
});
|
|
102
|
+
}));
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
// Stashed so the unknown-model pre-flight and doctor --deep can read the agent's real
|
package/src/acp-enums.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The value sets ACP allows for plan and todo fields. They live here because two layers read
|
|
2
|
+
// them: the sanitizers in delegate.js, which strip anything else off an agent frame, and the
|
|
3
|
+
// zod schemas in server.js, which advertise them to hosts. Kept in four hand-synced copies
|
|
4
|
+
// before, where a drift would have meant stripping a value the tool documents, or documenting
|
|
5
|
+
// one it strips.
|
|
6
|
+
//
|
|
7
|
+
// Plan status and todo status happen to carry the same three values today. They stay separate
|
|
8
|
+
// constants because ACP treats them as separate enums, and collapsing them would silently
|
|
9
|
+
// couple two things that are free to diverge.
|
|
10
|
+
|
|
11
|
+
export const PLAN_PRIORITIES = /** @type {const} */ (["high", "medium", "low"]);
|
|
12
|
+
|
|
13
|
+
export const PLAN_STATUSES = /** @type {const} */ (["pending", "in_progress", "completed"]);
|
|
14
|
+
|
|
15
|
+
export const TODO_STATUSES = /** @type {const} */ (["pending", "in_progress", "completed"]);
|