Skip to content

mcp: add ListResourcesHandler for dynamic resources/list#1030

Open
piyushbag wants to merge 2 commits into
modelcontextprotocol:mainfrom
piyushbag:list-resources-handler
Open

mcp: add ListResourcesHandler for dynamic resources/list#1030
piyushbag wants to merge 2 commits into
modelcontextprotocol:mainfrom
piyushbag:list-resources-handler

Conversation

@piyushbag

Copy link
Copy Markdown
Contributor

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

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
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