Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into any

Aperta Adatta ai principianti
#1,534 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@beiryu ci sta già lavorando.

Dal 19/11/2026.

  • #1535 di @tang-ontheway — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Inizia da mcp/streamable_headers.go e leggi extractName, che decodifica params per ottenere il nome di tools/call e prompts/get. Modifica la struttura di decodifica in modo che legga solo il nome, quindi aggiungi o esegui un test di regressione per gli argomenti numerici fuori intervallo tramite Streamable HTTP. Il lavoro è completato quando il client può impostare Mcp-Name e il server accetta e inoltra la chiamata preservando gli argomenti.

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

Descrizione

Summary

Under protocol version 2026-07-28, a tools/call whose arguments contain a valid JSON number outside float64's range (for example {"n":1e1000}) fails over Streamable HTTP before it reaches the tool handler. This happens on both the client and the server side.

Cause

extractName (mcp/streamable_headers.go) gets the tool name for the Mcp-Name header by unmarshaling the whole params into CallToolParams, whose Arguments field is any. Decoding 1e1000 into any fails because the number overflows float64. The error is swallowed (return "", false), so:

  • client: ClientSession.CallTool can't set Mcp-Name, and the request is rejected: missing required Mcp-Name header for method "tools/call": rejected by transport: Bad Request;
  • server: the same function is used to compare the header with the body (around line 382), so a request from another client that does send the header is also rejected before dispatch.

A raw ToolHandler receives Arguments as json.RawMessage and would otherwise get these bytes unchanged. Over stdio, in memory, or under an older protocol version, the same call works.

Reproduction (v1.8.0)
s := mcp.NewServer(&mcp.Implementation{Name: "s", Version: "v0"}, nil)
s.AddTool(&mcp.Tool{Name: "echo", InputSchema: json.RawMessage(`{"type":"object"}`)},
	func(_ context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
		return &mcp.CallToolResult{Content: []mcp.Content{&mcp.TextContent{Text: string(req.Params.Arguments)}}}, nil
	})
ts := httptest.NewServer(mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server { return s },
	&mcp.StreamableHTTPOptions{Stateless: true, JSONResponse: true}))
defer ts.Close()

cs, _ := mcp.NewClient(&mcp.Implementation{Name: "c", Version: "v0"}, nil).
	Connect(ctx, &mcp.StreamableClientTransport{Endpoint: ts.URL}, nil)
// cs.InitializeResult().ProtocolVersion == "2026-07-28"
_, err := cs.CallTool(ctx, &mcp.CallToolParams{Name: "echo", Arguments: json.RawMessage(`{"n":1e1000}`)})
// err: calling "tools/call": sending "tools/call": missing required Mcp-Name header for method "tools/call": rejected by transport: Bad Request

With {"n":12345678901234567890} the call succeeds and the handler receives the bytes unchanged, so only out-of-range numbers are affected.

Suggested fix

extractName needs only the name, so it can decode into a struct with just that field. That avoids decoding the arguments at all, which is also cheaper for large argument payloads:

case "tools/call", "prompts/get":
	var p struct{ Name string `json:"name"` }
	if err := internaljson.Unmarshal(params, &p); err == nil {
		return p.Name, true
	}

prompts/get has the same shape (its Arguments is map[string]string, so it fails differently, on non-string values).

Found while building an MCP server on the go-sdk, where a test now pins this behavior.

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.