Skip to content

perf(mcp): cache MCP tool list per run instead of re-listing before each call#955

Merged
radugheo merged 1 commit into
mainfrom
feat/mcp-refresh-schema-once-per-run
Jun 30, 2026
Merged

perf(mcp): cache MCP tool list per run instead of re-listing before each call#955
radugheo merged 1 commit into
mainfrom
feat/mcp-refresh-schema-once-per-run

Conversation

@radugheo

@radugheo radugheo commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator
  • Cache the MCP tool list on McpClient: fetched once per run instead of before every tool call
  • Cleared on dispose(), so a resumed run uses a fresh client and re-fetches once
  • Cached self-heal now runs against a list refreshed once per run/resume, not on every call
  • force_refresh=True forces a live re-query when needed
  • Dynamic discovery already listed once at startup; unchanged
  • Tests: two list_tools() calls now issue a single RPC; added force-refresh and dispose-clears-cache cases

Copilot AI review requested due to automatic review settings June 30, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves MCP tool invocation performance by memoizing McpClient.list_tools() so tool discovery/schema is fetched once per client lifetime (effectively once per run/resume), instead of re-listing before each tool call. It also updates MCP tool documentation and expands the MCP client test suite to cover caching, forced refresh, and cache clearing on disposal.

Changes:

  • Cache McpClient.list_tools() results with an opt-out force_refresh=True, and clear the cache on dispose().
  • Update MCP tool/schema-refresh documentation to reflect once-per-run tool-list caching behavior.
  • Add/adjust tests to validate caching semantics, force_refresh, and disposal behavior; bump package version to 0.13.14.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/uipath_langchain/agent/tools/mcp/mcp_client.py Adds in-memory tool-list caching and clears it on dispose.
src/uipath_langchain/agent/tools/mcp/mcp_tool.py Updates schema-refresh docs to reflect cached tool discovery.
src/uipath_langchain/agent/tools/mcp/claude.md Documents once-per-run tool-list caching semantics and limitations.
tests/agent/tools/test_mcp/test_mcp_client.py Updates/extends tests for cached list_tools, force refresh, and dispose cache clearing.
tests/agent/tools/test_mcp/claude.md Updates test suite documentation to include new caching tests.
pyproject.toml Bumps package version to 0.13.14.
uv.lock Updates lockfile for the version bump (and changes exclude-newer).

Comment thread src/uipath_langchain/agent/tools/mcp/mcp_client.py Outdated
@radugheo radugheo force-pushed the feat/mcp-refresh-schema-once-per-run branch from 1bc3dd4 to a0122eb Compare June 30, 2026 08:23
…ach call

list_tools() is memoized on McpClient and cleared on dispose(), so the live
tool list/schema is fetched once per run rather than before every tool call.
A resumed run builds a fresh client and re-fetches; force_refresh=True bypasses
the cache. The cached self-heal still evaluates against a list refreshed once
per run (and per resume) instead of on every invocation.
@radugheo radugheo force-pushed the feat/mcp-refresh-schema-once-per-run branch from a0122eb to 9a3fdf8 Compare June 30, 2026 09:53
@sonarqubecloud

Copy link
Copy Markdown

@radugheo radugheo merged commit 05827c2 into main Jun 30, 2026
49 checks passed
@radugheo radugheo deleted the feat/mcp-refresh-schema-once-per-run branch June 30, 2026 12:15
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.

3 participants