From 4c543514c463cbed8a4cde661be0f1a82d3a55be Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Mon, 9 Jun 2025 14:24:11 -0400 Subject: [PATCH] internal/mcp: resource template iterator Add Client.ResourceTemplates Test forthcoming. Change-Id: I35e8ee8fabdf8fa216456ab3fcd0c8a7de9287c8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/680255 Reviewed-by: Robert Findley LUCI-TryBot-Result: Go LUCI Reviewed-by: Sam Thanawalla --- mcp/client.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mcp/client.go b/mcp/client.go index daebfa8..e30eec9 100644 --- a/mcp/client.go +++ b/mcp/client.go @@ -383,6 +383,19 @@ func (cs *ClientSession) Resources(ctx context.Context, params *ListResourcesPar }) } +// ResourceTemplates provides an iterator for all resource templates available on the server, +// automatically fetching pages and managing cursors. +// The `params` argument can set the initial cursor. +// Iteration stops at the first encountered error, which will be yielded. +func (cs *ClientSession) ResourceTemplates(ctx context.Context, params *ListResourceTemplatesParams) iter.Seq2[ResourceTemplate, error] { + if params == nil { + params = &ListResourceTemplatesParams{} + } + return paginate(ctx, params, cs.ListResourceTemplates, func(res *ListResourceTemplatesResult) []*ResourceTemplate { + return res.ResourceTemplates + }) +} + // Prompts provides an iterator for all prompts available on the server, // automatically fetching pages and managing cursors. // The `params` argument can set the initial cursor.