server.py

Overview

server.py implements an asynchronous MCP (Modular Cloud Platform) server for querying zoo animal data. It provides two primary API tools that enable clients to retrieve animal information either filtered by species or by individual animal name. These tools are exposed using the FastMCP framework, which manages asynchronous HTTP endpoints in a modular and scalable manner.

The file contains a static in-memory dataset of zoo animals, each represented as a dictionary with attributes such as species, name, age, enclosure, and trail. The MCP server runs on a configurable port (default 8080), listens for incoming HTTP requests, and responds asynchronously with the requested animal data.

This setup supports efficient, concurrent access for clients that need to query zoo animal records, without the overhead of external databases.


Classes and Functions

mcp = FastMCP("Zoo Animal MCP Server 🦁🐧🐻")


get_animals_by_species(species: str) -> List[Dict[str, Any]]


get_animal_details(name: str) -> Dict[str, Any]


Main Execution Block

if __name__ == "__main__":
    port = int(os.getenv("PORT", 8080))
    logger.info(f"🚀 MCP server started on port {port}")
    asyncio.run(
        mcp.run_async(
            transport="http",
            host="0.0.0.0",
            port=port,
        )
    )

Data Structures

ZOO_ANIMALS


Important Implementation Details


Interactions with Other System Components


Visual Diagram

classDiagram
class FastMCP {
+tool()
+run_async()
}
class server.py {
-ZOO_ANIMALS: List[Dict]
+get_animals_by_species()
+get_animal_details()
+main()
}
FastMCP <.. server.py : uses
server.py o-- "list" : ZOO_ANIMALS
server.py : +get_animals_by_species()
server.py : +get_animal_details()

This class diagram illustrates the key components of server.py:


References to Related Topics