Skip to content

Commit ddbd190

Browse files
cliffhallclaude
andcommitted
fix(everything): catch failed list-change sends; require inputResponses on tasks/update
Copilot round 5 on #5131: - The instance publisher sends list changes through the low-level Server methods and catches their failure, since McpServer's helpers start the same send and drop the promise. - tasks/update without inputResponses, which the extension's schema requires, is refused with -32602 instead of acknowledged. Part of #4852 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent d9ce091 commit ddbd190

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

‎src/everything/__tests__/modern.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,37 @@ describe("change notifications", () => {
538538
expect(await arrived).toEqual({ uri: URI });
539539
});
540540

541+
it.each(["toolsChanged", "promptsChanged", "resourcesChanged"] as const)(
542+
"logs, rather than leaves unhandled, a %s notification that cannot be sent",
543+
async (method) => {
544+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
545+
const server = new McpServer({ name: "s", version: "0" });
546+
vi.spyOn(server, "isConnected").mockReturnValue(true);
547+
const failure = new Error("closed");
548+
vi.spyOn(server.server, "sendToolListChanged").mockRejectedValue(failure);
549+
vi.spyOn(server.server, "sendPromptListChanged").mockRejectedValue(
550+
failure,
551+
);
552+
vi.spyOn(server.server, "sendResourceListChanged").mockRejectedValue(
553+
failure,
554+
);
555+
instancePublisher(server, () => true)[method]();
556+
await vi.waitFor(() =>
557+
expect(error).toHaveBeenCalledWith(
558+
"Change notification failed:",
559+
failure,
560+
),
561+
);
562+
},
563+
);
564+
565+
it("sends no list change from an instance with no connection", () => {
566+
const server = new McpServer({ name: "s", version: "0" });
567+
const send = vi.spyOn(server.server, "sendToolListChanged");
568+
instancePublisher(server, () => true).toolsChanged();
569+
expect(send).not.toHaveBeenCalled();
570+
});
571+
541572
it("logs, rather than throws, a resource update that cannot be sent", async () => {
542573
const error = vi.spyOn(console, "error").mockImplementation(() => {});
543574
const server = new McpServer({ name: "s", version: "0" });

‎src/everything/__tests__/tasks.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ describe("the extension", () => {
168168
expect(result.isError).toBe(true);
169169
});
170170

171+
it("refuses tasks/update without inputResponses with -32602", async () => {
172+
peer = await rawClient(TASKS);
173+
const created = await peer.call("simulate-research-query", { topic: "t" });
174+
const response = await peer.request("tasks/update", {
175+
taskId: created.taskId,
176+
});
177+
expect(response.error).toMatchObject({
178+
code: -32602,
179+
message: "Invalid params for tasks/update: inputResponses is required",
180+
});
181+
});
182+
171183
it("drops a task once its TTL has passed", async () => {
172184
peer = await rawClient(TASKS);
173185
const created = await peer.call("simulate-research-query", { topic: "t" });

‎src/everything/server/context.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ export function instancePublisher(
6262
): ChangePublisher {
6363
const report = (error: unknown) =>
6464
console.error("Change notification failed:", error);
65+
// The low-level sends return their promise; McpServer's own helpers start
66+
// the same send and drop it, so a failed one would go unhandled.
67+
const send = (notify: () => Promise<void>) => {
68+
if (server.isConnected()) notify().catch(report);
69+
};
6570
return {
66-
toolsChanged: () => server.sendToolListChanged(),
67-
promptsChanged: () => server.sendPromptListChanged(),
68-
resourcesChanged: () => server.sendResourceListChanged(),
71+
toolsChanged: () => send(() => server.server.sendToolListChanged()),
72+
promptsChanged: () => send(() => server.server.sendPromptListChanged()),
73+
resourcesChanged: () => send(() => server.server.sendResourceListChanged()),
6974
resourceUpdated: (uri) => {
7075
if (isSubscribed(uri)) {
7176
server.server.sendResourceUpdated({ uri }).catch(report);

‎src/everything/server/tasks.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,15 @@ export function registerTasksExtension(server: McpServer): void {
372372
async ({ taskId }, ctx) => {
373373
requireTasks(ctx);
374374
// The SDK lifts `inputResponses` out of the params of every request
375-
// (it is a reserved retry field on 2026-07-28) into the context.
376-
const inputResponses: TaskInputResponses =
377-
ctx.mcpReq.inputResponses ?? {};
375+
// (it is a reserved retry field on 2026-07-28) into the context. The
376+
// extension requires it, so a request without it is malformed.
377+
const inputResponses = ctx.mcpReq.inputResponses;
378+
if (inputResponses === undefined) {
379+
throw new ProtocolError(
380+
ProtocolErrorCode.InvalidParams,
381+
"Invalid params for tasks/update: inputResponses is required",
382+
);
383+
}
378384
const now = Date.now();
379385
const task = find(taskId, now);
380386
const state = stateOf(task, now);

0 commit comments

Comments
 (0)