fix(mcp): cache empty tools lists - #4796
Open
CoralGarden52 wants to merge 1 commit into
Open
Conversation
sylvesterkaczmarek
left a comment
Contributor
There was a problem hiding this comment.
I traced this through the cache sentinel and invalidation paths. _tools_list is None is the unpopulated state, while [] is a valid server result, so switching the hit check away from list truthiness fixes the repeated-fetch case without changing the dirty-cache contract: invalidate_tools_cache() still forces the next lookup through the MCP request path. The cached value also remains the raw tool list before filtering, so this does not make a filtered view the new source of truth.
The regression exercises the public context-manager/list_tools() boundary, confirms cached_tools == [], and pins a single underlying request across two lookups. I did not find a blocking issue in this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes MCP tools-list caching when a server returns a valid empty tool list.
With
cache_tools_list=True,MCPServer.list_tools()stores an empty result as[], but the cache-hit check used list truthiness. As a result, every later discovery call fetched the empty list again. The cache-hit check now distinguishes the unpopulatedNonesentinel from a populated empty list.The regression test exercises the public
MCPServerStdiocontext-manager andlist_tools()boundary, verifiescached_tools == [], and confirms that two calls make only one underlying MCP request. Existing invalidation, pagination, filtering, mutation-isolation, and non-empty caching behavior remains covered by the same test module.Validation:
make formatmake lintmake typecheckmake testsAll repository verification commands passed locally.