mcp: typed tool arguments lose precision for large int64 values
维护者通常 1 天内回复
评估
调研方向
从 mcp/tool.go 开始,使用提供的内存中复现作为首次检查,跟踪 AddTool 参数 schema 的应用和默认路径。添加一个覆盖 int64 值 9007199254740993 的回归测试,并验证 typed handler 接收到的值未发生变化,同时现有验证和尾随数据行为保持不变。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When using the typed mcp.AddTool API, an integer larger than the IEEE-754
safe integer range can be silently rounded before it reaches the tool handler.
The value is accepted as a JSON integer, but the handler receives a different
value.
To Reproduce
Environment:
- Go MCP SDK:
v1.7.0 - Go:
go1.25.7 linux/amd64
Save the following as main.go in a module that requires
github.com/modelcontextprotocol/go-sdk v1.7.0:
package main
import (
"context"
"fmt"
"log"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type input struct {
ID int64 `json:"id"`
}
func main() {
const want int64 = 9007199254740993 // 2^53 + 1
server := mcp.NewServer(
&mcp.Implementation{Name: "server", Version: "repro"}, nil)
mcp.AddTool(server, &mcp.Tool{Name: "echo_id"},
func(_ context.Context, _ *mcp.CallToolRequest, in input) (
*mcp.CallToolResult, input, error) {
fmt.Printf("handler_received=%d\n", in.ID)
return nil, in, nil
})
clientTransport, serverTransport := mcp.NewInMemoryTransports()
ctx := context.Background()
serverSession, err := server.Connect(ctx, serverTransport, nil)
if err != nil {
log.Fatal(err)
}
defer serverSession.Close()
client := mcp.NewClient(
&mcp.Implementation{Name: "client", Version: "repro"}, nil)
clientSession, err := client.Connect(ctx, clientTransport, nil)
if err != nil {
log.Fatal(err)
}
defer clientSession.Close()
_, err = clientSession.CallTool(ctx, &mcp.CallToolParams{
Name: "echo_id",
Arguments: map[string]any{"id": want},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("want=%d\n", want)
}
Run:
go mod init example.com/mcp-int64-repro
go get github.com/modelcontextprotocol/[email protected]
go run .
Observed output:
handler_received=9007199254740992
want=9007199254740993
The issue is reproducible with the in-memory transport and does not depend on
an external server.
Expected behavior
The typed tool handler should receive exactly the integer sent by the client:
handler_received=9007199254740993
want=9007199254740993
Values representable by Go int64 should not be silently changed during
schema validation or default application.
Logs
No error is returned. The value is silently rounded.
Additional context
The behavior appears to come from the schema application path in
mcp/tool.go: tool arguments are decoded into map[string]any, and the
generic JSON number is then represented as float64. Applying defaults causes
the value to be marshaled again, making the rounding observable before the
typed handler decodes it.
A possible implementation direction is to preserve JSON numbers (for example,
using Decoder.UseNumber()) while applying the schema and defaults, while
retaining strict validation of trailing JSON data. The low-level
Server.AddTool handler path does not have this particular schema round-trip,
but it also does not provide the typed validation/default behavior.
This affects any tool that accepts IDs or counters outside the IEEE-754 safe
integer range, even though those values are valid JSON integers and valid Go
int64 values.
- 主要语言
- Go
- 星标
- 5.3k
- 派生
- 607
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 82
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/go-sdk 的其他 Issue
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions可能重新可做 关联的 PR 已关闭且未合并。 未关闭needs investigation
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/go-sdk#745 · 13 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
mcp: whether MaxLineLength rejects a message depends on how the stream is read可能已有人在做 @Tangerg 今天认领。 未关闭
modelcontextprotocol/go-sdk#1509 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
modelcontextprotocol/go-sdk#1506 · 2 条评论 ·
维护者通常 1 天内回复
-
mcp: closing a session right after a cancelled call drops notifications/cancelled, so the server handler keeps running可能已有人在做 @vshalpnjabi 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
modelcontextprotocol/go-sdk#1505 · 1 条评论 ·
维护者通常 1 天内回复
-
mcp: a canceled write on IOTransport/StdioTransport cannot leave the write queue可能已有人在做 @Tangerg 于 1 天前认领。 未关闭
modelcontextprotocol/go-sdk#1498 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/go-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
openmcp-project/service-provider-crossplane#330 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
openmcp-project/service-provider-kro#220 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
[FEATURE]: Set fieldPath and reason on the CEL validation rules可能已有人在做 @bjosv 今天认领。 未关闭enhancement needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
valkey-io/valkey-operator#618 ·
维护者通常 3 天内回复