A handler's -32002 (resource not found) is rewritten to -32602 on 2025-era sessions

Đang mở
#3,266 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Viv786ek đang làm issue này rồi.

Từ ngày 3/12/2026.

  • #3272 của @Viv786ek — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/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ệ
node.js, typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

The issue identifies the era codecs and ProtocolError.fromError as the affected paths, but gives no file paths or test names. Start by locating the -32002 mapping and the client error conversion, then read the protocol version negotiation and existing error tests. Done means a 2025-11-25 session preserves -32002 on the wire and client error, while the 2026-07-28 behavior remains correct.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

v2

Packages: @modelcontextprotocol/server and @modelcontextprotocol/client 2.4.0
Compared with: @modelcontextprotocol/sdk 1.32.1
Runtime: Node.js 24.22.1

Summary

Both era codecs map an error code of -32002 to -32602 (encodeErrorCode: (code) => code === -32002 ? -32602 : code), so a resources/read handler that throws -32002 answers -32602 on a session that negotiated 2025-11-25, not only on 2026-07-28. SEP-2164 (implemented here in #2194) moves a missing resource to -32602 in the 2026-07-28 revision, but the 2025-11-25 specification still lists -32002, and servers and clients built on 1.x send and check that code. On the client side, ProtocolError.fromError turns a -32002 whose data carries uri into ResourceNotFoundError, whose code is -32602, so a client can no longer see that the server sent -32002.

Reproduction

const { Server, InMemoryTransport, ProtocolError } = require('@modelcontextprotocol/server');
const { Client } = require('@modelcontextprotocol/client');

(async () => {
  const server = new Server({ name: 'repro', version: '1.0.0' }, { capabilities: { resources: {} } });
  server.setRequestHandler('resources/read', async (request) => {
    throw new ProtocolError(-32002, `Resource not found: ${request.params.uri}`, { uri: request.params.uri });
  });
  const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
  await server.connect(serverTransport);
  const client = new Client({ name: 'c', version: '1' });
  await client.connect(clientTransport);
  console.log('negotiated:', client.getNegotiatedProtocolVersion()); // 2025-11-25

  const deliver = clientTransport.onmessage;
  clientTransport.onmessage = (message, extra) => {
    if (message.error) console.log('wire error code:', message.error.code);
    deliver(message, extra);
  };
  const error = await client.readResource({ uri: 'file:///missing.txt' }).catch((e) => e);
  console.log('client error:', error.constructor.name, error.code);
})();

Expected (2025-11-25 session)

wire error code: -32002
client error: … -32002

(1.32.1 prints -32002 for both.)

Actual

wire error code: -32602
client error: ResourceNotFoundError -32602

Suggestion

Map -32002 to -32602 only in the 2026-07-28 codec, so a 2025-era session keeps the code its revision documents, or let a server opt out of the mapping. On the client, keep the received code on the error (for example as code, with the normalized code elsewhere), so code written against 2025-era servers keeps working.

Ngôn ngữ chính
TypeScript
Star
13.8k
Fork
2.5k
Merge trung bình
6 ngày 23 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/typescript-sdk

Tất cả issue của modelcontextprotocol/typescript-sdk

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.