Learn how to use MCPToolbox with Agno to connect to MCP Toolbox for Databases with tool filtering capabilities.
MCPToolbox enables Agents to connect to Google’s MCP Toolbox for Databases with advanced filtering capabilities. It extends Agno’s MCPTools functionality to filter tools by toolset or tool name, allowing agents to load only the specific database tools they need.
Get started with MCPToolbox instantly using our fully functional demo.
Copy
Ask AI
# Clone the repo and navigate to the demo foldergit clone https://github.com/agno-agi/agno.gitcd agno/cookbook/tools/mcp/mcp_toolbox_demo# Start the database and MCP Toolbox servers# With Docker and Docker Composedocker-compose up -d# With Podmanpodman compose up -d# Install dependenciesuv sync# Set your API key and run the basic agentexport OPENAI_API_KEY="your_openai_api_key"uv run agent.py
This starts a PostgreSQL database with sample hotel data and an MCP Toolbox server that exposes database operations as filtered tools.
To verify that your docker/podman setup is working correctly, you can check the database connection:
Copy
Ask AI
# Using Docker Composedocker-compose exec db psql -U toolbox_user -d toolbox_db -c "SELECT COUNT(*) FROM hotels;"# Using Podmanpodman exec db psql -U toolbox_user -d toolbox_db -c "SELECT COUNT(*) FROM hotels;"
Here’s the simplest way to use MCPToolbox (after running the Quick Start setup):
Copy
Ask AI
import asynciofrom agno.agent import Agentfrom agno.models.openai import OpenAIChatfrom agno.tools.mcp_toolbox import MCPToolboxasync def main(): # Connect to the running MCP Toolbox server and filter to hotel tools only async with MCPToolbox( url="http://127.0.0.1:5001", toolsets=["hotel-management"] # Only load hotel search tools ) as toolbox: agent = Agent( model=OpenAIChat(), tools=[toolbox], instructions="You help users find hotels. Always mention hotel ID, name, location, and price tier." ) # Ask the agent to find hotels await agent.aprint_response("Find luxury hotels in Zurich")# Run the exampleasyncio.run(main())
MCPToolbox solves the tool overload problem. Without filtering, your agent gets overwhelmed with too many database tools:Without MCPToolbox (50+ tools):
import asynciofrom textwrap import dedentfrom agno.agent import Agentfrom agno.tools.mcp_toolbox import MCPToolboxurl = "http://127.0.0.1:5001"async def run_agent(message: str = None) -> None: """Run an interactive CLI for the Hotel agent with the given message.""" async with MCPToolbox( url=url, toolsets=["hotel-management", "booking-system"] ) as db_tools: print(db_tools.functions) # Print available tools for debugging agent = Agent( tools=[db_tools], instructions=dedent( """ \ You're a helpful hotel assistant. You handle hotel searching, booking and cancellations. When the user searches for a hotel, mention it's name, id, location and price tier. Always mention hotel ids while performing any searches. This is very important for any operations. For any bookings or cancellations, please provide the appropriate confirmation. Be sure to update checkin or checkout dates if mentioned by the user. Don't ask for confirmations from the user. """ ), markdown=True, show_tool_calls=True, add_history_to_messages=True, debug_mode=True, ) await agent.acli_app(message=message, stream=True)if __name__ == "__main__": asyncio.run(run_agent(message=None))