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

Ouverte
#3,150 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
55/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
Active
Stack technique
node.js, typescript
Domaine
api, backend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
TypeScript
Étoiles
13.8k
Forks
2.5k
Merge moyen
6 j 23 h
PR mergées (30 j)
2

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/typescript-sdk

Toutes les issues de modelcontextprotocol/typescript-sdk

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.