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
* MRTR: drive input_required manually to keep pending-request UX (#1704) Follow-up to #1627/#1705. Instead of letting the SDK auto-fulfil the modern (2026-07-28) MRTR retry loop, InspectorClient now drives it itself so the Inspector keeps its pending-request UX, owns the loop, and shows era-accurate semantics. Core (core/mcp/inspectorClient.ts): - Construct the SDK Client with `inputRequired: { autoFulfill: false }` (unconditional; a no-op on legacy, which never returns input_required). - New `requestWithInputRequired()` driver: issues the request with `allowInputRequired` + `withInputRequired(schema)`, and while the result is `input_required`, fulfils each embedded request through the SAME pending sampling/elicitation plumbing, then retries the original call with `inputResponses` + the echoed `requestState` on a fresh id, bounded by MRTR_MAX_ROUNDS. - Route tools/call, prompts/get, and resources/read through the driver. - Embedded roots/list is auto-answered from configured roots (no pending UX); decline/cancel is echoed to the server (not treated as an abort); a tool-call abort mid-round settles the pending request and surfaces ToolCallCancelledError. - Extract shared `enqueuePendingSample`/`enqueuePendingElicitation` helpers used by both the legacy inbound handlers and the driver; add a per-request `origin` ("server-request" | "input-required") to the pending wrappers. Web UI: - New `MrtrOriginNote` element shows an "input_required — your answer returns as a retry" note on a modern MRTR round; legacy panels are unchanged. - Thread `origin` App -> PendingClientRequestModal -> the sampling/elicitation panels (and the inline panels). Test servers: new MRTR presets (multi-round, roots, sampling, loop, edge-case param shaping). Integration tests cover the manual round-trip (asserting the pending UI pauses and the retry carries inputResponses + requestState on a new id), multi-round, roots auto-answer, sampling, decline-echoed, maxRounds bound, abort mid-round, and requestState-only/inputRequests-only param shaping. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Review: clarify sampling-reject and between-rounds abort comments (#1704) Address review nits on PR #1719 (comment-only, no behavior change): - enqueuePendingSample docstring: sampling has no decline/cancel action; the panel either sends a result (resolve) or Rejects (reject → fails the call). The shared "declined/cancelled resolves" wording was accurate only for the elicitation case. - callToolWithRetries abort comment: note the between-rounds case — when the abort lands while an MRTR round awaits an embedded pending request there is no in-flight SDK request, so nothing is sent on the wire; the outcome (ToolCallCancelledError, no failed-call record) is identical. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * test-servers: add mrtr-showcase config exercising every MRTR preset (#1704) A single modern-era streamable-HTTP server (port 3111) bundling all six MRTR presets — mrtr_confirm, mrtr_two_step, mrtr_sample, mrtr_roots, mrtr_edge, mrtr_loop — for manual testing of the manual-driving pending-request UX across single-round, multi-round, sampling, roots, param-shaping, and maxRounds paths. Document it in the README alongside modern-mrtr-http.json. 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>
229 lines
6.7 KiB
TypeScript
229 lines
6.7 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import userEvent from "@testing-library/user-event";
|
|
import type {
|
|
CreateMessageRequestParams,
|
|
CreateMessageResult,
|
|
} from "@modelcontextprotocol/client";
|
|
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
|
|
import { InlineSamplingRequest } from "./InlineSamplingRequest";
|
|
|
|
const textRequest: CreateMessageRequestParams = {
|
|
messages: [
|
|
{
|
|
role: "user",
|
|
content: { type: "text", text: "Please analyze this code." },
|
|
},
|
|
],
|
|
maxTokens: 1024,
|
|
};
|
|
|
|
const arrayContentRequest: CreateMessageRequestParams = {
|
|
messages: [
|
|
{
|
|
role: "user",
|
|
content: [
|
|
// Note: SamplingMessage content is a single block, but the component
|
|
// also handles arrays defensively. Cast to satisfy types in tests.
|
|
{ type: "text", text: "from array" },
|
|
] as unknown as CreateMessageRequestParams["messages"][number]["content"],
|
|
},
|
|
],
|
|
maxTokens: 1024,
|
|
};
|
|
|
|
const nonTextSingleRequest: CreateMessageRequestParams = {
|
|
messages: [
|
|
{
|
|
role: "user",
|
|
content: {
|
|
type: "image",
|
|
data: "abc",
|
|
mimeType: "image/png",
|
|
},
|
|
},
|
|
],
|
|
maxTokens: 1024,
|
|
};
|
|
|
|
const emptyRequest: CreateMessageRequestParams = {
|
|
messages: [],
|
|
maxTokens: 1024,
|
|
};
|
|
|
|
const textDraft: CreateMessageResult = {
|
|
role: "assistant",
|
|
model: "claude-sonnet-4-20250514",
|
|
content: { type: "text", text: "draft response" },
|
|
};
|
|
|
|
const imageDraft: CreateMessageResult = {
|
|
role: "assistant",
|
|
model: "claude-sonnet-4-20250514",
|
|
content: { type: "image", data: "abc", mimeType: "image/png" },
|
|
};
|
|
|
|
const audioDraft: CreateMessageResult = {
|
|
role: "assistant",
|
|
model: "claude-sonnet-4-20250514",
|
|
content: { type: "audio", data: "abc", mimeType: "audio/wav" },
|
|
};
|
|
|
|
const baseProps = {
|
|
queuePosition: "1 of 1",
|
|
onAutoRespond: vi.fn(),
|
|
onEditAndSend: vi.fn(),
|
|
onReject: vi.fn(),
|
|
onViewDetails: vi.fn(),
|
|
};
|
|
|
|
describe("InlineSamplingRequest", () => {
|
|
it("renders the badge, queue position, and message preview", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest {...baseProps} request={textRequest} />,
|
|
);
|
|
expect(screen.getByText("sampling/createMessage")).toBeInTheDocument();
|
|
expect(screen.getByText("1 of 1")).toBeInTheDocument();
|
|
expect(screen.getByText("Please analyze this code.")).toBeInTheDocument();
|
|
// Default origin is a legacy server request — no MRTR note.
|
|
expect(screen.queryByText("input_required")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the MRTR note for a modern input_required round", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={textRequest}
|
|
origin="input-required"
|
|
/>,
|
|
);
|
|
expect(screen.getByText("input_required")).toBeInTheDocument();
|
|
expect(screen.getByText(/sent back as a retry/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders model hints when provided", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={{
|
|
...textRequest,
|
|
modelPreferences: {
|
|
hints: [{ name: "claude-opus" }, { name: "claude-sonnet" }],
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
expect(
|
|
screen.getByText("Model hints: claude-opus, claude-sonnet"),
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it("does not render hints when none are present", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest {...baseProps} request={textRequest} />,
|
|
);
|
|
expect(screen.queryByText(/^Model hints:/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("does not render hints when hints array is empty", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={{
|
|
...textRequest,
|
|
modelPreferences: { hints: [] },
|
|
}}
|
|
/>,
|
|
);
|
|
expect(screen.queryByText(/^Model hints:/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("renders the text draft preview when a text draft result is provided", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={textRequest}
|
|
draftResult={textDraft}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("draft response")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders the image draft preview when an image draft result is provided", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={textRequest}
|
|
draftResult={imageDraft}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("[Image content]")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders the audio draft preview when an audio draft result is provided", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={textRequest}
|
|
draftResult={audioDraft}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("[Audio content]")).toBeInTheDocument();
|
|
});
|
|
|
|
it("handles requests with array-shaped content", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest {...baseProps} request={arrayContentRequest} />,
|
|
);
|
|
expect(screen.getByText("from array")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders a non-text content type label for non-text single-content messages", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest {...baseProps} request={nonTextSingleRequest} />,
|
|
);
|
|
expect(screen.getByText("[image]")).toBeInTheDocument();
|
|
});
|
|
|
|
it("handles requests with no messages", () => {
|
|
renderWithMantine(
|
|
<InlineSamplingRequest {...baseProps} request={emptyRequest} />,
|
|
);
|
|
expect(screen.getByText("sampling/createMessage")).toBeInTheDocument();
|
|
});
|
|
|
|
it("invokes onViewDetails when View Details is clicked", async () => {
|
|
const user = userEvent.setup();
|
|
const onViewDetails = vi.fn();
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={textRequest}
|
|
onViewDetails={onViewDetails}
|
|
/>,
|
|
);
|
|
await user.click(screen.getByRole("button", { name: "View Details" }));
|
|
expect(onViewDetails).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("invokes onAutoRespond, onEditAndSend, and onReject when their buttons are clicked", async () => {
|
|
const user = userEvent.setup();
|
|
const onAutoRespond = vi.fn();
|
|
const onEditAndSend = vi.fn();
|
|
const onReject = vi.fn();
|
|
renderWithMantine(
|
|
<InlineSamplingRequest
|
|
{...baseProps}
|
|
request={textRequest}
|
|
onAutoRespond={onAutoRespond}
|
|
onEditAndSend={onEditAndSend}
|
|
onReject={onReject}
|
|
/>,
|
|
);
|
|
await user.click(screen.getByRole("button", { name: "Auto-respond" }));
|
|
await user.click(screen.getByRole("button", { name: /Edit.*Send/ }));
|
|
await user.click(screen.getByRole("button", { name: "Reject" }));
|
|
expect(onAutoRespond).toHaveBeenCalledTimes(1);
|
|
expect(onEditAndSend).toHaveBeenCalledTimes(1);
|
|
expect(onReject).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|