Skip to content

feat: add MCP tools caching to list_mcp_tools - #276

Open
Cosmos-Atom wants to merge 1 commit into
SAP:mainfrom
Cosmos-Atom:feat/mcp-tools-caching
Open

feat: add MCP tools caching to list_mcp_tools#276
Cosmos-Atom wants to merge 1 commit into
SAP:mainfrom
Cosmos-Atom:feat/mcp-tools-caching

Conversation

@Cosmos-Atom

@Cosmos-Atom Cosmos-Atom commented Aug 19, 2026

Copy link
Copy Markdown

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.

  • New CacheOptions(ttl, max_size) dataclass — pass to list_mcp_tools(cache=...)
  • Results cached per filter + auth-type combination with monotonic TTL (default 600 s)
  • cache.evict() for caller-triggered invalidation when tools change on the server
  • LRU eviction when max_size entries exceeded (default 32) — prevents unbounded memory growth
  • 19 new unit tests covering hit/miss, TTL expiry, LRU eviction, and evict()
  • user-guide.md updated with usage examples and CacheOptions API reference

Related Issue

Closes #178

Type of Change

  • New feature (non-breaking change that adds functionality)

How to Test

  1. Install the package locally: uv sync
  2. Run the new unit tests: uv run pytest tests/agentgateway/unit/test_tools_cache.py -v
  3. Run the full agentgateway test suite: uv run pytest tests/agentgateway/unit/ -q
  4. All 236 tests should pass

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Additional Notes

Cache is in-process only — not shared across client instances, processes, or Kubernetes pods. This matches the existing _TokenCache design. 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.

@Cosmos-Atom
Cosmos-Atom requested a review from a team as a code owner August 19, 2026 08:12
@cla-assistant

cla-assistant Bot commented Aug 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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
Cosmos-Atom force-pushed the feat/mcp-tools-caching branch from b0bc0b6 to e1d72c6 Compare August 19, 2026 08:24
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.

Support MCP tools caching

1 participant