perf(mcp): cache MCP tool list per run instead of re-listing before each call#955
Merged
Merged
Conversation
There was a problem hiding this comment.
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-outforce_refresh=True, and clear the cache ondispose(). - 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 to0.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). |
1bc3dd4 to
a0122eb
Compare
…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.
a0122eb to
9a3fdf8
Compare
|
edis-uipath
approved these changes
Jun 30, 2026
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.



McpClient: fetched once per run instead of before every tool calldispose(), so a resumed run uses a fresh client and re-fetches onceforce_refresh=Trueforces a live re-query when neededlist_tools()calls now issue a single RPC; added force-refresh and dispose-clears-cache cases