mcp: SchemaCache grows by one entry per AddTool call for tools with an any input
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- backend-api-design
Direzione di ricerca
Leggi toolForErr in mcp/server.go ed esamina il comportamento della cache dello schema con input any. Aggiungi un test di regressione che chiami ripetutamente AddTool con un SchemaCache condiviso e confermi che la cache non cresce a ogni chiamata. Il lavoro è completato quando il test passa e l’uso della memoria rimane limitato, come per gli input struct.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Checklist
- I searched the existing issues, and this has not been reported before.
- This is a real problem that I ran into myself, using the latest release of the SDK.
- I ran into it in a production system, not in a toy example, a benchmark, or an automated or AI-driven scan of the code.
- I (a human) examined the relevant SDK code, and wrote or reviewed every line of this report. It is not unreviewed AI output.
- This report is brief and concise, and sticks to the facts needed to understand the problem.
What happened?
With a shared SchemaCache, every AddTool call for a tool whose input type is any adds a new cache entry that is never used again. So a stateless server (new Server per request, one shared cache) keeps using more memory forever. Tools with a struct input don't have this problem.
Cause: toolForErr (mcp/server.go) makes a new &jsonschema.Schema{Type: "object"} for an any input on every call. The cache stores schemas by pointer, so it never finds the old one and adds a new entry each time.
Expected: memory stays flat, like it does for struct inputs.
I'd like to fix this (small change in toolForErr plus a test) if that's OK. I used an AI assistant to help find this and draft the report; I ran the repro and checked the code myself.
How to reproduce
package main
import (
"context"
"fmt"
"runtime"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
cache := mcp.NewSchemaCache()
for i := 0; i < 100_000; i++ {
s := mcp.NewServer(&mcp.Implementation{Name: "s", Version: "v0"}, &mcp.ServerOptions{SchemaCache: cache})
mcp.AddTool(s, &mcp.Tool{Name: "ping"}, func(context.Context, *mcp.CallToolRequest, any) (*mcp.CallToolResult, any, error) {
return nil, nil, nil
})
}
runtime.GC()
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("heap: %.0f MB\n", float64(m.HeapAlloc)/(1<<20))
runtime.KeepAlive(cache)
}
Prints about heap: 168 MB. With a struct input instead of any, it stays under 1 MB.
Go MCP SDK version
v1.8.0 (also on main at 13d3c71)
Go version
go1.27.4 windows/amd64
- Lingua principale
- Go
- Stelle
- 5.4k
- Fork
- 623
- Merge medio
- 22h 10m
- PR unite (30g)
- 30
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di modelcontextprotocol/go-sdk
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into anyForse di nuovo libera @beiryu l’ha presa 10 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
modelcontextprotocol/go-sdk#1534 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertaneeds investigation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
modelcontextprotocol/go-sdk#745 · 13 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
modelcontextprotocol/go-sdk#1555 ·
I maintainer di solito rispondono entro 1 giorno
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requestsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
modelcontextprotocol/go-sdk#1552 ·
I maintainer di solito rispondono entro 1 giorno
-
mcp: stateless subscriptions/listen stream can start with an unrequested tools/list_changedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
modelcontextprotocol/go-sdk#1551 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di modelcontextprotocol/go-sdk
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
apache/dubbo-admin#1659 ·
I maintainer di solito rispondono entro 8 giorni
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindForse già presa @arshil42 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100