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

未關閉
#3,150 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
node.js, typescript
領域
api, backend

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
TypeScript
星號
13.8k
分支
2.5k
平均合併
6 天 23 小時
30 天內合併 PR
2

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/typescript-sdk 的其他 Issue

查看 modelcontextprotocol/typescript-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。