experimental.tasks.getTaskResult() throws TypeError: Cannot read properties of undefined (reading '_zod') when the optional result schema is omitted
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- api
Hướng nghiên cứu
Bắt đầu trong src/experimental/tasks/client.ts và so sánh getTaskResult với cách xử lý schema mặc định trong getTask và listTasks. Theo dõi schema được chuyển tiếp qua Protocol.getTaskResult trong src/shared/protocol.ts và tái hiện vấn đề bằng ví dụ InMemoryTransport được cung cấp. Hoàn tất khi gọi getTaskResult(taskId) mà không có schema không còn gây ra lỗi, trong khi cách khắc phục bằng schema tường minh vẫn được hỗ trợ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
client.experimental.tasks.getTaskResult(taskId) throws TypeError: Cannot read properties of undefined (reading '_zod') when called without an explicit result schema, which its type signature says is optional.
ExperimentalClientTasks.getTaskResult declares resultSchema?: T (src/experimental/tasks/client.ts) and forwards it to Protocol.getTaskResult, whose signature requires it (resultSchema: T) and passes it straight into request(). With undefined, validation reaches isZ4Schema(undefined) in src/server/zod-compat.ts, which reads ._zod off it.
Because the throw happens in _onresponse — inside the transport's message handler rather than in the awaited call path — it is also awkward to catch from application code.
Compare getTask and listTasks, which both pass a default schema; getTaskResult appears to have been missed.
Reproduction
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import { InMemoryTaskStore } from "@modelcontextprotocol/sdk/experimental/tasks/stores/in-memory.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
const store = new InMemoryTaskStore();
const server = new Server(
{ name: "repro", version: "1.0.0" },
{
capabilities: { tools: {}, tasks: { list: {}, cancel: {}, requests: { tools: { call: {} } } } },
taskStore: store,
},
);
server.setRequestHandler(ListToolsRequestSchema, () => ({
tools: [{ name: "t", inputSchema: { type: "object" } }],
}));
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
const task = await extra.taskStore.createTask({ ttl: 60000 });
await extra.taskStore.storeTaskResult(task.taskId, "completed", {
content: [{ type: "text", text: "done" }],
});
return { task };
});
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
const client = new Client({ name: "repro-client", version: "1.0.0" });
await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]);
let taskId = "";
for await (const message of client.experimental.tasks.callToolStream({
name: "t",
arguments: {},
task: { ttl: 60000 },
})) {
if (message.type === "taskCreated") { taskId = message.task.taskId; break; }
if (message.type === "result") { taskId = message.result.task?.taskId ?? ""; break; }
}
await client.experimental.tasks.getTaskResult(taskId); // TypeError
Expected
Either getTaskResult defaults to CallToolResultSchema (or ResultSchema) the way getTask and listTasks default theirs, or the parameter is made required so the type signature matches the behaviour.
Actual
TypeError: Cannot read properties of undefined (reading '_zod')
at isZ4Schema (src/server/zod-compat.ts:60)
at safeParse (src/server/zod-compat.ts:82)
at src/shared/protocol.ts:1199
at Client._onresponse (src/shared/protocol.ts:928)
Workaround
Pass the schema explicitly:
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
await client.experimental.tasks.getTaskResult(taskId, CallToolResultSchema);
Environment
@modelcontextprotocol/sdk1.30.0- Node 22.23.1, macOS
- Both
zod@3.25.76andzod@4.1.5present in the workspace; reproduced via the v3-resolved copy.
Happy to open a PR adding the default if that is the direction you would prefer.
- Ngôn ngữ chính
- TypeScript
- Star
- 13.4k
- Fork
- 2.2k
- Merge trung bình
- 3 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 3
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/typescript-sdk
-
Auth metadata discovery: fallback URL built on resource host instead of authorization-server host Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
modelcontextprotocol/typescript-sdk#2783 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
modelcontextprotocol/typescript-sdk#2766 · 1 bình luận ·
-
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 72/100
Tất cả issue của modelcontextprotocol/typescript-sdk
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Đang mởbug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Client support matrix inclusion Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
calcite-components needs triage refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Esri/calcite-design-system#15203 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
fullcalendar/fullcalendar#8106 ·