mcp: typed tool arguments lose precision for large int64 values
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 74/100
Línea de trabajo
Comienza en mcp/tool.go y sigue la aplicación del esquema de argumentos de AddTool y la ruta predeterminada, usando la reproducción proporcionada en memoria como primera comprobación. Añade una prueba de regresión que cubra el valor int64 9007199254740993 y verifica que el handler tipado lo recibe sin cambios, mientras la validación existente y el comportamiento ante datos posteriores permanecen intactos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Go
- Estrellas
- 5.3k
- Forks
- 607
- Merge medio
- 1 d 11 h
- PR fusionados (30 d)
- 82
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/go-sdk
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoneeds investigation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/go-sdk#745 · 13 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
mcp: whether MaxLineLength rejects a message depends on how the stream is readPosiblemente ocupada @Tangerg la tomó hoy. Abierto
modelcontextprotocol/go-sdk#1509 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
modelcontextprotocol/go-sdk#1506 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
mcp: closing a session right after a cancelled call drops notifications/cancelled, so the server handler keeps runningPosiblemente ocupada @vshalpnjabi la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
modelcontextprotocol/go-sdk#1505 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
mcp: a canceled write on IOTransport/StdioTransport cannot leave the write queuePosiblemente ocupada @Tangerg la tomó hace 1 día. Abierto
modelcontextprotocol/go-sdk#1498 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/go-sdk
Issues similares
-
enhancement needs:sonnet ready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/TypeScript#65370 ·
Los mantenedores suelen responder en 1 día
-
docs: data-ownership invites vendors to build add-ons around the OSPosiblemente ocupada @brandli la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
gentian-org/gentian-os#894 ·
Los mantenedores suelen responder en 1 día
-
bug tech debt testing
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
aws/amazon-vpc-cni-k8s#3976 ·
Los mantenedores suelen responder en 1 día
-
bug raised-by:desk
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
medici-finance/assay#5678 ·
Los mantenedores suelen responder en 1 día