modelcontextprotocol / modelcontextprotocol/typescript-sdk

tools/call with null arguments returns -32603 (InternalError) instead of being accepted

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

Chưa có ai nhận issue này.

bug fix proposed P2 ready for work
Ngôn ngữ chính
TypeScript
Star
13.4k
Fork
2.2k
Merge trung bình
3 ngày 15 giờ
Pull request đã merge (30 ngày)
4

Mô tả

When a client sends a tools/call request where arguments is null (rather than omitted or {}), the SDK returns -32603 InternalError with a raw Zod validation message instead of accepting the request.

This affects every server built on the TypeScript SDK. Clients that serialize missing/empty fields as null (common in Go, Java, and C# JSON libraries) cannot call tools without arguments.

Reproduce

Send this over stdio to any server built with @modelcontextprotocol/sdk:

{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"clientInfo":{"name":"test","version":"1.0"},"protocolVersion":"2025-11-25","capabilities":{}}}
{"jsonrpc":"2.0","method":"tools/call","id":2,"params":{"name":"echo","arguments":null}}

Expected

Request accepted (arguments treated as empty/undefined).

Actual

{
  "jsonrpc": "2.0",
  "id": 2,
  "error": {
    "code": -32603,
    "message": "[\n  {\n    \"expected\": \"record\",\n    \"code\": \"invalid_type\",\n    \"path\": [\"params\", \"arguments\"],\n    \"message\": \"Invalid input: expected record, received null\"\n  }\n]"
  }
}

Two problems:

  1. null rejected for an optional field. CallToolRequestParamsSchema uses .optional() which accepts undefined but not null. The MCP spec says arguments is optional; null should be treated as absent.

  2. Wrong error code. The error is -32603 (InternalError) instead of -32602 (InvalidParams). The protocol handler uses schema.parse() which throws a ZodError on failure. ZodError has no numeric code property, so the error handler at protocol.ts:672 falls back to ProtocolErrorCode.InternalError.

Impact

Tested against @modelcontextprotocol/server-everything: all 13 tools fail with this error when called with null arguments. Any Go, Java, or C# client that serializes missing fields as null will hit this on every server built with the TypeScript SDK.

Versions

  • @modelcontextprotocol/sdk main branch (also confirmed on published npm package)
  • Node.js v25.8.2

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu với CallToolRequestParamsSchema và trình xử lý giao thức quanh protocol.ts:672, sau đó tái hiện yêu cầu qua stdio bằng JSON được cung cấp. Hoàn tất khi tools/call chấp nhận các đối số null là không có và dữ liệu yêu cầu không hợp lệ tạo ra lỗi InvalidParams của giao thức thay vì InternalError.

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

Đánh giá

Công nghệ
typescript
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
66/100

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.