Tasks: io.modelcontextprotocol/tasks extension on modern servers (era fork) (#1731)
Some checks failed
Run install, format, lint, build, and test on every push / build (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish-github-container-registry (push) Has been cancelled
Some checks failed
Run install, format, lint, build, and test on every push / build (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish-github-container-registry (push) Has been cancelled
* Tasks: modern io.modelcontextprotocol/tasks extension (era fork core) Core + test-server implementation of the SEP-2663 tasks extension for modern (2026-07-28) connections, forked from the legacy 2025-11-25 tasks path. SDK v2 removed all tasks support AND era-gates the tasks/* spec methods out of the modern era on both the client (outbound) and server (inbound) sides, and its codec rejects a resultType:"task" result outright. So the Inspector drives the extension itself: task creation rides tools/call (a modern method) with the resultType:"task" frame rewritten at the transport to a CallToolResult carrying the handle in _meta; tasks/get/update/cancel go over a raw-wire request channel that bypasses the era gate (full modern envelope, string ids, consumed by the transport). input_required tasks reuse the existing pending-request modal via fulfilInputRequests, answered with tasks/update. No tasks/list, no tasks/result. Tab + run-as-task gate on the negotiated extension; the managed task store's refresh re-polls known handles on modern (no server list). Test server serves the extension via an Express interceptor (SDK can't) + a shared poll-driven runtime. Full integration coverage of both eras. Refs #1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Tasks modern era: tests + coverage (raw-wire, schemas, era integration) Adds unit coverage for modernTaskSchemas and the raw-wire request channel (transport-null guard, send failure, timeout, error response, teardown), plus end-to-end era integration tests (create/poll/input-required/update/cancel, synchronous passthrough, unknown-id error, modern store re-poll). Fixes the App and constructor-capabilities tests for the always-on tasks extension. Refs #1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Tasks modern era: docs + share test servers per era to de-flake coverage Document the tasks era-fork test configs in README and the new core/test-server files in AGENTS.md. Share one modern + one legacy test server across the era integration block (started lazily, stopped in afterAll) — starting a fresh Express server per test made connection negotiation flaky under the heavy concurrent coverage run. Refs #1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Restore pr-screenshots deleted inadvertently The logging/subscriptions PR screenshots + README were staged-deleted in the working tree before this branch; restore them from v2/main so this PR doesn't remove other PRs' artifacts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Tasks modern era: offer Run-as-task for any tool + PR screenshots On modern (SEP-2663) task creation is server-directed — the client declares the extension once and any tool may return a task — so the Tools screen now offers 'Run as task' for every tool on a modern connection (threaded via a modernTasks prop through InspectorView → ToolsScreen → ToolDetailPanel), rather than gating on the legacy per-tool taskSupport. Verified end-to-end in the web UI (remote proxy): create → poll tasks/get → input_required elicitation → tasks/update → inline result, plus the unchanged legacy tasks/list/result flow. Adds proof screenshots. Refs #1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Tasks modern era: address two follow-ups (task-input note + ordinary-path auto-poll) 1. The pending-request note now distinguishes a modern task round from an MRTR round: a new 'task-input-required' PendingRequestOrigin threads through fulfilInputRequests → the pending-request modal → MrtrOriginNote, which shows 'submitted via a tasks/update request (SEP-2663), not a retry' instead of the MRTR retry copy. 2. The ordinary (non-run-as-task) modern callTool path now auto-polls an unsolicited task handle: attemptToolCall detects the rewritten handle in the result _meta and drives it to termination (get → input_required/update → inline result), dispatching task events so the Tasks tab + toasts track it and the tool result resolves to the task's final result. The poll loop is shared with the streaming path via extracted helpers (submitModernTaskInput / modernTaskTerminalOutcome / modernTaskPollInterval). Refs #1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Tasks modern era: address review (negotiated envelope version, input-round cap, clarifying comment) + fresh smoke screenshots Review of #1731: 1. withModernTaskEnvelope now stamps the NEGOTIATED protocol version (getProtocolVersion() ?? MODERN_PROTOCOL_VERSION) so the envelope matches the MCP-Protocol-Version header instead of a hardcoded constant. 2. A never-completing input_required task is now bounded by MRTR_MAX_ROUNDS in the shared submitModernTaskInput (threaded through both poll loops), so a non-conformant server can't re-prompt the user forever. New modern_loop_task test-server tool + integration test cover the cap. 3. ToolDetailPanel: comment clarifying that per-tool taskSupport:"forbidden" is deliberately ignored on modern (task creation is server-directed under SEP-2663). (The abort-during-poll observation is addressed in the PR reply: the cancel path uses tasks/cancel and disconnect rejects the in-flight raw request, so the poll stops; matches legacy.) Fresh web-UI smoke screenshots (modern connected, task completed, input_required with the corrected tasks/update note, input completed). Refs #1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Tasks modern era: fix uncancelable input-required loop + sticky cancel Two bug fixes reported during manual testing of the tasks era-fork (#1631): 1. A modern task paused at `input_required` (e.g. `modern_loop_task`, which never advances) could not be cancelled: the poll loop blocked on the pending-request modal, so `cancelRequestorTask` sent `tasks/cancel` but the modal kept re-prompting. Now each modern poll loop registers a per-task AbortController (`registerTaskInputAbort`), `cancelRequestorTask` aborts it to reject the pending elicitation and unblock the poll, and the embedded input requests are tagged with their owning task id (`RELATED_TASK_META_KEY`) so the pending-request UI's Cancel action cancels the TASK rather than sending a "cancel" answer the server would re-prompt on. 2. On the legacy server, cancelling a task briefly showed CANCELLED then flipped to COMPLETED when the in-flight tool call resolved. Cancellation is a deliberate terminal decision, so `ManagedRequestorTasksState` now remembers cancelled task ids and ignores any later non-cancelled status update. Also: move the compact task id onto its own line in the embedded monitoring sidebar so the status badge / Cancel Task control don't wrap; DRY the duplicated task poll-interval logic into a shared `taskPollInterval` helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Refresh tasks PR screenshots + capture both bug-fix scenarios Recapture the five tasks flow screenshots against the current build and add two demonstrating the post-review fixes: modern_loop_task cancelled from the pending-request modal (uncancelable-loop fix) and a legacy task staying CANCELLED after the in-flight call resolves (sticky-cancel fix). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Address re-review: sticky cancel on legacy refresh + App cancel-routing test Re-review of the cancelable-loop / sticky-cancel fix raised two non-blocking hardening items: 1. The legacy tasks/list refresh() rebuilt the list from the server, honoring only dismissedTaskIds — so a cooperative-cancel server that re-lists a user-cancelled task as completed could un-stick the cancel on a manual Refresh. The refresh path now pins a cancelledTaskIds task to "cancelled" (keeping it visible-as-cancelled, matching the live-merge handlers) rather than dropping it. Covered by a new state test. 2. Added an App.test.tsx case locking in the user-facing half of the fix: Cancel on a task-input-required elicitation calls cancelRequestorTask (not respond). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
320daf2f67
commit
2259b1a3e1
2 changed files with 2483 additions and 132 deletions
|
|
@ -903,9 +903,10 @@ describe("InspectorClient coverage backfill", () => {
|
|||
});
|
||||
|
||||
describe("constructor capability branches and createReceiverTask options", () => {
|
||||
it("constructs with no advertised capabilities (clientOptions undefined branch)", async () => {
|
||||
// sample:false + elicit:false + no roots + no receiverTasks → the
|
||||
// capabilities object is empty, so clientOptions is passed as undefined.
|
||||
it("advertises only the tasks extension when no other capabilities are set", async () => {
|
||||
// sample:false + elicit:false + no roots + no receiverTasks → the only
|
||||
// advertised capability is the always-on Tasks extension (#1631), so
|
||||
// `capabilities` is non-empty and is always attached.
|
||||
client = new InspectorClient(
|
||||
{
|
||||
type: "stdio",
|
||||
|
|
@ -919,7 +920,10 @@ describe("InspectorClient coverage backfill", () => {
|
|||
},
|
||||
);
|
||||
const caps = client.getClientCapabilities();
|
||||
expect(Object.keys(caps)).toHaveLength(0);
|
||||
expect(caps.sampling).toBeUndefined();
|
||||
expect(caps.elicitation).toBeUndefined();
|
||||
expect(caps.roots).toBeUndefined();
|
||||
expect(caps.extensions?.["io.modelcontextprotocol/tasks"]).toBeDefined();
|
||||
await client.connect();
|
||||
expect(client.getStatus()).toBe("connected");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,380 @@
|
|||
import { describe, it, expect, afterEach, afterAll } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
import { InspectorClient } from "@inspector/core/mcp/inspectorClient.js";
|
||||
import { createTransportNode } from "@inspector/core/mcp/node/transport.js";
|
||||
import { eraToVersionNegotiation } from "@inspector/core/mcp/types.js";
|
||||
import { ManagedRequestorTasksState } from "@inspector/core/mcp/state/managedRequestorTasksState.js";
|
||||
import {
|
||||
createTestServerHttp,
|
||||
type TestServerHttp,
|
||||
createTestServerInfo,
|
||||
} from "@modelcontextprotocol/inspector-test-server";
|
||||
import type { ServerConfig } from "@modelcontextprotocol/inspector-test-server";
|
||||
import { getTaskServerConfig } from "@modelcontextprotocol/inspector-test-server";
|
||||
import type { ContentBlock } from "@modelcontextprotocol/client";
|
||||
import type { MessageEntry } from "@inspector/core/mcp/types.js";
|
||||
|
||||
/**
|
||||
* Live coverage of the Tasks era fork (#1631). Modern (2026-07-28) servers serve
|
||||
* the `io.modelcontextprotocol/tasks` extension (SEP-2663): a task-augmented
|
||||
* `tools/call` returns a `CreateTaskResult`, the client polls `tasks/get`
|
||||
* (no `tasks/list`, no blocking `tasks/result`), an `input_required` task
|
||||
* surfaces an embedded elicitation answered via `tasks/update`, and a completed
|
||||
* task inlines its result. Legacy servers keep the `capabilities.tasks` /
|
||||
* `tasks/list` flow. Both are driven against a real server over a real transport.
|
||||
*/
|
||||
describe("tasks era fork (#1631)", () => {
|
||||
let client: InspectorClient | null = null;
|
||||
// One server per era, shared across the block's tests (started lazily, stopped
|
||||
// in afterAll). Starting a fresh Express server per test made connection
|
||||
// negotiation flaky under the heavy concurrent coverage run; task ids are
|
||||
// unique per create so sharing state is harmless.
|
||||
let modernServer: TestServerHttp | null = null;
|
||||
let legacyServer: TestServerHttp | null = null;
|
||||
|
||||
afterEach(async () => {
|
||||
if (client) {
|
||||
try {
|
||||
await client.disconnect();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
client = null;
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
for (const s of [modernServer, legacyServer]) {
|
||||
if (s) {
|
||||
try {
|
||||
await s.stop();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
modernServer = null;
|
||||
legacyServer = null;
|
||||
});
|
||||
|
||||
async function startModernTasksServer(): Promise<TestServerHttp> {
|
||||
if (modernServer) return modernServer;
|
||||
const started = createTestServerHttp({
|
||||
serverInfo: createTestServerInfo("tasks-modern-test", "1.0.0"),
|
||||
tasksExtension: true,
|
||||
// A plain tool alongside the task tools, so a modern tools/call that does
|
||||
// NOT create a task exercises the synchronous-result path.
|
||||
tools: [
|
||||
{
|
||||
name: "plain_echo",
|
||||
description: "Echo the message without creating a task",
|
||||
inputSchema: { message: z.string().optional() },
|
||||
handler: async (args: Record<string, unknown>) => ({
|
||||
content: [
|
||||
{ type: "text" as const, text: `echo:${args.message ?? ""}` },
|
||||
],
|
||||
}),
|
||||
},
|
||||
],
|
||||
modern: {},
|
||||
});
|
||||
await started.start();
|
||||
modernServer = started;
|
||||
return started;
|
||||
}
|
||||
|
||||
async function startLegacyTasksServer(): Promise<TestServerHttp> {
|
||||
if (legacyServer) return legacyServer;
|
||||
const config = getTaskServerConfig() as ServerConfig;
|
||||
const started = createTestServerHttp({
|
||||
...config,
|
||||
serverInfo: createTestServerInfo("tasks-legacy-test", "1.0.0"),
|
||||
});
|
||||
await started.start();
|
||||
legacyServer = started;
|
||||
return started;
|
||||
}
|
||||
|
||||
async function connect(
|
||||
url: string,
|
||||
era: "legacy" | "modern",
|
||||
): Promise<{ connected: InspectorClient; messages: MessageEntry[] }> {
|
||||
const connected = new InspectorClient(
|
||||
{ type: "streamable-http", url },
|
||||
{
|
||||
environment: { transport: createTransportNode },
|
||||
versionNegotiation: eraToVersionNegotiation(era),
|
||||
},
|
||||
);
|
||||
const messages: MessageEntry[] = [];
|
||||
connected.addEventListener("message", (event) => {
|
||||
messages.push(event.detail);
|
||||
});
|
||||
await connected.connect();
|
||||
client = connected;
|
||||
return { connected, messages };
|
||||
}
|
||||
|
||||
function methodsSent(messages: MessageEntry[]): string[] {
|
||||
return messages
|
||||
.filter((m) => m.direction === "request")
|
||||
.map((m) => ("method" in m.message ? m.message.method : ""))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function firstText(content: ContentBlock[] | undefined): string {
|
||||
const block = content?.[0];
|
||||
return block && "text" in block ? block.text : "";
|
||||
}
|
||||
|
||||
describe("modern era", () => {
|
||||
it("negotiates the tasks extension and gates on it", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected } = await connect(started.url, "modern");
|
||||
expect(connected.getProtocolEra()).toBe("modern");
|
||||
expect(connected.isTasksExtensionNegotiated()).toBe(true);
|
||||
expect(
|
||||
connected.getCapabilities()?.extensions?.[
|
||||
"io.modelcontextprotocol/tasks"
|
||||
],
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it("creates a task, polls tasks/get (no tasks/list or tasks/result), and inlines the completed result", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
const tool = tools.find((t) => t.name === "modern_task");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
messages.length = 0;
|
||||
const invocation = await connected.callToolStream(tool!, {
|
||||
message: "hi",
|
||||
});
|
||||
expect(invocation.success).toBe(true);
|
||||
expect(firstText(invocation.result?.content as ContentBlock[])).toContain(
|
||||
"completed",
|
||||
);
|
||||
|
||||
const methods = methodsSent(messages);
|
||||
expect(methods).toContain("tasks/get");
|
||||
expect(methods).not.toContain("tasks/list");
|
||||
expect(methods).not.toContain("tasks/result");
|
||||
|
||||
// Every task-eligible request declares the extension per-request (SEP-2663).
|
||||
const call = messages.find(
|
||||
(m) =>
|
||||
m.direction === "request" &&
|
||||
"method" in m.message &&
|
||||
m.message.method === "tools/call",
|
||||
);
|
||||
const meta = (
|
||||
call?.message as { params?: { _meta?: Record<string, unknown> } }
|
||||
).params?._meta;
|
||||
expect(
|
||||
(
|
||||
meta?.["io.modelcontextprotocol/clientCapabilities"] as {
|
||||
extensions?: Record<string, unknown>;
|
||||
}
|
||||
)?.extensions,
|
||||
).toHaveProperty("io.modelcontextprotocol/tasks");
|
||||
});
|
||||
|
||||
it("answers an input_required task via tasks/update, then completes", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
const tool = tools.find((t) => t.name === "modern_input_task");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
let pausedAtPendingUi = false;
|
||||
connected.addEventListener("newPendingElicitation", (event) => {
|
||||
pausedAtPendingUi = true;
|
||||
// The task round is tagged distinctly from an MRTR round so the UI can
|
||||
// show the accurate "answer via tasks/update" note (#1631 follow-up).
|
||||
expect(event.detail.origin).toBe("task-input-required");
|
||||
void event.detail.respond({
|
||||
action: "accept",
|
||||
content: { approved: true },
|
||||
});
|
||||
});
|
||||
|
||||
messages.length = 0;
|
||||
const invocation = await connected.callToolStream(tool!, {});
|
||||
expect(invocation.success).toBe(true);
|
||||
expect(pausedAtPendingUi).toBe(true);
|
||||
expect(firstText(invocation.result?.content as ContentBlock[])).toContain(
|
||||
"approved",
|
||||
);
|
||||
|
||||
const methods = methodsSent(messages);
|
||||
expect(methods).toContain("tasks/update");
|
||||
});
|
||||
|
||||
it("auto-polls an unsolicited task handle on the ordinary callTool path (#1631 follow-up)", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
const tool = tools.find((t) => t.name === "modern_task")!;
|
||||
|
||||
// The ordinary (non-run-as-task) path: the server answers with a task
|
||||
// handle; callTool must poll it to termination and resolve to the task's
|
||||
// final inline result — NOT the transport's "task created" placeholder.
|
||||
const taskUpdates: string[] = [];
|
||||
connected.addEventListener("requestorTaskUpdated", (event) => {
|
||||
taskUpdates.push(event.detail.taskId);
|
||||
});
|
||||
|
||||
messages.length = 0;
|
||||
const invocation = await connected.callTool(tool, {
|
||||
message: "unsolicited",
|
||||
});
|
||||
expect(invocation.success).toBe(true);
|
||||
expect(firstText(invocation.result?.content as ContentBlock[])).toContain(
|
||||
"completed",
|
||||
);
|
||||
expect(taskUpdates.length).toBeGreaterThan(0);
|
||||
expect(methodsSent(messages)).toContain("tasks/get");
|
||||
});
|
||||
|
||||
it("answers an input_required unsolicited handle via tasks/update on the ordinary path (#1631 follow-up)", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
const tool = tools.find((t) => t.name === "modern_input_task")!;
|
||||
|
||||
connected.addEventListener("newPendingElicitation", (event) => {
|
||||
expect(event.detail.origin).toBe("task-input-required");
|
||||
void event.detail.respond({
|
||||
action: "accept",
|
||||
content: { approved: true },
|
||||
});
|
||||
});
|
||||
|
||||
messages.length = 0;
|
||||
const invocation = await connected.callTool(tool, {});
|
||||
expect(invocation.success).toBe(true);
|
||||
expect(firstText(invocation.result?.content as ContentBlock[])).toContain(
|
||||
"approved",
|
||||
);
|
||||
expect(methodsSent(messages)).toContain("tasks/update");
|
||||
});
|
||||
|
||||
it("bounds a never-completing input_required task with the round cap (#1631 review)", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
const tool = tools.find((t) => t.name === "modern_loop_task")!;
|
||||
|
||||
// The server never advances past input_required, so the client re-prompts
|
||||
// each poll; auto-answer, and the round cap must eventually abort instead
|
||||
// of looping forever.
|
||||
connected.addEventListener("newPendingElicitation", (event) => {
|
||||
void event.detail.respond({
|
||||
action: "accept",
|
||||
content: { approved: true },
|
||||
});
|
||||
});
|
||||
|
||||
await expect(connected.callToolStream(tool, {})).rejects.toThrow(
|
||||
/exceeded \d+ input_required rounds/,
|
||||
);
|
||||
});
|
||||
|
||||
it("cancels a task paused at input_required — aborts the pending elicitation and unblocks the poll (#1631)", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
|
||||
// A never-completing task: without the cancel-aborts-input fix, cancelling
|
||||
// wouldn't unblock the poll — the modal would re-prompt forever.
|
||||
const tool = tools.find((t) => t.name === "modern_loop_task")!;
|
||||
let capturedTaskId: string | undefined;
|
||||
let cancelledEventTaskId: string | undefined;
|
||||
let cancelPromise: Promise<void> | undefined;
|
||||
connected.addEventListener("requestorTaskUpdated", (event) => {
|
||||
capturedTaskId = event.detail.taskId;
|
||||
});
|
||||
connected.addEventListener("taskCancelled", (event) => {
|
||||
cancelledEventTaskId = event.detail.taskId;
|
||||
});
|
||||
connected.addEventListener("newPendingElicitation", () => {
|
||||
// Cancel the underlying task instead of answering — this must abort the
|
||||
// pending elicitation (close the modal) and let the poll settle.
|
||||
if (capturedTaskId && !cancelPromise) {
|
||||
cancelPromise = connected
|
||||
.cancelRequestorTask(capturedTaskId)
|
||||
.catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
messages.length = 0;
|
||||
// The poll must unblock and the call settle (reject) — not hang or loop.
|
||||
await expect(connected.callToolStream(tool, {})).rejects.toThrow();
|
||||
// Let tasks/cancel finish (it dispatches taskCancelled on completion).
|
||||
await cancelPromise;
|
||||
expect(methodsSent(messages)).toContain("tasks/cancel");
|
||||
expect(cancelledEventTaskId).toBe(capturedTaskId);
|
||||
// The pending elicitation was aborted, not left dangling behind a modal.
|
||||
expect(connected.getPendingElicitations()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("passes a synchronous (non-task) tool result straight through", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected } = await connect(started.url, "modern");
|
||||
const { tools } = await connected.listTools();
|
||||
const plain = tools.find((t) => t.name === "plain_echo");
|
||||
expect(plain).toBeDefined();
|
||||
|
||||
const invocation = await connected.callToolStream(plain!, {
|
||||
message: "hi",
|
||||
});
|
||||
expect(invocation.success).toBe(true);
|
||||
expect(firstText(invocation.result?.content as ContentBlock[])).toContain(
|
||||
"echo:hi",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a tasks/get for an unknown task id (raw-wire error path)", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected } = await connect(started.url, "modern");
|
||||
await expect(
|
||||
connected.getRequestorTask("does-not-exist"),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("modern store refresh re-polls known tasks (no tasks/list)", async () => {
|
||||
const started = await startModernTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "modern");
|
||||
const store = new ManagedRequestorTasksState(connected);
|
||||
const { tools } = await connected.listTools();
|
||||
const tool = tools.find((t) => t.name === "modern_task")!;
|
||||
|
||||
// Running the task seeds the store via requestorTaskUpdated events.
|
||||
await connected.callToolStream(tool, { message: "x" });
|
||||
expect(store.getTasks().length).toBeGreaterThan(0);
|
||||
|
||||
messages.length = 0;
|
||||
await store.refresh();
|
||||
const methods = methodsSent(messages);
|
||||
// Refresh re-polls with tasks/get; it never calls tasks/list on modern.
|
||||
expect(methods).not.toContain("tasks/list");
|
||||
store.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("legacy era", () => {
|
||||
it("does not negotiate the extension and keeps the tasks/list flow", async () => {
|
||||
const started = await startLegacyTasksServer();
|
||||
const { connected, messages } = await connect(started.url, "legacy");
|
||||
expect(connected.isTasksExtensionNegotiated()).toBe(false);
|
||||
expect(connected.getCapabilities()?.tasks).toBeDefined();
|
||||
|
||||
const store = new ManagedRequestorTasksState(connected);
|
||||
messages.length = 0;
|
||||
await store.refresh();
|
||||
expect(methodsSent(messages)).toContain("tasks/list");
|
||||
store.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue