Created
February 1, 2026 18:32
-
-
Save kausmeows/6019a4d76557181a827b369c05c3c8d4 to your computer and use it in GitHub Desktop.
MCP tool failure isolation in AgentOS
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
| """ | |
| Example demonstrating MCP tool failure isolation in AgentOS. | |
| This example shows that when an AgentOS app includes multiple agents - some with MCP tools | |
| and some without - a connection failure to an MCP server should NOT cause the entire app | |
| to fail. Only the agent using the failing MCP tool should be affected. | |
| Run this example with: | |
| python cookbook/05_agent_os/mcp_demo/mcp_tools_failure_isolation.py | |
| Then test the endpoints: | |
| 1. GET http://localhost:7777/agents - Should return both agents (even if MCP fails) | |
| 2. POST http://localhost:7777/agents/basic-agent/runs - Should work (no MCP dependency) | |
| 3. POST http://localhost:7777/agents/mcp-agent/runs - May fail if MCP server unavailable | |
| """ | |
| from agno.agent import Agent | |
| from agno.db.sqlite import SqliteDb | |
| from agno.models.openai import OpenAIChat | |
| from agno.os import AgentOS | |
| from agno.tools.mcp import MCPTools | |
| # Setup the database | |
| db = SqliteDb(db_file="tmp/mcp_failure_test.db") | |
| # Agent 1: Basic agent without MCP tools - should always work | |
| basic_agent = Agent( | |
| id="basic-agent", | |
| name="Basic Agent", | |
| description="A simple agent without MCP tools", | |
| model=OpenAIChat(id="gpt-4o-mini"), | |
| db=db, | |
| instructions="You are a helpful assistant.", | |
| markdown=True, | |
| ) | |
| # MCP tools pointing to a non-existent server (simulating failure) | |
| # This will fail to connect during startup | |
| failing_mcp_tools = MCPTools( | |
| transport="streamable-http", | |
| url="http://localhost:9999/nonexistent-mcp-server", # This server doesn't exist | |
| timeout_seconds=5, | |
| ) | |
| # Agent 2: Agent with MCP tools that may fail | |
| mcp_agent = Agent( | |
| id="mcp-agent", | |
| name="MCP Agent", | |
| description="An agent with MCP tools that may fail to connect", | |
| model=OpenAIChat(id="gpt-4o-mini"), | |
| db=db, | |
| tools=[failing_mcp_tools], | |
| instructions="You are an assistant with MCP tools.", | |
| markdown=True, | |
| ) | |
| # Create AgentOS with both agents | |
| # The expectation: If MCP connection fails, basic_agent should still be accessible | |
| agent_os = AgentOS( | |
| name="MCP Failure Isolation Test", | |
| description="Test app demonstrating MCP failure isolation", | |
| agents=[basic_agent, mcp_agent], | |
| ) | |
| app = agent_os.get_app() | |
| if __name__ == "__main__": | |
| """Run the AgentOS. | |
| Expected behavior: | |
| - The app should start even if MCP connection fails | |
| - GET /agents should list both agents | |
| - POST /agents/basic-agent/runs should work normally | |
| - POST /agents/mcp-agent/runs should gracefully handle MCP unavailability | |
| Current behavior (bug): | |
| - If MCP connection fails, the entire app fails to start with 500 error | |
| """ | |
| agent_os.serve(app="test:app", port=7777) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment