Skip to content

MCP: cache resource catalogs per connection like tools and prompts #52852

Open

Description

@davdroman

Description

OpenCode V2 sends another resources/list and resources/templates/list request for every resource catalog read, even when callers share the same live connection and the catalog has not changed. Concurrent reads multiply that traffic.

With a generic local MCP server, eight concurrent reads through Mcp.Service.resourceCatalog() and Mcp.Service.resources() produced eight requests for each list operation. One shared request per operation would be enough for that burst.

A short-lived cache of successful discovery results, with invalidation on resource-list notifications and connection teardown, would avoid these duplicate requests without keeping non-notifying servers stale indefinitely. Resource contents should still be read directly.

Plugins

No external plugins are needed for the core regression.

OpenCode version

V2 source checkout.

Steps to reproduce

The executed regression is coalesces concurrent MCP resource discovery and reuses successful catalogs in packages/core/test/mcp.test.ts in the proposed fix.

  1. Connect to the generic local MCP server in that test.
  2. Start eight concurrent reads, alternating resourceCatalog() and resources() on the same service.
  3. Count the server's resource-list and template-list requests.

The unpatched implementation sent eight of each. The fix sends one of each and reuses the successful results for subsequent reads within five seconds.

Screenshot and/or share link

Not applicable. The regression checks protocol request counts.

Operating System

macOS.

Terminal

Not applicable. This is a core integration test.

Activity

  1. changed the title [-]MCP resource discovery repeats identical requests on one live connection[/-] [+]MCP: cache resource catalogs per connection like tools and prompts[/+] on Oct 18, 2026
  2. opencode-agent commented on Oct 18, 2026

    @opencode-agent
    Contributor

    Retitling to the underlying gap. Tools and prompts are already fetched once per connection and refreshed on list_changed, but resource catalogs are re-fetched from the server on every list_mcp_resources call. Resources should be cached per connection the same way, and invalidated on notifications/resources/list_changed, reconnect and session recovery.

  3. Messier81 commented on Oct 26, 2026

    @Messier81

    Opened #59375 for this. It caches resource catalogs per connection and clears the cache on list_changed, reconnect and session recovery. Failed loads aren't cached.

  4. opencodejr commented on Oct 27, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and the test, @davdroman!

    You're asking for OpenCode V2 to cache MCP resource discovery (resources/list and resources/templates/list) per connection for a short time. Concurrent and repeated reads through resourceCatalog() / resources() would then share one request, and the cache would be cleared on resource-list notifications and connection teardown. Resource contents would still be read directly.

    Right now, resource catalogs are fetched live on every read by design, while tools and prompts are kept on the connection. So I'm tracking this as an improvement rather than a bug. Maintainers will consider it together with your PR.

    Related:

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions