Hotel Management Typesafe

Typed hotel search with Pydantic input and output schemas over MCPToolbox database tools.

hotel_management_typesafe.py
"""
Hotel Management Typesafe
=============================

Demonstrates hotel management typesafe.
"""

import asyncio
from datetime import date
from textwrap import dedent
from typing import List, Literal

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mcp_toolbox import MCPToolbox
from pydantic import BaseModel, Field

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


url = "http://127.0.0.1:5001"

toolsets = ["hotel-management", "booking-system"]


class Hotel(BaseModel):
    id: int = Field(..., description="Unique identifier for the hotel")
    name: str = Field(..., description="Name of the hotel")
    location: str = Field(..., description="Location of the hotel")
    checkin_date: date = Field(..., description="Check-in date for the hotel stay")
    checkout_date: date = Field(..., description="Check-out date for the hotel stay")
    price_tier: Literal["Luxury", "Economy", "Boutique", "Extended-Stay"] = Field(
        description="The hotel tier/category - must be one of: Luxury, Economy, Boutique, or Extended-Stay"
    )
    booked: str = Field(
        description="Indicates if the hotel is booked (bit field from database)"
    )


class HotelSearch(BaseModel):
    location: str = Field(
        ...,
        description="The city, region, or specific location to search for hotels",
        min_length=1,
        max_length=100,
    )
    tier: Literal["Luxury", "Economy", "Boutique", "Extended-Stay"] = Field(
        description="The hotel tier/category to search for"
    )


class HotelSearchResult(BaseModel):
    hotels: List[Hotel] = Field(
        description="List of hotels matching the search criteria"
    )
    total_results: int = Field(description="Total number of hotels found")


agent = Agent(
    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,
    input_schema=HotelSearch,
    output_schema=HotelSearchResult,
    parser_model=OpenAIChat("gpt-5.2"),
    debug_level=2,
)


async def run_agent(hotel_search: HotelSearch) -> None:
    async with MCPToolbox(url=url, toolsets=toolsets) as tools:
        agent.tools = [tools]
        await agent.aprint_response(hotel_search)


# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    hotel_search = HotelSearch(
        location="Zurich",
        tier="Boutique",
    )

    asyncio.run(run_agent(hotel_search))

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 toolbox-core

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Clone Agno

Clone the pinned Agno source and run the remaining commands from its root:

git clone https://github.com/agno-agi/agno.git
cd agno
git checkout 8f36eaf2d18e91afa7b327eec66a3cd3685dcb87

Start MCP Toolbox

Install and start Docker with Compose support. This local demonstration starts PostgreSQL on host port 5432 and Toolbox on 5001; both ports must be available. Start the services:

cd cookbook/91_tools/mcp/mcp_toolbox_demo
docker compose up -d
cd ../../../..

Run the example

Run the example from the repository root:

python cookbook/91_tools/mcp/mcp_toolbox_demo/hotel_management_typesafe.py

Full source: cookbook/91_tools/mcp/mcp_toolbox_demo/hotel_management_typesafe.py