`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- bun, typescript
调研方向
从 packages/client/src/client/client.ts 中的 callTool 开始。issue 指出,在检查 resultType 之前,会对每个结果运行输出 schema 验证。阅读 allowInputRequired 的处理逻辑和现有的 isInputRequiredResult 用法,然后检查与输出 schema 验证及输入必需结果相关的客户端测试。完成标准是输入必需结果能够直接通过,同时完整结果仍会验证其结构化内容。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- TypeScript
- 星标
- 13.8k
- 派生
- 2.5k
- 平均合并
- 6 天 23 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/typescript-sdk 的其他 Issue
-
v2
难度 1/5 1 小时以内 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 条评论 ·
维护者通常 1 天内回复
-
v2
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 条评论 ·
维护者通常 1 天内回复
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` reply可能已有人在做 @Tidehyc 于 7 天前认领。 未关闭v2
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 条评论 ·
维护者通常 1 天内回复
-
UriTemplate.match() throws a TypeError on an empty expression it accepts可能已有人在做 @yunusemrejs 于 12 天前认领。 未关闭v1 v2
难度 2/5 1-3 小时 新手友好度 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 条评论 ·
维护者通常 1 天内回复
-
`OpenIdProviderDiscoveryMetadataSchema` strips `revocation_endpoint`, so clients can't revoke against OIDC-only authorization servers可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭v1 v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/typescript-sdk#3213 · 3 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/typescript-sdk 的全部 Issue
相似的 Issue
-
clawsweeper:intake:bug clawsweeper:intake:needs-environment
难度 2/5 1-3 小时 新手友好度 82/100
openclaw/openclaw#212827 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
KT-2245 e2e specs that call the backend directly fall back to the developer's own Kronn on :3140未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Use one constant for the 10,000-character input limit可能已有人在做 @NginxL 今天认领。 未关闭good first issue refactor
难度 2/5 1-3 小时 新手友好度 78/100
aniru-dh21/snap-validate#51 ·
维护者通常 1 天内回复
-
dependencies effort: small good first issue priority: low
难度 1/5 1-3 小时 新手友好度 88/100
TMHSDigital/screencast-mcp#509 ·
维护者通常 1 天内回复
-
from-review tech-debt testing
难度 2/5 1-3 小时 新手友好度 82/100
blamechris/chroxy#9520 ·
维护者通常 1 天内回复