Skip to content

fix(client): keep tool metadata intact when a listTools() refresh fails (v1.x) - #2618

Open
harshasiddartha wants to merge 288 commits into
modelcontextprotocol:v1.xfrom
harshasiddartha:fix/2614-atomic-tool-metadata-cache
Open

harshasiddartha wants to merge 288 commits into
modelcontextprotocol:v1.xfrom
harshasiddartha:fix/2614-atomic-tool-metadata-cache

Conversation

@harshasiddartha

Copy link
Copy Markdown

Fixes #2614.

What's broken

cacheToolMetadata() clears _cachedToolOutputValidators, _cachedKnownTaskTools and _cachedRequiredTaskTools before it starts compiling the replacement catalog. If a later tool's outputSchema fails to compile, listTools() rejects as expected — but the caches have already been wiped or partially overwritten.

The client is then left in a worse state than before the refresh: callTool() finds no validator for tools that previously had one and silently skips output validation, and tools marked taskSupport: "required" are no longer recognised as such.

Change

Build the replacement Map/Set locally and assign them only after every tool has been processed. A failed refresh now leaves the metadata from the last successful listTools() in effect.

Test

Added a regression test to test/client/index.test.ts under outputSchema validation: it lists a catalog containing a tool with an output schema and a taskSupport: "required" tool, then serves a second catalog whose output schema fails to compile, and asserts both pieces of metadata are still enforced afterwards.

Without the source change it fails with:

AssertionError: promise resolved "{ content: [], …(1) }" instead of rejecting

npm test (1640 tests), npm run typecheck, npm run lint and npm run build all pass.

Scope

This is deliberately limited to the failure-atomicity of the cache write. The separate validator-lookup ordering issue in #2612 (callTool() resolving the validator after awaiting the response) is untouched — the two changes are in different methods and don't conflict.

Targeting v1.x since the reported behaviour is in the v1 client; main no longer has this code path.

mattzcarey and others added 30 commits February 3, 2026 14:59
…port (modelcontextprotocol#1448)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…odelcontextprotocol#1504)

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>
…es (modelcontextprotocol#1478)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…tprotocol#1485)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…otocol#1490)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…otocol#1491)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tprotocol#1210)

Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
…tprotocol#1484)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
…tocol#1487)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
modelcontextprotocol#1522)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ontextprotocol#1524)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…r guide (modelcontextprotocol#1525)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ontextprotocol#1526)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…uth server URL (modelcontextprotocol#1527)

Co-authored-by: hassan123789 <49031989+hassan123789@users.noreply.github.com>
…textprotocol#1532)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…odelcontextprotocol#1546)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…l#1549)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rotocol#1550)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ds (modelcontextprotocol#1556)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mattzcarey and others added 24 commits July 9, 2026 11:04
…ontextprotocol#2369)

Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…tateless (modelcontextprotocol#2557)

Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
@harshasiddartha
harshasiddartha requested a review from a team as a code owner August 6, 2026 08:45
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@2618

commit: a0350ac

@claude claude Bot added the v1 Issues / PRs related to v1.x label Aug 18, 2026
@harshasiddartha
harshasiddartha force-pushed the fix/2614-atomic-tool-metadata-cache branch from a0350ac to 99b7350 Compare September 27, 2026 21:14
@harshasiddartha
harshasiddartha requested a review from a team as a code owner September 27, 2026 21:14
@changeset-bot

changeset-bot Bot commented Sep 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 99b7350

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This branch has not been deployed

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

Labels

v1 Issues / PRs related to v1.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.