feat: add MCP tools caching to list_mcp_tools - #276
Open
Cosmos-Atom wants to merge 1 commit into
Open
Conversation
Adds optional in-process result caching for list_mcp_tools() to avoid redundant MCP session round-trips in agentic loops where the tool list rarely changes. - New CacheOptions(ttl, max_size) dataclass accepted by list_mcp_tools(cache=...) - Results cached per filter + auth-type combination with monotonic TTL (default 600 s) - cache.evict() for caller-triggered invalidation - LRU eviction when max_size entries exceeded (default 32) - 19 new unit tests covering hit/miss, TTL expiry, LRU eviction, evict() - user-guide.md updated with usage examples and CacheOptions API reference Closes SAP#178
Cosmos-Atom
force-pushed
the
feat/mcp-tools-caching
branch
from
August 19, 2026 08:24
b0bc0b6 to
e1d72c6
Compare
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.
Description
Adds optional in-process result caching for
list_mcp_tools()to avoid redundant MCP session round-trips in agentic loops where the tool list rarely changes.CacheOptions(ttl, max_size)dataclass — pass tolist_mcp_tools(cache=...)cache.evict()for caller-triggered invalidation when tools change on the servermax_sizeentries exceeded (default 32) — prevents unbounded memory growthuser-guide.mdupdated with usage examples andCacheOptionsAPI referenceRelated Issue
Closes #178
Type of Change
How to Test
uv syncuv run pytest tests/agentgateway/unit/test_tools_cache.py -vuv run pytest tests/agentgateway/unit/ -qChecklist
Additional Notes
Cache is in-process only — not shared across client instances, processes, or Kubernetes pods. This matches the existing
_TokenCachedesign. Concurrent cache misses produce redundant fetches but no data corruption (same accepted trade-off documented in_token_cache.py).This PR was implemented with AI assistance (Claude) per the SAP GenAI contribution guidelines.