[v2] Client rounds integers above Number.MAX_SAFE_INTEGER in server messages

Aperta
#3,150 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
api, backend

Direzione di ricerca

Start by tracing JSON decoding in packages/core-internal/src/shared/stdio.ts, packages/client/src/client/streamableHttp.ts, and packages/client/src/client/sse.ts; compare the Go SDK fix linked in the issue. The issue proposes opt-in parse and stringify hooks while preserving existing defaults. Done means exact integer values can be decoded across the listed paths and existing consumers retain current behavior.

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

Descrizione

v1 v2
What happened?

The client silently rounds integers above Number.MAX_SAFE_INTEGER in server messages. A server written in Go, Rust, or Python can legitimately return {"id": 9007199254740993} in structuredContent (or any other result field), and the client hands the application 9007199254740992 with no error. The application cannot recover the original value, because the SDK owns the transport parsing.

Every client-side decode path uses plain JSON.parse:

  • packages/core-internal/src/shared/stdio.ts: deserializeMessage(), used by ReadBuffer and the stdio transport
  • packages/client/src/client/streamableHttp.ts: SSE events and JSON responses
  • packages/client/src/client/sse.ts

The Go SDK had the same bug for structuredContent (modelcontextprotocol/go-sdk#1236) and fixed it in modelcontextprotocol/go-sdk#1239.

What did you expect?

A way to decode numbers exactly. Changing the default to BigInt would break existing consumers, so an opt-in hook seems right: for example a parseJson?: (text: string) => unknown option on the client transports and on ReadBuffer/deserializeMessage. Clients could then use a JSON.parse reviver with context.source (available in Node 22+ and current browsers) or a library such as lossless-json. A matching stringifyJson option would let exact values round-trip in requests (for example with JSON.rawJSON).

Code to reproduce
import { deserializeMessage } from '@modelcontextprotocol/client';

const line = '{"jsonrpc":"2.0","id":1,"result":{"content":[],"structuredContent":{"id":9007199254740993}}}';
const message = deserializeMessage(line) as { result: { structuredContent: { id: number } } };
console.log(message.result.structuredContent.id);
// 9007199254740992
SDK version

@modelcontextprotocol/client 2.4.0 on Node 24.20.0. The same code is on main, and 1.x (1.32.2) has the same deserializeMessage.

Area

Transports

We ran into this in Volt, a coding agent that passes MCP tool results to sandboxed scripts and needs them exact. Happy to send a PR if the opt-in approach is acceptable.

Drafted with an AI coding agent; the reproduction above was run and verified.

Lingua principale
TypeScript
Stelle
13.8k
Fork
2.5k
Merge medio
6g 23h
PR unite (30g)
2

Preparare l'ambiente

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.

Altre issue di modelcontextprotocol/typescript-sdk

Tutte le issue di modelcontextprotocol/typescript-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.