mcp: SchemaCache grows by one entry per AddTool call for tools with an any input
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Đọc toolForErr trong mcp/server.go và kiểm tra hành vi của bộ nhớ đệm schema với đầu vào any. Thêm một bài kiểm thử hồi quy gọi AddTool nhiều lần với một SchemaCache dùng chung và xác nhận bộ nhớ đệm không tăng lên sau mỗi lần gọi. Công việc được xem là hoàn tất khi bài kiểm thử chạy qua và mức sử dụng bộ nhớ được giới hạn, như với đầu vào struct.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Go
- Star
- 5.4k
- Fork
- 623
- Merge trung bình
- 22 giờ 10 phút
- Pull request đã merge (30 ngày)
- 30
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/go-sdk
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into anyCó thể làm lại được @beiryu đã nhận 10 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/go-sdk#1534 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởneeds investigation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/go-sdk#745 · 13 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
modelcontextprotocol/go-sdk#1555 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requestsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/go-sdk#1552 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: stateless subscriptions/listen stream can start with an unrequested tools/list_changedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
modelcontextprotocol/go-sdk#1551 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/go-sdk
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
apache/dubbo-admin#1659 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindCó thể đã có người làm @arshil42 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Packaging: support mise-en-placeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100