`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- bun, typescript
- Bereich
- backend-api-design
Rechercherichtung
Beginne in packages/client/src/client/client.ts bei callTool, wo der Issue zufolge die Validierung des Ausgabeschemas für jedes Ergebnis ausgeführt wird, bevor resultType geprüft wird. Lies die Behandlung von allowInputRequired und die vorhandene Verwendung von isInputRequiredResult und prüfe anschließend die relevanten Client-Tests zur Validierung des Ausgabeschemas und zu Input-Required-Ergebnissen. Fertig ist die Arbeit, wenn Input-Required-Ergebnisse durchgereicht werden und vollständige Ergebnisse weiterhin ihren strukturierten Inhalt validieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
On a 2026-07-28 connection, client.callTool(params, { allowInputRequired: true }) is meant to hand an input_required result back to the caller. It does so for a tool with no outputSchema. For a tool that declares one, it throws:
ProtocolError: Tool <name> has an output schema but did not return structured content
callTool runs the output-schema check on every result the request returns, before looking at resultType. An input_required result carries no structuredContent, so the check always fails for a tool with an outputSchema, and the caller never receives the input requests.
Expected
The docs for allowInputRequired say an input_required response is "handed back to the caller instead of being auto-fulfilled (or rejected)", and withInputRequired() says "input_required values pass through as-is, complete results validate against the wrapped schema." callTool should behave the same way: return the input_required result as it is, and validate structuredContent only on a complete result. An output schema describes a completed tool result; an input_required result is not one.
Reproduction
@modelcontextprotocol/client and @modelcontextprotocol/server 2.3.0 and 2.4.0 (and main at 5ee54ee). Run with Bun:
import { Client, StreamableHTTPClientTransport, isInputRequiredResult } from "@modelcontextprotocol/client";
import { Server, createMcpHandler } from "@modelcontextprotocol/server";
function build(): Server {
const server = new Server({ name: "repro", version: "1.0.0" }, { capabilities: { tools: {} } });
const inputSchema = { type: "object" as const, properties: {} };
server.setRequestHandler("tools/list", async () => ({
tools: [
{ name: "typed", inputSchema, outputSchema: { type: "object" as const, properties: { ok: { type: "boolean" } }, required: ["ok"] } },
{ name: "untyped", inputSchema },
],
}));
server.setRequestHandler("tools/call", async (_req, ctx) => {
if (!ctx.mcpReq.inputResponses?.confirm) {
return {
resultType: "input_required",
inputRequests: { confirm: { method: "elicitation/create", params: { message: "Proceed?", requestedSchema: { type: "object", properties: { yes: { type: "boolean" } } } } } },
requestState: "s1",
};
}
return { content: [{ type: "text" as const, text: "done" }], structuredContent: { ok: true } };
});
return server;
}
const handler = createMcpHandler(build);
const http = Bun.serve({ port: 0, fetch: (r) => handler.fetch(r) });
const client = new Client(
{ name: "repro-client", version: "1.0.0" },
{ capabilities: { elicitation: { form: {} } }, versionNegotiation: { mode: { pin: "2026-07-28" } } },
);
await client.connect(new StreamableHTTPClientTransport(new URL(`http://localhost:${http.port}/mcp`)));
await client.listTools();
for (const name of ["untyped", "typed"]) {
try {
const r = await client.callTool({ name, arguments: {} }, { allowInputRequired: true });
console.log(`${name}: returned, isInputRequiredResult=${isInputRequiredResult(r)}`);
} catch (e) {
console.log(`${name}: THREW ${(e as Error).message}`);
}
}
Output:
untyped: returned, isInputRequiredResult=true
typed: THREW Tool typed has an output schema but did not return structured content
Where it happens
packages/client/src/client/client.ts, callTool: after this.request(...) returns, the if (validator) block requires structuredContent on any result that is not isError, with no check of resultType.
Proposed fix
Return an input_required result before the output-schema check. isInputRequiredResult is already exported from @modelcontextprotocol/core-internal:
@@ callTool
+ if (isInputRequiredResult(result)) {
+ return result;
+ }
+
const validator = compiled !== undefined && compiled.ok ? compiled.validator : undefined;
if (validator) {
// If tool has outputSchema, it MUST return structuredContent (unless it's an error).
With this guard applied to the built 2.3.0 client, the reproduction prints isInputRequiredResult=true for both tools. The default auto-fulfil path is unaffected: there the driver completes the rounds inside request(), so callTool only ever sees a complete result, which still validates.
callTool is typed Promise<CallToolResult>, so the returned value needs a cast here, or, better, an overload that returns CallToolResult | InputRequiredResult when allowInputRequired: true, matching what withInputRequired() does for request().
Impact
This breaks any client that relays a server's input requests to its own user, such as a gateway or proxy that forwards a downstream client's elicitation capability. It happens as soon as the server both declares output schemas and asks for input, which some production servers now do for policy-gated reads and destructive actions. The workaround we use is to pass toolDefinition without its outputSchema, which disables output validation for the relayed call: https://github.com/NimbleBrainInc/nimblebrain/pull/2326
- Vorherrschende Sprache
- TypeScript
- Sterne
- 13.8k
- Forks
- 2.5k
- Ø Merge
- 6 T. 23 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/typescript-sdk
-
v2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` replyEvtl. vergeben @Tidehyc hat das vor 7 Tagen übernommen. Offenv2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
UriTemplate.match() throws a TypeError on an empty expression it acceptsEvtl. vergeben @yunusemrejs hat das vor 12 Tagen übernommen. Offenv1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
`OpenIdProviderDiscoveryMetadataSchema` strips `revocation_endpoint`, so clients can't revoke against OIDC-only authorization serversEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenv1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/typescript-sdk#3213 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in modelcontextprotocol/typescript-sdk
Ähnliche Issues
-
clawsweeper:intake:bug clawsweeper:intake:needs-environment
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
openclaw/openclaw#212827 · 1 Kommentar · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
KT-2245 e2e specs that call the backend directly fall back to the developer's own Kronn on :3140Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Use one constant for the 10,000-character input limitEvtl. vergeben @NginxL hat das heute übernommen. Offengood first issue refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
aniru-dh21/snap-validate#51 ·
Maintainer antworten meist innerhalb von 1 Tag
-
dependencies effort: small good first issue priority: low
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
TMHSDigital/screencast-mcp#509 ·
Maintainer antworten meist innerhalb von 1 Tag
-
from-review tech-debt testing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
blamechris/chroxy#9520 ·
Maintainer antworten meist innerhalb von 1 Tag