Introduction of Building MCP

Frontend (React)
     ↓
Backend (Spring Boot / Node)
     ↓
MCP Server Layer
     ↓
Microservices (AI, DB, Redis, Storage)

Build MCP Steps (Python FastMCP):

  1. Install MCP SDK

    npm init -y
    npm install @modelcontextprotocol/sdk
    npm install zod
    
  2. Basic MCP server

    import os
    import httpx
    from mcp.server.fastmcp import FastMCP
    from backend.core.drone_registry import registry
    
    mcp = FastMCP(
        name="rescue-drone-mcp",
    	  version: "1.0.0",
        instructions=(
            "You are the MCP interface for a rescue drone fleet operating in an earthquake disaster zone. "
            "Call get_map_info and list_active_drones first. "
            "Use start_search (not move_to + thermal_scan) to begin an autonomous sweep — it returns immediately. "
            "Then loop on wait_for_event: act on survivor_found with delivery_aid, on battery_low with return_to_base, "
            "and exit the loop when all drones have sent search_complete."
        ),
    )
    
  3. Build a tool

    @mcp.tool()
    async def get_battery_status(drone_id: str) -> dict:
        """
        Return the battery percentage for a specific drone.
    
        When battery is below 20%, call request_backup immediately.
        Battery charges gradually at 5%/s — poll this to track charging progress.
        """
        drone = registry.get(drone_id)
        if not drone:
            return {"error": f"Drone '{drone_id}' not found."}
    
        url = f"http://{drone.host}:{drone.port}"
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{url}/drones/{drone_id}/battery", timeout=3.0)
        return resp.json()
    
  4. Start the server

    mcp.run()
    

Types of MCP Tools

1. Read Tools