MRTR: drive input_required manually to keep pending-request UX (#1704) (#1719)
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>
This commit is contained in:
Cliff Hall 2026-07-17 23:15:19 -04:00 • committed by GitHub
commit 9b2c188d11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 1131 additions and 96 deletions

View file

@ -0,0 +1,20 @@
{
"serverInfo": {
"name": "composable-mrtr-showcase",
"version": "1.0.0"
},
"tools": [
{ "preset": "echo" },
{ "preset": "mrtr_confirm" },
{ "preset": "mrtr_two_step" },
{ "preset": "mrtr_sample" },
{ "preset": "mrtr_roots" },
{ "preset": "mrtr_edge" },
{ "preset": "mrtr_loop" }
],
"transport": {
"type": "streamable-http",
"port": 3111,
"modern": true
}
}

View file

@ -20,6 +20,11 @@ import {
createListRootsTool,
createCollectFormElicitationTool,
createMrtrTool,
createMrtrMultiRoundTool,
createMrtrRootsTool,
createMrtrSamplingTool,
createMrtrLoopTool,
createMrtrEdgeCaseTool,
createCollectUrlElicitationTool,
createUrlElicitationFormTool,
createSendNotificationTool,
@ -99,6 +104,16 @@ function resolveToolPreset(
return createCollectFormElicitationTool();
case "mrtr_confirm":
return createMrtrTool();
case "mrtr_two_step":
return createMrtrMultiRoundTool();
case "mrtr_roots":
return createMrtrRootsTool();
case "mrtr_sample":
return createMrtrSamplingTool();
case "mrtr_loop":
return createMrtrLoopTool();
case "mrtr_edge":
return createMrtrEdgeCaseTool();
case "collect_url_elicitation":
return createCollectUrlElicitationTool();
case "url_elicitation_form":

View file

@ -442,6 +442,223 @@ export function createMrtrTool(): ToolDefinition {
};
}
/**
* A two-round MRTR tool: it asks for a first value, then (on the retry) a second
* value, then completes. Exercises the manual driver's loop across MORE than one
* `input_required` round.
*
* The modern leg is stateless and each retry carries only THAT round's
* `inputResponses` (spec-correct — the client does not accumulate prior
* answers). So the tool tracks which step it is on via the opaque `requestState`
* the client echoes back, not via accumulated responses. Used to verify the
* Inspector surfaces each embedded elicitation in turn and only completes after
* both are answered (#1704).
*/
export function createMrtrMultiRoundTool(): ToolDefinition {
return {
name: "mrtr_two_step",
description:
"Two-round MRTR tool: collects a first value, then a second value, then completes.",
inputSchema: {},
handler: async (
_params: Record<string, unknown>,
_context?: TestServerContext,
extra?: HandlerExtra,
) => {
const step =
typeof extra?.requestState === "string" ? extra.requestState : "start";
if (step === "start") {
return inputRequired({
inputRequests: {
first: inputRequired.elicit({
message: "Step 1: enter the first value",
requestedSchema: {
type: "object",
properties: { value: { type: "string", title: "First" } },
required: ["value"],
},
}),
},
requestState: `mrtr-two:step2:${++mrtrMintCount}`,
});
}
if (step.startsWith("mrtr-two:step2")) {
return inputRequired({
inputRequests: {
second: inputRequired.elicit({
message: "Step 2: enter the second value",
requestedSchema: {
type: "object",
properties: { value: { type: "string", title: "Second" } },
required: ["value"],
},
}),
},
requestState: `mrtr-two:done:${++mrtrMintCount}`,
});
}
return toToolResult(
`MRTR two-step complete — final answer: ${JSON.stringify(
extra?.inputResponses?.second,
)}`,
);
},
};
}
/**
* An MRTR tool that embeds a `roots/list` request. The Inspector auto-answers it
* from the configured roots (no pending UX), so the retry carries the client's
* `{ roots }` result and the tool completes reporting how many roots it saw.
* Used to verify silent roots fulfilment mid-MRTR (#1704).
*/
export function createMrtrRootsTool(): ToolDefinition {
return {
name: "mrtr_roots",
description:
"MRTR tool that asks the client for its roots, then completes reporting the count.",
inputSchema: {},
handler: async (
_params: Record<string, unknown>,
_context?: TestServerContext,
extra?: HandlerExtra,
) => {
const responses = extra?.inputResponses;
if (!responses || responses.roots === undefined) {
return inputRequired({
inputRequests: { roots: inputRequired.listRoots() },
requestState: `mrtr-roots:${++mrtrMintCount}`,
});
}
const rootsResult = responses.roots as { roots?: unknown[] };
const count = Array.isArray(rootsResult.roots)
? rootsResult.roots.length
: 0;
return toToolResult(
`MRTR roots complete — client reported ${count} root(s)`,
);
},
};
}
/**
* An MRTR tool that embeds a `sampling/createMessage` request. On the retry the
* client's sampling result is echoed back and the tool completes. Verifies the
* driver surfaces an embedded sampling request through the pending-request UI
* the same way it does an elicitation (#1704).
*/
export function createMrtrSamplingTool(): ToolDefinition {
return {
name: "mrtr_sample",
description:
"MRTR tool that asks the client to sample an LLM completion, then completes.",
inputSchema: {},
handler: async (
_params: Record<string, unknown>,
_context?: TestServerContext,
extra?: HandlerExtra,
) => {
const responses = extra?.inputResponses;
if (!responses || responses.sample === undefined) {
return inputRequired({
inputRequests: {
sample: inputRequired.createMessage({
messages: [
{
role: "user",
content: { type: "text", text: "Say hello." },
},
],
maxTokens: 64,
}),
},
requestState: `mrtr-sample:${++mrtrMintCount}`,
});
}
return toToolResult(
`MRTR sample complete — echoed: ${JSON.stringify(responses.sample)}`,
);
},
};
}
/**
* A pathological MRTR tool that ALWAYS returns `input_required` and never
* completes. Used to verify the manual driver bounds the loop (its
* `MRTR_MAX_ROUNDS` cap) instead of spinning forever (#1704).
*/
export function createMrtrLoopTool(): ToolDefinition {
return {
name: "mrtr_loop",
description:
"Pathological MRTR tool that never completes — always returns input_required.",
inputSchema: {},
handler: async () => {
return inputRequired({
inputRequests: {
again: inputRequired.elicit({
message: "Answer again (this never completes)",
requestedSchema: {
type: "object",
properties: { value: { type: "string", title: "Value" } },
},
}),
},
requestState: `mrtr-loop:${++mrtrMintCount}`,
});
},
};
}
/**
* An MRTR tool exercising the driver's param-shaping edge cases (#1704):
* - Round 1 embeds an elicitation but mints NO `requestState` (so the retry
* carries `inputResponses` and no `requestState`).
* - Round 2 is `requestState`-only: it carries a `requestState` and NO
* `inputRequests` (so the retry carries `requestState` and no
* `inputResponses`).
* - Round 3 completes.
*/
export function createMrtrEdgeCaseTool(): ToolDefinition {
return {
name: "mrtr_edge",
description:
"MRTR tool covering the inputRequests-only and requestState-only round shapes.",
inputSchema: {},
handler: async (
_params: Record<string, unknown>,
_context?: TestServerContext,
extra?: HandlerExtra,
) => {
const state =
typeof extra?.requestState === "string" ? extra.requestState : "";
// Round 2: the client answered round 1's elicitation. Bounce a
// requestState-only round (no embedded requests) to move to the final leg.
if (extra?.inputResponses?.note !== undefined) {
return inputRequired({
requestState: `mrtr-edge:final:${++mrtrMintCount}`,
});
}
// Round 3: the requestState-only round came back — complete.
if (state.startsWith("mrtr-edge:final")) {
return toToolResult("MRTR edge complete");
}
// Round 1: embed an elicitation with NO requestState.
return inputRequired({
inputRequests: {
note: inputRequired.elicit({
message: "Edge round 1: enter a note",
requestedSchema: {
type: "object",
properties: { value: { type: "string", title: "Note" } },
},
}),
},
});
},
};
}
/**
* Create a "url_elicitation_form" tool that spins up a simple HTTP server on a dynamic
* port with a form page, sends that URL via URL elicitation, and on form submit collects
@ -1291,7 +1508,8 @@ export function createAddToolTool(): ToolDefinition {
{
description: params.description as string,
inputSchema: params.inputSchema as
Record<string, z.ZodType> | undefined,
| Record<string, z.ZodType>
| undefined,
},
async () => {
return {
@ -1395,7 +1613,8 @@ export function createAddPromptTool(): ToolDefinition {
{
description: params.description as string | undefined,
argsSchema: params.argsSchema as
Record<string, z.ZodType> | undefined,
| Record<string, z.ZodType>
| undefined,
},
async () => {
return {
@ -1539,7 +1758,9 @@ export function createSendProgressTool(
// Extract progressToken from metadata
const progressToken = extra?._meta?.progressToken as
string | number | undefined;
| string
| number
| undefined;
// Send progress notifications
let sent = 0;
@ -1975,9 +2196,12 @@ export function createTaskTool(
handler: {
createTask: async (args, extra) => {
const message = (args as Record<string, unknown>)?.message as
string | undefined;
| string
| undefined;
const progressToken = extra._meta?.progressToken as
string | number | undefined;
| string
| number
| undefined;
const task = await extra.taskStore.createTask({});
runTaskExecution({
task,