mcp: typed tool arguments lose precision for large int64 values
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
mcp/tool.go から始め、提供されたインメモリ再現を最初の確認として使用しながら、AddTool の引数スキーマの適用とデフォルトパスを追跡してください。int64 値 9007199254740993 を対象とするリグレッションテストを追加し、既存のバリデーションと末尾データの動作を維持したまま、型付きハンドラーがその値を変更せずに受け取ることを検証してください。
索引モデルが 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時間
- マージ済み PR(30日)
- 82
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/go-sdk のほかの issue
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンneeds investigation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/go-sdk#745 · コメント 13 件 · リアクション 1 件 ·
メンテナーはふだん 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
-
enhancement needs:sonnet ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
microsoft/TypeScript#65370 ·
メンテナーはふだん 1 日以内に返信
-
docs: data-ownership invites vendors to build add-ons around the OS対応中かも @brandli が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
gentian-org/gentian-os#894 ·
メンテナーはふだん 1 日以内に返信
-
bug tech debt testing
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws/amazon-vpc-cni-k8s#3976 ·
メンテナーはふだん 1 日以内に返信
-
bug raised-by:desk
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
medici-finance/assay#5678 ·
メンテナーはふだん 1 日以内に返信