cursor-delegate-mcp 3.1.0 → 3.1.1
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/CHANGELOG.md +20 -0
- package/package.json +1 -1
- package/src/server.js +18 -17
- package/src/tasks.js +29 -10
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,26 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.1.1] - 2026-11-24
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- A finished task is kept for its hour however many finish, where only the last 100 were kept.
|
|
14
|
+
- `cancel` tells every session the server has seen from an unknown id, where only the last 500
|
|
15
|
+
sessions were kept.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- The server shuts down, stopping its agents, when its stdio transport closes. When the server's
|
|
20
|
+
stdout broke, as it does when the host dies, the transport paused stdin, no stdin EOF arrived,
|
|
21
|
+
and the server and the agent kept running.
|
|
22
|
+
- A completed task's result carries `resultType: "complete"`, as the `tools/call` result it stands
|
|
23
|
+
for, which the tasks extension's client schema requires.
|
|
24
|
+
- A task id resumes its session for as long as the server runs, not only for the hour its task is
|
|
25
|
+
kept.
|
|
26
|
+
- A finished task's status message is its error, or none, instead of its last progress line.
|
|
27
|
+
- `tasks/update` refuses a request with no `inputResponses`.
|
|
28
|
+
|
|
9
29
|
## [3.1.0] - 2026-11-24
|
|
10
30
|
|
|
11
31
|
### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
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, Copilot, or any MCP client to Cursor's CLI agent — structured results, plan mode, and changed files.",
|
package/src/server.js
CHANGED
|
@@ -3,7 +3,7 @@ import process from "node:process";
|
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { McpServer, CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, PROTOCOL_VERSION_META_KEY } from "@modelcontextprotocol/server";
|
|
6
|
-
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
6
|
+
import { serveStdio, StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { DEFAULT_MODEL, runDelegate as runDelegateDefault } from "./delegate.js";
|
|
9
9
|
import { runDoctor as runDoctorDefault } from "./doctor.js";
|
|
@@ -44,16 +44,8 @@ function unregisterInFlight(map, sessionId, handle) {
|
|
|
44
44
|
if (handles.size === 0) map.delete(sessionId);
|
|
45
45
|
}
|
|
46
46
|
// Session ids seen by this process, kept after the turn ends so cancel can tell a finished
|
|
47
|
-
// (still resumable) session from an id that never existed.
|
|
47
|
+
// (still resumable) session from an id that never existed.
|
|
48
48
|
const seenSessions = new Set();
|
|
49
|
-
const SEEN_SESSIONS_CAP = 500;
|
|
50
|
-
function rememberSession(set, id) {
|
|
51
|
-
if (id == null) return;
|
|
52
|
-
// Delete-then-add makes the Set an LRU, so a session still being resumed outlives one seen once.
|
|
53
|
-
if (set.has(id)) set.delete(id);
|
|
54
|
-
set.add(id);
|
|
55
|
-
if (set.size > SEEN_SESSIONS_CAP) set.delete(set.values().next().value);
|
|
56
|
-
}
|
|
57
49
|
|
|
58
50
|
// Delegations answered as MCP tasks. Module-level, as inFlight: a task outlives the request that
|
|
59
51
|
// started it, and serveStdio may build more than one server instance.
|
|
@@ -221,7 +213,7 @@ export async function runDelegateTool({
|
|
|
221
213
|
capturedSessionId = sessionId;
|
|
222
214
|
handle = { client, cancelRequested: false };
|
|
223
215
|
registerInFlight(inFlight, sessionId, handle);
|
|
224
|
-
|
|
216
|
+
seenSessions.add(sessionId);
|
|
225
217
|
// Sent now so a host that can call tools concurrently has an id to cancel mid-run.
|
|
226
218
|
onProgress(`session ready: ${sessionId}`);
|
|
227
219
|
},
|
|
@@ -296,7 +288,7 @@ export function buildServer({
|
|
|
296
288
|
},
|
|
297
289
|
async (args, ctx) => {
|
|
298
290
|
// Claude Code tells the model a task's id and never its session id, even after a stop.
|
|
299
|
-
const resumeSessionId = tasks.
|
|
291
|
+
const resumeSessionId = tasks.sessionOf(args.resumeSessionId) ?? args.resumeSessionId;
|
|
300
292
|
/** @param {Record<string, any>} [over] */
|
|
301
293
|
const run = (over) => runDelegateTool({ args: { ...args, resumeSessionId }, ctx, runDelegate, inFlight: flights, seenSessions, ...over });
|
|
302
294
|
if (!servesTasks || !listsTasks(ctx)) return run();
|
|
@@ -308,7 +300,7 @@ export function buildServer({
|
|
|
308
300
|
"cancel",
|
|
309
301
|
{
|
|
310
302
|
description:
|
|
311
|
-
"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 (agent process observed to exit), not-running (turn already ended, still resumable), not-found (id not in this process's
|
|
303
|
+
"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 (agent process observed to exit), not-running (turn already ended, still resumable), not-found (id not in this process's session history).",
|
|
312
304
|
inputSchema: z.object({
|
|
313
305
|
// Blank is a malformed call, not a stale id.
|
|
314
306
|
sessionId: z.string().trim().min(1, "sessionId must not be blank").describe("When delegate runs as an MCP task, its server-side task id works too."),
|
|
@@ -408,8 +400,9 @@ if (process.argv[1]) {
|
|
|
408
400
|
}
|
|
409
401
|
}
|
|
410
402
|
|
|
411
|
-
// Kill what is still running, then exit, on any way the host has of going away.
|
|
412
|
-
|
|
403
|
+
// Kill what is still running, then exit, on any way the host has of going away. Returns the
|
|
404
|
+
// shutdown stdin EOF triggers, for a host that goes some other way.
|
|
405
|
+
/** @param {import("./proc.js").ChildRegistry} [registry] @returns {() => void} */
|
|
413
406
|
export function installSignalCleanup(registry = children, {
|
|
414
407
|
exit = (code) => process.exit(code),
|
|
415
408
|
setExitCode = (code) => { process.exitCode = code; },
|
|
@@ -447,6 +440,7 @@ export function installSignalCleanup(registry = children, {
|
|
|
447
440
|
// A stdio host closes stdin before it resorts to a signal. The SDK aborts in-flight requests on
|
|
448
441
|
// EOF; this also stops their agents directly, waits for the kills, and exits.
|
|
449
442
|
stdin.on("end", () => shutdown(0));
|
|
443
|
+
return () => shutdown(0);
|
|
450
444
|
}
|
|
451
445
|
|
|
452
446
|
if (isMain) {
|
|
@@ -456,9 +450,16 @@ if (isMain) {
|
|
|
456
450
|
if (argv.includes("--version") || argv.includes("-v")) {
|
|
457
451
|
console.log(readPackageVersion());
|
|
458
452
|
} else {
|
|
459
|
-
installSignalCleanup();
|
|
453
|
+
const hostGone = installSignalCleanup();
|
|
454
|
+
const transport = new StdioServerTransport();
|
|
460
455
|
// One factory serves both protocol eras: a 2025-era initialize pins a legacy instance, and only
|
|
461
456
|
// a modern one answers with tasks.
|
|
462
|
-
serveStdio(({ era }) => buildServer({ era }));
|
|
457
|
+
serveStdio(({ era }) => buildServer({ era }), { transport });
|
|
458
|
+
// The transport also closes on a broken stdout, and then pauses stdin, so no 'end' arrives.
|
|
459
|
+
const closeServers = transport.onclose;
|
|
460
|
+
transport.onclose = () => {
|
|
461
|
+
closeServers?.();
|
|
462
|
+
hostGone();
|
|
463
|
+
};
|
|
463
464
|
}
|
|
464
465
|
}
|
package/src/tasks.js
CHANGED
|
@@ -6,7 +6,6 @@ import { CLIENT_CAPABILITIES_META_KEY, MissingRequiredClientCapabilityError, Pro
|
|
|
6
6
|
export const TASKS_EXTENSION = "io.modelcontextprotocol/tasks";
|
|
7
7
|
|
|
8
8
|
const RETAIN_MS = 60 * 60 * 1000;
|
|
9
|
-
const MAX_FINISHED = 100;
|
|
10
9
|
const FAST_POLL_MS = 3000;
|
|
11
10
|
const SLOW_POLL_MS = 10000;
|
|
12
11
|
const FAST_POLL_FOR_MS = 60 * 1000;
|
|
@@ -25,18 +24,21 @@ export function listsTasks(ctx) {
|
|
|
25
24
|
* }} Task
|
|
26
25
|
*/
|
|
27
26
|
|
|
28
|
-
/** @param {{ now?: () => number, retainMs?: number
|
|
29
|
-
export function createTaskStore({ now = Date.now, retainMs = RETAIN_MS
|
|
27
|
+
/** @param {{ now?: () => number, retainMs?: number }} [opts] */
|
|
28
|
+
export function createTaskStore({ now = Date.now, retainMs = RETAIN_MS } = {}) {
|
|
30
29
|
/** @type {Map<string, Task>} */
|
|
31
30
|
const tasks = new Map();
|
|
31
|
+
// A dropped task's session, so its id still resumes it: the host shows the model only the task id.
|
|
32
|
+
/** @type {Map<string, string>} */
|
|
33
|
+
const sessions = new Map();
|
|
32
34
|
// A running task is never dropped: its id is the host's only handle on the run.
|
|
33
35
|
const prune = () => {
|
|
34
36
|
const t = now();
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
for (const task of tasks.values()) {
|
|
38
|
+
if (task.endedAt === undefined || t - task.endedAt <= retainMs) continue;
|
|
39
|
+
tasks.delete(task.taskId);
|
|
40
|
+
if (task.sessionId) sessions.set(task.taskId, task.sessionId);
|
|
41
|
+
}
|
|
40
42
|
};
|
|
41
43
|
// A fact that changes what to do after a cancel, such as an agent the stop did not see exit.
|
|
42
44
|
/** @param {Task} task @param {string} text */
|
|
@@ -58,18 +60,28 @@ export function createTaskStore({ now = Date.now, retainMs = RETAIN_MS, maxFinis
|
|
|
58
60
|
add(task) { prune(); tasks.set(task.taskId, task); },
|
|
59
61
|
/** @param {string} taskId */
|
|
60
62
|
get(taskId) { prune(); return tasks.get(taskId); },
|
|
63
|
+
/** @param {string | undefined} taskId */
|
|
64
|
+
sessionOf(taskId) {
|
|
65
|
+
if (taskId === undefined) return undefined;
|
|
66
|
+
prune();
|
|
67
|
+
return tasks.get(taskId)?.sessionId ?? sessions.get(taskId);
|
|
68
|
+
},
|
|
61
69
|
// A cancelled task keeps its own status message: the run's error names the abort, a reason no
|
|
62
70
|
// blocking call returns.
|
|
63
71
|
/** @param {Task} task @param {{ result?: any, error?: any }} outcome */
|
|
64
72
|
finish(task, outcome) {
|
|
65
73
|
if (task.status === "working") {
|
|
66
74
|
task.endedAt = task.lastUpdatedAt = now();
|
|
75
|
+
// The last progress line is stale once the run is over; a failure says why instead.
|
|
67
76
|
if ("error" in outcome) {
|
|
68
77
|
task.status = "failed";
|
|
69
78
|
task.error = { code: ProtocolErrorCode.InternalError, message: String(outcome.error?.message ?? outcome.error) };
|
|
79
|
+
task.statusMessage = task.error.message;
|
|
70
80
|
} else {
|
|
71
81
|
task.status = "completed";
|
|
72
|
-
|
|
82
|
+
// The tools/call result a 2026-07-28 host would have read, marked as one.
|
|
83
|
+
task.result = { ...outcome.result, resultType: "complete" };
|
|
84
|
+
task.statusMessage = undefined;
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
prune();
|
|
@@ -168,8 +180,15 @@ export function registerTaskHandlers(server, store) {
|
|
|
168
180
|
server.server.setRequestHandler("tasks/get", { params: TaskParams, result: AnyResult },
|
|
169
181
|
async (/** @type {any} */ { taskId }, /** @type {any} */ ctx) => store.view(find(taskId, ctx)));
|
|
170
182
|
// A delegation never enters input_required: its questions come back in the result.
|
|
183
|
+
// The SDK lifts inputResponses into ctx before validation, and reads a non-object as an empty map.
|
|
171
184
|
server.server.setRequestHandler("tasks/update", { params: TaskParams, result: AnyResult },
|
|
172
|
-
async (/** @type {any} */ { taskId }, /** @type {any} */ ctx) => {
|
|
185
|
+
async (/** @type {any} */ { taskId }, /** @type {any} */ ctx) => {
|
|
186
|
+
find(taskId, ctx);
|
|
187
|
+
if (ctx?.mcpReq?.inputResponses === undefined) {
|
|
188
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, "tasks/update needs inputResponses");
|
|
189
|
+
}
|
|
190
|
+
return {};
|
|
191
|
+
});
|
|
173
192
|
server.server.setRequestHandler("tasks/cancel", { params: TaskParams, result: AnyResult },
|
|
174
193
|
async (/** @type {any} */ { taskId }, /** @type {any} */ ctx) => { store.cancel(find(taskId, ctx)); return {}; });
|
|
175
194
|
}
|