Skip to content

fix: resource refresh button now bypasses cache to re-read content#1155

Open
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
ctonneslan:fix/resource-refresh-button
Open

fix: resource refresh button now bypasses cache to re-read content#1155
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
ctonneslan:fix/resource-refresh-button

Conversation

@ctonneslan
Copy link

Problem

The refresh button in the Resources tab does nothing when clicked. This is because readResource() early-returns when the URI already exists in resourceContentMap:

if (fetchingResources.has(uri) || resourceContentMap[uri]) {
  return; // <-- cached content prevents re-read
}

Since the content was cached from the first read, clicking refresh has no effect. This also affects switching between resource template URIs (e.g. user://1 -> user://2 -> user://1) where the cached content is shown without re-reading.

Regression introduced around v0.20.0 when the resourceContentMap cache was added.

Fix

Added a force parameter to readResource() that bypasses the cache check:

const readResource = async (uri: string, force: boolean = false) => {
  if (fetchingResources.has(uri)) {
    return;
  }
  if (!force && resourceContentMap[uri]) {
    return;
  }
  // ... fetch from server

The refresh button passes force=true. Initial reads from the resource list still use the cache for performance.

Changes

  • client/src/App.tsx: Added force parameter to readResource(), updated prop wrapper
  • client/src/components/ResourcesTab.tsx: Updated prop type, refresh button passes force=true

Fixes #1120

The refresh button in the Resources tab was not working because
readResource() early-returns when the URI already exists in
resourceContentMap. Since the content was cached from the first
read, clicking refresh had no effect.

Added a force parameter to readResource() that bypasses the cache
check. The refresh button passes force=true while initial reads
still use the cache for performance.

Also fixes the issue where switching between resource template
URIs (e.g. user://1 then user://2 then back to user://1) would
show stale cached content without re-reading from the server.

Fixes modelcontextprotocol#1120
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.

Resource refresh button is not working

1 participant