mcp: add ttl for list results (SEP-2549) (#1008)

Fixes #994
This commit is contained in:
Guglielmo Colombo 2026-06-18 15:20:21 +02:00 • committed by GitHub
commit 6333aa7c63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2227,6 +2227,20 @@ func TestStreamableParamHeadersClientSetsHeaders(t *testing.T) {
return &CallToolResult{Content: []Content{&TextContent{Text: "ok"}}}, nil
})
// Install a receiving middleware on the server that opts the tools/list
// response caching by setting a positive ttlMs.
server.AddReceivingMiddleware(func(next MethodHandler) MethodHandler {
return func(ctx context.Context, method string, req Request) (Result, error) {
res, err := next(ctx, method, req)
if err == nil && method == methodListTools {
if r, ok := res.(*ListToolsResult); ok {
r.TTLMs = 60_000
}
}
return res, err
}
})
handler := NewStreamableHTTPHandler(func(req *http.Request) *Server { return server }, &StreamableHTTPOptions{
Stateless: true,
})