[v2] Client rounds integers above Number.MAX_SAFE_INTEGER in server messages
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 55/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
调研方向
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 内容生成。
描述
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 byReadBufferand the stdio transportpackages/client/src/client/streamableHttp.ts: SSE events and JSON responsespackages/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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/typescript-sdk 的其他 Issue
-
v2
难度 1/5 1 小时以内 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3270 · 1 条评论 ·
维护者通常 1 天内回复
-
`callTool` with `allowInputRequired: true` throws on an `input_required` result when the tool declares an `outputSchema`可能已有人在做 @mgoldsborough 于 6 天前认领。 未关闭v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/typescript-sdk#3249 ·
维护者通常 1 天内回复
-
v2
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/typescript-sdk#3243 · 3 条评论 ·
维护者通常 1 天内回复
-
TypeScript client accepts an unknown `resultType` in the first `server/discover` reply可能已有人在做 @Tidehyc 于 7 天前认领。 未关闭v2
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/typescript-sdk#3235 · 3 条评论 ·
维护者通常 1 天内回复
-
UriTemplate.match() throws a TypeError on an empty expression it accepts可能已有人在做 @yunusemrejs 于 12 天前认领。 未关闭v1 v2
难度 2/5 1-3 小时 新手友好度 80/100
modelcontextprotocol/typescript-sdk#3221 · 3 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/typescript-sdk 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 68/100
Vessel9817/onion-site-template#512 ·
维护者通常 1 天内回复
-
nightly-tests
难度 2/5 1-3 小时 新手友好度 68/100
BlackBeltTechnology/pi-agent-dashboard#1256 ·
维护者通常 1 天内回复
-
approved
难度 2/5 1-3 小时 新手友好度 85/100
fritzprix/libr-agent#3266 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
better-auth/better-auth#13101 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复