Skip to content

mcp: add ListResourcesHandler for dynamic resources/list#1002

Open
piyushbag wants to merge 3 commits into
modelcontextprotocol:mainfrom
piyushbag:fix-998-list-resources-handler
Open

mcp: add ListResourcesHandler for dynamic resources/list#1002
piyushbag wants to merge 3 commits into
modelcontextprotocol:mainfrom
piyushbag:fix-998-list-resources-handler

Conversation

@piyushbag

Copy link
Copy Markdown

Problem

resources/list is backed only by a static in-memory set populated via AddResource. Gateway servers that proxy upstream catalogs and template-served skill assets cannot enumerate resources on demand: reads work via ResourceHandler, but listing does not.

Approach

Add ListResourcesHandler on ServerOptions, analogous to ResourceHandler for reads:

  • Handler only (no static resources): client pagination cursors pass through unchanged. Suitable for gateway/proxy servers.
  • Handler + static resources: SDK paginates registered resources first, then invokes the handler for subsequent pages using an internal composite cursor.
  • Capability: advertise resources when the handler is set, even if no resources were added statically.

resources/directory/read backing is intentionally deferred until custom-method support (#956) lands.

Why this helps

  • First-class, typed registration instead of intercepting resources/list in middleware.
  • Preserves existing static AddResource behavior when no handler is configured.
  • Composes static and dynamic catalogs for template-backed servers that also register fixed entries.

Test plan

  • go test ./mcp/ -run TestListResourcesHandler
  • go test ./...
  • go test -race ./mcp/ -run TestListResourcesHandler

Fixes #998

piyushbag added 3 commits June 9, 2026 21:11
Adds ServerOptions.ListResourcesHandler so gateway and template-backed
servers can serve resources/list on demand. Static AddResource entries
are listed first when present; handler cursors pass through when they are not.

Fixes modelcontextprotocol#998
@piyushbag

Copy link
Copy Markdown
Author

Local verification on fix-998-list-resources-handler (855cf72):

go test ./... -count=1
ok  github.com/modelcontextprotocol/go-sdk/mcp
ok  github.com/modelcontextprotocol/go-sdk/oauthex

go test -race ./mcp/... -run TestListResourcesHandler -count=1
ok  github.com/modelcontextprotocol/go-sdk/mcp

I kept resources/directory/read out of scope per the PR note until custom methods (#956) land. Open to splitting static+dynamic pagination into a follow-up if maintainers want a smaller first merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: dynamic/lazy resources/list (and directory-read) backing for gateway/proxy and template-served catalogs

1 participant