cursor-delegate-mcp 1.1.0 → 1.2.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 +10 -0
- package/package.json +1 -1
- package/src/acp-client.js +11 -9
- package/src/delegate.js +1 -1
- package/src/doctor.js +2 -7
- package/src/proc.js +18 -0
- package/src/server.js +16 -6
- package/src/session-supervisor.js +1 -16
- package/src/spawn.js +19 -9
- package/src/version.js +7 -0
package/README.md
CHANGED
|
@@ -165,6 +165,16 @@ Applies to both the plugin and the MCP server:
|
|
|
165
165
|
|
|
166
166
|
By default, delegation uses the **Composer 2.5** model (standard tier). Cursor includes a separate **Auto + Composer** usage pool with generous included quota, apart from the API pool other models draw from. For a different model, say so (for example, "use Opus" or "delegate with Codex").
|
|
167
167
|
|
|
168
|
+
## Configuration
|
|
169
|
+
|
|
170
|
+
Environment variables (optional — defaults work for a standard cursor-agent install):
|
|
171
|
+
|
|
172
|
+
| Variable | Default | Description |
|
|
173
|
+
| -------- | ------- | ----------- |
|
|
174
|
+
| `ACP_AGENT_COMMAND` | `agent` | Launcher for the ACP agent process. |
|
|
175
|
+
| `ACP_AGENT_ARGS` | `acp` | Arguments passed to the launcher. Quote arguments that contain spaces: `--config "C:\path with spaces\acp.json"`. |
|
|
176
|
+
| `ACP_LOG_SIZE` | `2000` | ACP frames kept for the error transcript; `0` disables. |
|
|
177
|
+
|
|
168
178
|
## License
|
|
169
179
|
|
|
170
180
|
MIT © Andrei Lungeanu
|
package/package.json
CHANGED
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,7 +33,7 @@ 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
38
|
onSessionReady, onProgress, gitChangedSet = gitChangedSetReal,
|
|
39
39
|
} = {}) {
|
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
|
}
|
|
@@ -78,7 +73,7 @@ export async function runDoctor({
|
|
|
78
73
|
const agentProbe = await probeAgentVersion(spawnSpec);
|
|
79
74
|
|
|
80
75
|
const out = {
|
|
81
|
-
plugin: { version:
|
|
76
|
+
plugin: { version: VERSION },
|
|
82
77
|
client: {
|
|
83
78
|
name: version?.name ?? null,
|
|
84
79
|
version: version?.version ?? null,
|
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
|
|
|
@@ -38,6 +40,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
38
40
|
|
|
39
41
|
const supportsElicitation = !!server.server.getClientCapabilities?.()?.elicitation;
|
|
40
42
|
const autoAnswered = [];
|
|
43
|
+
const fallbackAnswers = [];
|
|
41
44
|
|
|
42
45
|
const onElicit = async ({ title, questions }) => {
|
|
43
46
|
const answers = [];
|
|
@@ -66,15 +69,21 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
66
69
|
if (result.action !== "accept") return null;
|
|
67
70
|
const choice = result.content?.choice || "";
|
|
68
71
|
let chosenOptionId = opts[0]?.id;
|
|
72
|
+
let matched = false;
|
|
69
73
|
for (const o of opts) {
|
|
70
74
|
if (
|
|
71
75
|
choice.toLowerCase() === String(o.id || "").toLowerCase() ||
|
|
72
76
|
choice.toLowerCase() === String(o.label || "").toLowerCase()
|
|
73
77
|
) {
|
|
74
78
|
chosenOptionId = o.id;
|
|
79
|
+
matched = true;
|
|
75
80
|
break;
|
|
76
81
|
}
|
|
77
82
|
}
|
|
83
|
+
if (!matched && opts.length) {
|
|
84
|
+
const chosen = opts.find((o) => o.id === chosenOptionId)?.label || chosenOptionId || "";
|
|
85
|
+
fallbackAnswers.push({ prompt: q.prompt, given: choice, chosen });
|
|
86
|
+
}
|
|
78
87
|
answers.push({ questionId: q.id, selectedOptionIds: [chosenOptionId] });
|
|
79
88
|
}
|
|
80
89
|
return { answers };
|
|
@@ -97,6 +106,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
97
106
|
},
|
|
98
107
|
});
|
|
99
108
|
if (autoAnswered.length) out.autoAnswered = autoAnswered;
|
|
109
|
+
if (fallbackAnswers.length) out.fallbackAnswers = fallbackAnswers;
|
|
100
110
|
return {
|
|
101
111
|
content: [{ type: "text", text: JSON.stringify(out, null, 2) }],
|
|
102
112
|
structuredContent: out,
|
|
@@ -114,7 +124,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
114
124
|
export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDoctorInjected } = {}) {
|
|
115
125
|
const runDelegate = runDelegateInjected || runDelegateDefault;
|
|
116
126
|
const runDoctor = runDoctorInjected || runDoctorDefault;
|
|
117
|
-
const server = new McpServer({ name: "cursor-delegate-mcp", version:
|
|
127
|
+
const server = new McpServer({ name: "cursor-delegate-mcp", version: VERSION });
|
|
118
128
|
|
|
119
129
|
server.registerTool(
|
|
120
130
|
"delegate",
|
|
@@ -127,7 +137,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
127
137
|
resumeSessionId: z.string().optional().describe("Resume an existing ACP session instead of a new one"),
|
|
128
138
|
workspace: z.string().optional().describe("Working directory for the agent (defaults to cwd)"),
|
|
129
139
|
model: z.string().default("composer-2.5"),
|
|
130
|
-
fast: z.
|
|
140
|
+
fast: z.boolean().default(false).describe("Fast speed tier — higher cost; enable only when the user asks"),
|
|
131
141
|
},
|
|
132
142
|
},
|
|
133
143
|
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,19 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const args =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
|
|
3
|
+
// Shell-like tokenizer: whitespace splits, double/single quotes group.
|
|
4
|
+
export function splitArgs(raw) {
|
|
5
|
+
const args = [];
|
|
6
|
+
const re = /"([^"]*)"|'([^']*)'|(\S+)/g;
|
|
7
|
+
for (const m of String(raw || "").matchAll(re)) {
|
|
8
|
+
args.push(m[1] ?? m[2] ?? m[3]);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveAcpSpawn() {
|
|
14
|
+
const command = process.env.ACP_AGENT_COMMAND || "agent";
|
|
15
|
+
const args = process.env.ACP_AGENT_ARGS
|
|
16
|
+
? splitArgs(process.env.ACP_AGENT_ARGS)
|
|
17
|
+
: ["acp"];
|
|
18
|
+
return { command, args, options: { shell: process.platform === "win32" } };
|
|
19
|
+
}
|
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;
|