Skip to content

mcp: preserve structured content number precision - #1239

Merged
guglielmo-san merged 3 commits into
modelcontextprotocol:mainfrom
CaliLuke:codex/issue-1236-structured-content-numbers
Sep 16, 2026
Merged

guglielmo-san merged 3 commits into
modelcontextprotocol:mainfrom
CaliLuke:codex/issue-1236-structured-content-numbers

Conversation

@CaliLuke

@CaliLuke CaliLuke commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

CallToolResult currently decodes structuredContent through an any field, which converts JSON numbers to float64 and silently rounds integers outside the IEEE-754 safe range.

This change decodes structuredContent separately with UseNumber, preserving wire numbers as json.Number while retaining the existing decoded object, array, and primitive shapes. The field documentation now describes that representation. Users who depend on the previous float64 behavior can temporarily restore it with MCPGODEBUG=structuredcontentfloat64=1.

An end-to-end in-memory client/server regression covers 9007199254740993 from a low-level Server.AddTool result. Additional coverage verifies the compatibility option restores the legacy rounded float64 value.

Verification:

  • gofmt -l .
  • go test ./...
  • go vet ./...

Fixes #1236

Comment thread mcp/protocol.go
@guglielmo-san

Copy link
Copy Markdown
Contributor

Thank you for the contribution!

@guglielmo-san
guglielmo-san merged commit 3785c50 into modelcontextprotocol:main Sep 16, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: CallToolResult structuredContent loses large integer precision

2 participants