Skip to content

Conversation

@Gops123
Copy link
Collaborator

@Gops123 Gops123 commented Dec 27, 2025

Summary

Fixes #87

When MCP servers fail to initialize (e.g., unavailable package, network issues, missing dependencies), the agent now gracefully degrades instead of failing entirely.

Problem

Previously, if any MCP server failed to initialize, the agent would fail to load with:

Error: Failed to load agent

Caused by:
    Tool execution error: No MCP servers could be initialized

This was problematic when:

  • An MCP server package doesn't exist or is unavailable
  • Network issues prevent server initialization
  • The user has both builtin tools (Shell) and MCP tools configured

Solution

The agent now:

  1. Logs a warning with detailed error information for each failed MCP server
  2. Continues loading with any successfully initialized tools
  3. Falls back to builtin tools (Shell, HTTP) if configured alongside MCP

Changes

  • crates/aof-runtime/src/executor/runtime.rs:

    • create_mcp_executor_from_config now returns Option<Arc<dyn ToolExecutor>> instead of error
    • Added CombinedToolExecutor to support both builtin and MCP tools
    • Updated load_agent_from_config to handle MCP failures gracefully
    • Added test test_mcp_executor_graceful_failure
  • docs/reference/agent-spec.md:

    • Added "Graceful Degradation" section with example

Testing

Tested with non-existent MCP server - agent loads and responds successfully using Shell tool only.

Log output shows graceful degradation:

WARN: Failed to initialize MCP server 'non-existent-mcp': MCP protocol error
WARN: No MCP servers could be initialized. Agent will continue without MCP tools.
INFO: MCP initialization failed, using builtin tools only: ["shell", "kubectl"]
INFO: Agent loaded successfully: test-graceful

Checklist

  • Code follows project style
  • Tests added for the fix
  • Documentation updated
  • Manually verified the fix

🤖 Generated with Claude Code

When MCP servers fail to initialize (e.g., unavailable package, network issues),
the agent now:
- Logs a warning with detailed error information
- Continues loading with any successfully initialized tools
- Falls back to builtin tools (Shell, HTTP) if configured alongside MCP

This ensures agents remain functional even when some external tools are unavailable.

Changes:
- Updated create_mcp_executor_from_config to return Option instead of error
- Added CombinedToolExecutor to support both builtin and MCP tools
- Updated load_agent_from_config to handle MCP failures gracefully
- Added test for graceful MCP failure handling
- Updated docs with graceful degradation section

Fixes #87

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Agent fails to load when type-based MCP tool cannot be initialized

2 participants