Skip to content

Commit 5cabc1e

Browse files
cliffhallclaude
andauthored
feat(web): URL elicitation — explicit completion step + error-path (-32042) handling (#1415) (#1436)
* feat(web): two-step URL elicitation completion (#1415) Replace accept-on-open with an explicit completion step for URL elicitations. Opening the URL now only transitions the panel to its waiting state; the elicitation resolves with `accept` only when the user clicks the revealed "I've completed it" action, or with `cancel`. - ElicitationUrlPanel: add `onComplete`, reveal the completion button and relabel open→"Reopen in Browser" while `isWaiting`. - PendingClientRequestModal: wire local `isWaiting`; open no longer sends a response. Removed the accept-on-open comment that pointed here. - Tests cover open→waiting→complete and open→cancel, and assert opening alone does not resolve the elicitation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): handle URL-elicitation-required (-32042) error path Implements the spec's "URL mode with elicitation required error" flow (2025-11-25). When a tools/call returns a `-32042` UrlElicitationRequired error, the client now surfaces the required URL elicitation(s) and retries the call once completed, instead of showing a bare error. Core (InspectorClient.callTool): - Detect `-32042` (typed UrlElicitationRequiredError or generic McpError) via the new `getUrlElicitationsFromError` helper. - Surface each carried elicitation in order through the existing pending- elicitation queue / modal (reusing the two-step "Open → I've completed it" UI), then re-issue the original call once all are accepted. A decline/cancel aborts with a clear message; a bounded retry count guards a server that keeps returning the error. - `ElicitationCreateMessage.completeIfPending()` lets the optional `notifications/elicitation/complete` auto-advance/auto-accept an open URL elicitation; the completion-notification handler now resolves (was: only removed) the pending entry. - Extracted `attemptToolCall` / `dispatchFailedToolCall` from the old callTool body to support the retry loop without duplicating bookkeeping. Web (App): - A non-spec `-32042` with no elicitations (nothing to open) shows a dedicated yellow toast linking to a new UrlElicitationErrorModal with the raw error body, mirroring the output-schema-validation toast. Tests: helper unit tests, completeIfPending unit tests, callTool error-path retry/cancel/no-list/ordinary-error tests (injected fake client), the new modal (test + stories), and an App toast test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): abort URL-elicitation error path on a repeated URL Guard the -32042 retry loop: if the server's retry error re-requests a URL the user already completed earlier in the same call, completing it again can't make progress, so callTool aborts with a new typed UrlElicitationLoopError instead of re-prompting (which would loop until the retry cap). The web layer detects it and shows a "URL elicitation loop" toast naming the repeated URL rather than a generic failure. Tests: core abort-on-repeat test (URL presented once, two attempts, then loop error) and an App loop-toast test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(web): let Copy-URL reach the URL-elicitation completion step Address review of #1436: the "I've completed it" action was gated behind clicking "Open in Browser" (only that set isWaiting), so a user who used Copy URL to finish the flow externally could only Cancel. Copying the URL now also moves the panel into the waiting state, exposing the completion step. Also trims the now-redundant second sentence of the waiting hint. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(core): address review of error-path URL elicitation Review follow-ups on #1436 (all non-blocking): - Remove the leftover bare block scope in attemptToolCall (extraction artifact); body de-indented one level. - Log a warning when callTool gives up after the URL-elicitation retry cap is hit, so a server that keeps demanding new elicitations is diagnosable rather than looking like an ordinary failure. - Assert the dispatch-once invariant on the loop-abort and cancel-abort paths (exactly one failed toolCallResultChange event). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(core): fix attemptToolCall body indentation Run prettier over the extracted attemptToolCall method body, which was left over-indented by 2 spaces after the bare-block removal in 0754b43. core/ is outside clients/web's format:check scope, so npm run validate did not catch it. Whitespace-only; the pre-existing line 658 wrap (also outside the format scope) is left as-is, out of scope for this PR. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(core): settle pending elicitations on disconnect to avoid callTool hang Address review of #1436: an error-path `awaitUrlElicitation` promise only settled via respond, but `disconnect()` cleared `pendingElicitations` wholesale — so a disconnect mid-elicitation (server crash, manual disconnect, transport close) left `callTool` (and the UI's in-flight toolCallState) hanging forever. - Add `ElicitationCreateMessage.cancel()`: settles a pending elicitation as `{ action: "cancel" }` without calling `onRemove` (the queue is cleared by the caller, so it must not splice mid-iteration). - `disconnect()` now cancels each pending elicitation before clearing the array, and dispatches `pendingElicitationsChange` (it already did so for samples) so the modal closes on a transport-close teardown too. Tests: disconnect-mid-elicitation settles callTool (no hang); cancel() unit tests (resolves-without-remove, no-op once responded). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 49d6be6 commit 5cabc1e

16 files changed

Lines changed: 1232 additions & 124 deletions

‎clients/web/src/App.test.tsx‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
2+
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
3+
import { UrlElicitationLoopError } from "@inspector/core/mcp/urlElicitation.js";
24
import {
35
renderWithMantine,
46
screen,
@@ -720,6 +722,61 @@ describe("App task wiring", () => {
720722
);
721723
});
722724

725+
it("shows a URL-elicitation toast when a tool call fails with a no-list -32042", async () => {
726+
const user = userEvent.setup();
727+
renderWithMantine(<App />);
728+
await user.click(screen.getByText("connect"));
729+
await waitFor(() => expect(clientInstances).toHaveLength(1));
730+
731+
(
732+
clientInstances[0] as unknown as {
733+
callTool: ReturnType<typeof vi.fn>;
734+
}
735+
).callTool.mockRejectedValueOnce(
736+
new McpError(
737+
ErrorCode.UrlElicitationRequired,
738+
"This request requires browser-based authorization.",
739+
),
740+
);
741+
742+
await user.click(screen.getByText("call"));
743+
744+
await waitFor(() =>
745+
expect(notificationsMock.show).toHaveBeenCalledWith(
746+
expect.objectContaining({
747+
title: "URL elicitation required",
748+
color: "yellow",
749+
}),
750+
),
751+
);
752+
});
753+
754+
it("shows a loop toast when a tool call aborts on a repeated URL elicitation", async () => {
755+
const user = userEvent.setup();
756+
renderWithMantine(<App />);
757+
await user.click(screen.getByText("connect"));
758+
await waitFor(() => expect(clientInstances).toHaveLength(1));
759+
760+
(
761+
clientInstances[0] as unknown as {
762+
callTool: ReturnType<typeof vi.fn>;
763+
}
764+
).callTool.mockRejectedValueOnce(
765+
new UrlElicitationLoopError("https://example.com/authorize"),
766+
);
767+
768+
await user.click(screen.getByText("call"));
769+
770+
await waitFor(() =>
771+
expect(notificationsMock.show).toHaveBeenCalledWith(
772+
expect.objectContaining({
773+
title: "URL elicitation loop",
774+
color: "yellow",
775+
}),
776+
),
777+
);
778+
});
779+
723780
it("surfaces a refresh failure as a red toast", async () => {
724781
vi.mocked(useManagedRequestorTasks).mockReturnValue({
725782
tasks: [],

‎clients/web/src/App.tsx‎

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import type {
2323
InspectorClientEventMap,
2424
JsonValue,
2525
} from "@inspector/core/mcp/index.js";
26+
import {
27+
getUrlElicitationsFromError,
28+
UrlElicitationLoopError,
29+
} from "@inspector/core/mcp/urlElicitation.js";
2630
import type { TypedEventGeneric } from "@inspector/core/mcp/typedEventTarget.js";
2731
import type {
2832
InspectorServerSettings,
@@ -98,6 +102,7 @@ import {
98102
import { ServerSettingsModal } from "./components/groups/ServerSettingsModal/ServerSettingsModal";
99103
import { ConnectionInfoModal } from "./components/groups/ConnectionInfoModal/ConnectionInfoModal";
100104
import { OutputValidationModal } from "./components/groups/OutputValidationModal/OutputValidationModal";
105+
import { UrlElicitationErrorModal } from "./components/groups/UrlElicitationErrorModal/UrlElicitationErrorModal";
101106
import type { OAuthDetails } from "./components/groups/ConnectionInfoContent/ConnectionInfoContent";
102107
import { ServerRemoveConfirmModal } from "./components/groups/ServerRemoveConfirmModal/ServerRemoveConfirmModal";
103108
import {
@@ -223,6 +228,46 @@ const OutputValidationToastMessage = ({
223228
</Stack>
224229
);
225230

231+
// Body of the non-spec URLElicitationRequired toast: the server returned a
232+
// -32042 error with no `elicitations` list, so there's no URL to open. We keep
233+
// the toast short and link to a modal with the raw error body.
234+
const UrlElicitationErrorToastMessage = ({
235+
onViewDetails,
236+
}: {
237+
onViewDetails: () => void;
238+
}) => (
239+
<Stack gap={4}>
240+
<Text size="sm">
241+
The server reported a URLElicitationRequired error but listed no required
242+
elicitations, so there&apos;s nothing to open.
243+
</Text>
244+
<Anchor component="button" type="button" size="sm" onClick={onViewDetails}>
245+
View error details
246+
</Anchor>
247+
</Stack>
248+
);
249+
250+
function errorMessage(err: unknown): string {
251+
return err instanceof Error ? err.message : String(err);
252+
}
253+
254+
// Pretty-print a thrown error for the URL-elicitation details modal: an McpError
255+
// carries a `code`/`data` worth showing alongside the message, so include them
256+
// when present; otherwise fall back to the plain message.
257+
function formatErrorDetails(err: unknown): string {
258+
if (err && typeof err === "object") {
259+
const e = err as { code?: unknown; message?: unknown; data?: unknown };
260+
if (e.code !== undefined || e.data !== undefined) {
261+
return JSON.stringify(
262+
{ code: e.code, message: e.message, data: e.data },
263+
null,
264+
2,
265+
);
266+
}
267+
}
268+
return errorMessage(err);
269+
}
270+
226271
// How long a progress toast lingers after its last tick. Each new tick on the
227272
// same progress stream resets this window (via `notifications.update`), so a
228273
// steady stream keeps one toast alive; the toast clears a few seconds after
@@ -339,6 +384,12 @@ function App() {
339384
toolName: string;
340385
message: string;
341386
} | null>(null);
387+
// Raw body for the non-spec URLElicitationRequired (-32042, no elicitations)
388+
// modal opened from its warning toast.
389+
const [urlElicitationErrorDetails, setUrlElicitationErrorDetails] = useState<{
390+
toolName: string;
391+
details: string;
392+
} | null>(null);
342393

343394
// The active connection target. `null` between sessions; set as soon as
344395
// the user toggles a server card on. Drives state-manager lifetime.
@@ -1258,9 +1309,50 @@ function App() {
12581309
error: invocation.error,
12591310
});
12601311
} catch (err) {
1312+
// The server kept asking for a URL the user already completed this call,
1313+
// so callTool aborted to avoid an endless re-prompt loop. Surface that
1314+
// explicitly rather than as a generic failure.
1315+
if (err instanceof UrlElicitationLoopError) {
1316+
setToolCallState({ status: "error", error: err.message });
1317+
notifications.show({
1318+
autoClose: false,
1319+
title: "URL elicitation loop",
1320+
color: "yellow",
1321+
message: (
1322+
<Text size="sm">
1323+
The server requested the same URL again after you completed it (
1324+
{err.url}), so the call was cancelled to avoid an endless loop.
1325+
</Text>
1326+
),
1327+
});
1328+
return;
1329+
}
1330+
// A URLElicitationRequired (-32042) error that reaches here carried no
1331+
// elicitations (a non-spec response — the with-list case is handled and
1332+
// retried inside callTool). There's no URL to open, so surface a short
1333+
// toast that links to the raw error rather than a bare error panel.
1334+
const urlElicitations = getUrlElicitationsFromError(err);
1335+
if (urlElicitations !== null && urlElicitations.length === 0) {
1336+
const details = {
1337+
toolName: name,
1338+
details: formatErrorDetails(err),
1339+
};
1340+
setToolCallState({ status: "error", error: errorMessage(err) });
1341+
notifications.show({
1342+
autoClose: false,
1343+
title: "URL elicitation required",
1344+
color: "yellow",
1345+
message: (
1346+
<UrlElicitationErrorToastMessage
1347+
onViewDetails={() => setUrlElicitationErrorDetails(details)}
1348+
/>
1349+
),
1350+
});
1351+
return;
1352+
}
12611353
setToolCallState({
12621354
status: "error",
1263-
error: err instanceof Error ? err.message : String(err),
1355+
error: errorMessage(err),
12641356
});
12651357
}
12661358
},
@@ -1953,6 +2045,12 @@ function App() {
19532045
message={outputValidationDetails?.message}
19542046
onClose={() => setOutputValidationDetails(null)}
19552047
/>
2048+
<UrlElicitationErrorModal
2049+
opened={urlElicitationErrorDetails !== null}
2050+
toolName={urlElicitationErrorDetails?.toolName}
2051+
details={urlElicitationErrorDetails?.details}
2052+
onClose={() => setUrlElicitationErrorDetails(null)}
2053+
/>
19562054
<PendingClientRequestModal
19572055
request={pendingRequestContent}
19582056
serverName={activeServer?.name ?? "this server"}

‎clients/web/src/components/groups/ElicitationUrlPanel/ElicitationUrlPanel.stories.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const meta: Meta<typeof ElicitationUrlPanel> = {
88
args: {
99
onCopyUrl: fn(),
1010
onOpenInBrowser: fn(),
11+
onComplete: fn(),
1112
onCancel: fn(),
1213
message: "Please authenticate with the external service.",
1314
requestId: "elicit-abc-123",

‎clients/web/src/components/groups/ElicitationUrlPanel/ElicitationUrlPanel.test.tsx‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const baseProps = {
1010
isWaiting: false,
1111
onCopyUrl: vi.fn(),
1212
onOpenInBrowser: vi.fn(),
13+
onComplete: vi.fn(),
1314
onCancel: vi.fn(),
1415
};
1516

@@ -33,16 +34,29 @@ describe("ElicitationUrlPanel", () => {
3334
).toBeInTheDocument();
3435
});
3536

36-
it("does not render waiting indicator when isWaiting is false", () => {
37+
it("does not render the waiting indicator or complete action when not waiting", () => {
3738
renderWithMantine(<ElicitationUrlPanel {...baseProps} />);
3839
expect(
39-
screen.queryByText("Waiting for completion..."),
40+
screen.queryByText(/Waiting for completion/),
4041
).not.toBeInTheDocument();
42+
expect(
43+
screen.queryByRole("button", { name: "I've completed it" }),
44+
).not.toBeInTheDocument();
45+
expect(
46+
screen.getByRole("button", { name: "Open in Browser" }),
47+
).toBeInTheDocument();
4148
});
4249

43-
it("renders waiting indicator when isWaiting is true", () => {
50+
it("renders the waiting indicator and complete action when waiting", () => {
4451
renderWithMantine(<ElicitationUrlPanel {...baseProps} isWaiting />);
45-
expect(screen.getByText("Waiting for completion...")).toBeInTheDocument();
52+
expect(screen.getByText(/Waiting for completion/)).toBeInTheDocument();
53+
expect(
54+
screen.getByRole("button", { name: "I've completed it" }),
55+
).toBeInTheDocument();
56+
// The open action is relabelled so the user can reopen the tab.
57+
expect(
58+
screen.getByRole("button", { name: "Reopen in Browser" }),
59+
).toBeInTheDocument();
4660
});
4761

4862
it("invokes onCopyUrl when Copy URL is clicked", async () => {
@@ -65,6 +79,16 @@ describe("ElicitationUrlPanel", () => {
6579
expect(onOpenInBrowser).toHaveBeenCalledTimes(1);
6680
});
6781

82+
it("invokes onComplete when I've completed it is clicked while waiting", async () => {
83+
const user = userEvent.setup();
84+
const onComplete = vi.fn();
85+
renderWithMantine(
86+
<ElicitationUrlPanel {...baseProps} isWaiting onComplete={onComplete} />,
87+
);
88+
await user.click(screen.getByRole("button", { name: "I've completed it" }));
89+
expect(onComplete).toHaveBeenCalledTimes(1);
90+
});
91+
6892
it("invokes onCancel when Cancel is clicked", async () => {
6993
const user = userEvent.setup();
7094
const onCancel = vi.fn();
@@ -74,4 +98,12 @@ describe("ElicitationUrlPanel", () => {
7498
await user.click(screen.getByRole("button", { name: "Cancel" }));
7599
expect(onCancel).toHaveBeenCalledTimes(1);
76100
});
101+
102+
it("disables the completion and cancel actions when busy", () => {
103+
renderWithMantine(<ElicitationUrlPanel {...baseProps} isWaiting busy />);
104+
expect(
105+
screen.getByRole("button", { name: "I've completed it" }),
106+
).toBeDisabled();
107+
expect(screen.getByRole("button", { name: "Cancel" })).toBeDisabled();
108+
});
77109
});

‎clients/web/src/components/groups/ElicitationUrlPanel/ElicitationUrlPanel.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ export interface ElicitationUrlPanelProps {
1313
message: string;
1414
url: string;
1515
requestId: string;
16+
/**
17+
* The URL has been opened and we're waiting for the user to confirm they
18+
* finished the external flow. Reveals the "I've completed it" action; opening
19+
* the URL does not resolve the elicitation on its own.
20+
*/
1621
isWaiting: boolean;
1722
onCopyUrl: () => void;
1823
onOpenInBrowser: () => void;
24+
/** User confirms the external flow is done — sends `accept`. */
25+
onComplete: () => void;
1926
onCancel: () => void;
2027
/**
2128
* A response has been dispatched; lock the responding actions so a second
@@ -56,6 +63,7 @@ export function ElicitationUrlPanel({
5663
isWaiting,
5764
onCopyUrl,
5865
onOpenInBrowser,
66+
onComplete,
5967
onCancel,
6068
busy = false,
6169
}: ElicitationUrlPanelProps) {
@@ -70,7 +78,7 @@ export function ElicitationUrlPanel({
7078
Copy URL
7179
</Button>
7280
<Button variant="light" onClick={onOpenInBrowser} disabled={busy}>
73-
Open in Browser
81+
{isWaiting ? "Reopen in Browser" : "Open in Browser"}
7482
</Button>
7583
</Group>
7684
<Divider />
@@ -88,6 +96,11 @@ export function ElicitationUrlPanel({
8896
<Button variant="light" onClick={onCancel} disabled={busy}>
8997
Cancel
9098
</Button>
99+
{isWaiting && (
100+
<Button onClick={onComplete} disabled={busy}>
101+
I've completed it
102+
</Button>
103+
)}
91104
</Group>
92105
</Stack>
93106
);

0 commit comments

Comments
 (0)