modelcontextprotocol / modelcontextprotocol/typescript-sdk

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

Aperta
#2,012 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug fix proposed P2 ready for work
Lingua principale
TypeScript
Stelle
13.4k
Fork
2.2k
Merge medio
3g 15h
PR unite (30g)
4

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da CallToolRequestParamsSchema e dal gestore del protocollo intorno a protocol.ts:672, quindi riproduci la richiesta tramite stdio usando il JSON mostrato. Il lavoro è completato quando tools/call accetta gli argomenti null come assenti e i dati della richiesta non validi producono l’errore InvalidParams del protocollo invece di InternalError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
66/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.