fix(adk): keep the agent running when an MCP server becomes unreachable - #2845
Open
TigerkidYang wants to merge 1 commit into
Open
TigerkidYang wants to merge 1 commit into
TigerkidYang wants to merge 1 commit into
Conversation
The MCP toolset lists tools lazily on every invocation. When one configured server is down, ListTools fails, the whole tool-collection step fails, and every task of every agent that references that server ends in FAILED before the model is called. The only hint is a single startup-time ERROR log; later turns produce nothing at error level. Wrap the failure in mcpAppToolset.Tools: log it at error level with the server URL on every affected invocation, and return the last successfully listed tools (or none if the server was never reachable) instead of an error. A dead backend then behaves like a set of failing tools: the model still sees them and receives a tool error when it calls one, and the rest of the agent keeps working. A cancelled or expired invocation context is still surfaced as an error. Fixes kagent-dev#2551 Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: MichaelRunchangYang <[email protected]>
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.
Problem
When one configured MCP server is unreachable, every task of every agent that references it ends in
FAILEDbefore the model is called, and nothing at error level explains why after startup. Cause: the ADK MCP toolset lists tools lazily on every invocation, so a failingListToolsfails the whole tool-collection step. Reproduced locally with a 500-returning MCP backend: taskFAILED, zero LLM calls, only the one startup-timefailed to classify MCP toolslog.Follow-up to the discussion on #2551, where the reporter confirmed the remaining scope after 0.10.0: an error-level log for the failure, and keeping the last known tool list so a dead backend degrades like a filtered tool instead of taking the agent down.
Fix
mcpAppToolset.Toolsnow wraps the inner toolset's failure:url,toolsetand the underlying error;ConnectionSafeMcpToolalready handles call-time connection errors;initializeToolSetpasses the server URL through for the log line. No changes to the classification / lazy-fallback path.With this change the same repro completes: the model is called, the task ends
COMPLETED, and the log showsMCP server unreachable and its tools were never listed; continuing without them url=http://….Tests
mcp_ui_degrade_test.go:ERRORlog naming the URL;ERRORlog;go vetandgo test ./adk/pkg/mcp/pass, including the existingTestInitializeToolSetRecoversWhenServerStartsAfterInitialization.Notes
KAgentMcpToolset.get_toolsstill raises when the server cannot be listed; I left it out to keep this PR to the Go runtime the issue was reported on, and can follow up there if wanted.Fixes #2551
Prepared with Claude Code assistance; the diff was reviewed and the tests above were run locally before opening the PR.
🤖 Generated with Claude Code