mcp: tool schemas and metadata lose JSON number precision

Aperta
#1,310 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Tangerg ci sta già lavorando.

Dal 28/9/2026.

  • #1311 di @Tangerg — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
api

Direzione di ricerca

Start at the Tool and CallToolResult wire decoding entry points and inspect the existing UnmarshalUseNumber helper. Reproduce the issue over the serialized in-memory NDJSON transport and Streamable HTTP, then verify that schema and metadata numbers retain their original precision while structuredContent remains unchanged.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

On upstream main at 7cb505cc11ed7bda8b8db8b12cd62fec22e0e1f8 (Go 1.27.0, darwin/arm64), tools/list schema numbers and tool/result/content _meta numbers are rounded before the client receives them. structuredContent already preserves these numbers.

For example, register a tool with the low-level Server.AddTool API using this raw input/output schema:

{"type":"object","properties":{"id":{"const":9007199254740993}},"required":["id"]}

Return structuredContent: {"id":9007199254740993} and _meta: {"revision":9007199254740993}. After client/server transport, the schema constant and metadata revision re-marshal as 9007199254740992, while structured content still contains 9007199254740993. The same loss affects tool metadata, text content metadata, resource-link metadata, and embedded resource metadata. Negative large integers and high-precision decimals are also affected.

Expected: preserve numeric values in these arbitrary JSON fields at the protocol decode boundary, so consumers can use their original schemas and metadata. This is about descriptor/result fidelity, not implementing a new schema validator.

A regression reproduces this over both the SDK's serialized in-memory NDJSON transport and Streamable HTTP. It does not involve a downstream fork or custom transport decoder.

This differs from #1201 / #1244 / #1302, which address server-side applySchema, and from the explicit-null fix in #1285.

Proposed change: decode Tool and the CallToolResult wire object with the existing UnmarshalUseNumber helper. This keeps exported fields intact but changes decoded dynamic numeric types from float64 to json.Number for the affected fields. Callers asserting float64 need to adapt; maintainer agreement on this behavioral compatibility change is needed. No new compatibility switch or alternate value format is proposed. The current schema-validation dependency's precision limitations remain a separate concern.

Lingua principale
Go
Stelle
5.4k
Fork
623
Merge medio
22h 10m
PR unite (30g)
30

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/go-sdk

Tutte le issue di modelcontextprotocol/go-sdk

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.