Include Exclude Tools

Filter which MCP server tools an agent can use with include_tools and exclude_tools.

Use multiple MCP servers in a single agent, filtering the tools each server exposes.

include_exclude_tools.py
"""
This example demonstrates how to use multiple MCP servers in a single agent,
filtering the tools each server exposes.

Prerequisites:
- Google Maps:
    - Set the environment variable `GOOGLE_MAPS_API_KEY` with your Google Maps API key.
    You can obtain the API key from the Google Cloud Console:
    https://console.cloud.google.com/projectselector2/google/maps-apis/credentials

    - You also need to activate the Address Validation API for your .
    https://console.developers.google.com/apis/api/addressvalidation.googleapis.com
"""

import asyncio

from agno.agent import Agent
from agno.tools.mcp import MCPTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


async def run_agent(message: str) -> None:
    """Run the agent with the given message.

    Remember to set the environment variable `GOOGLE_MAPS_API_KEY` with your Google Maps API key.
    """

    # Initialize one MCPTools instance per server, filtering tools per server
    async with (
        MCPTools(
            command="npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt",
            include_tools=["airbnb_search"],
        ) as airbnb_tools,
        MCPTools(
            command="npx -y @modelcontextprotocol/server-google-maps",
            exclude_tools=["maps_place_details"],
        ) as maps_tools,
    ):
        agent = Agent(
            tools=[airbnb_tools, maps_tools],
            markdown=True,
        )

        await agent.aprint_response(message, stream=True)


# Example usage
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    asyncio.run(
        run_agent(
            "What listings are available in Cape Town for 2 people for 3 nights from 1 to 4 August 2025?"
        )
    )

    asyncio.run(run_agent("What restaurants are open right now in Cape Town?"))

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U "agno[mcp]" openai

Prepare Node.js

The MCP server runs with npx. Install Node.js, then verify the commands:

node --version
npx --version

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Review the source limitation

Filters apply separately to each MCPTools instance: Airbnb exposes only airbnb_search; the Maps instance excludes only maps_place_details.

The Google Maps reference server is archived. To run this historical example, follow its API-enablement instructions and create a Google Maps API key. Export GOOGLE_MAPS_API_KEY in the same shell as the client:

export GOOGLE_MAPS_API_KEY="your_google_maps_api_key"

Add from os import environ to the saved file. Add env={"GOOGLE_MAPS_API_KEY": environ["GOOGLE_MAPS_API_KEY"]} to the Maps MCPTools(...) constructor so the child process receives the key. The Airbnb filter does not remove Maps tools.

Update the sample times

Replace the August 2025 Airbnb dates with future dates and replace right now with an explicit local date and time.

Run the example

Save the code above as include_exclude_tools.py, then run:

python include_exclude_tools.py

Full source: cookbook/91_tools/mcp/include_exclude_tools.py