Skip to main content
Glama

FastAPI MCP Server

by arrehman3
demo.shโ€ข4.55 kB
#!/bin/bash # Demonstration script for FastAPI + MCP Server + Gemini CLI integration echo "๐ŸŽฏ FastAPI + MCP Server + Gemini CLI Integration Demo" echo "==================================================" # Check if we're in the right directory if [ ! -f "sample_app.py" ] || [ ! -f "mcp_server.py" ]; then echo "โŒ Please run this script from the project directory" exit 1 fi # Check if virtual environment exists if [ ! -d "venv" ]; then echo "โŒ Virtual environment not found. Please run ./setup.sh first" exit 1 fi echo "" echo "๐Ÿ“‹ This demo will show you how to:" echo "1. Start the FastAPI application" echo "2. Start the MCP server" echo "3. Install and configure Gemini CLI" echo "4. Call MCP tools from Gemini CLI" echo "" read -p "Press Enter to continue..." echo "" echo "๐Ÿš€ Step 1: Starting FastAPI application..." echo "Command: source venv/bin/activate && python sample_app.py" echo "" echo "The FastAPI app will be available at http://localhost:8000" echo "You can test it with: curl http://localhost:8000/" echo "" read -p "Press Enter to start FastAPI app (it will run in background)..." # Start FastAPI in background source venv/bin/activate python sample_app.py & FASTAPI_PID=$! echo "โœ… FastAPI app started (PID: $FASTAPI_PID)" echo "" # Wait a moment for FastAPI to start sleep 3 echo "๐Ÿงช Testing FastAPI app..." if curl -s http://localhost:8000/ > /dev/null; then echo "โœ… FastAPI app is running successfully!" curl -s http://localhost:8000/ | python -m json.tool else echo "โŒ FastAPI app failed to start" kill $FASTAPI_PID 2>/dev/null exit 1 fi echo "" echo "๐Ÿš€ Step 2: MCP Server" echo "The MCP server wraps the FastAPI app and exposes its endpoints as tools" echo "Available MCP tools:" echo "- get_app_info: Get basic app information" echo "- get_health: Check app health status" echo "- get_users: List all users" echo "- create_user: Create a new user" echo "- get_user: Get user by ID" echo "- get_tasks: List all tasks" echo "- create_task: Create a new task" echo "- get_task: Get task by ID" echo "- update_task: Update an existing task" echo "- delete_task: Delete a task" echo "- get_stats: Get user and task statistics" echo "" read -p "Press Enter to continue..." echo "" echo "๐Ÿš€ Step 3: Installing Gemini CLI" echo "Command: npm install -g @google/gemini-cli@latest" echo "" if command -v gemini &> /dev/null; then echo "โœ… Gemini CLI is already installed" gemini --version else echo "โš ๏ธ Gemini CLI is not installed. Please install it manually:" echo " npm install -g @google/gemini-cli@latest" echo "" echo " You can also install Node.js from https://nodejs.org/ if needed" fi echo "" echo "๐Ÿš€ Step 4: Adding MCP Server to Gemini CLI" echo "Command: gemini mcp add fastapi-sample stdio python $(pwd)/mcp_server.py" echo "" if command -v gemini &> /dev/null; then echo "Adding MCP server to Gemini CLI..." gemini mcp add fastapi-sample stdio python $(pwd)/mcp_server.py echo "" echo "โœ… MCP server added to Gemini CLI!" echo "" echo "๐Ÿš€ Step 5: Testing MCP Tools" echo "" echo "You can now call MCP tools using Gemini CLI:" echo "" echo "# List available MCP servers and tools:" echo "gemini mcp list" echo "" echo "# Get app information:" echo "gemini call fastapi-sample get_app_info" echo "" echo "# Create a user:" echo "gemini call fastapi-sample create_user --name \"John Doe\" --email \"john@example.com\" --age 30" echo "" echo "# Get all users:" echo "gemini call fastapi-sample get_users" echo "" echo "# Create a task:" echo "gemini call fastapi-sample create_task --title \"Learn MCP\" --description \"Study Model Context Protocol\" --user_id 1" echo "" echo "# Get statistics:" echo "gemini call fastapi-sample get_stats" echo "" read -p "Press Enter to test a simple MCP tool call..." echo "" echo "๐Ÿงช Testing MCP tool call..." echo "Command: gemini call fastapi-sample get_app_info" gemini call fastapi-sample get_app_info else echo "โš ๏ธ Gemini CLI not available. Please install it first." fi echo "" echo "๐ŸŽ‰ Demo completed!" echo "" echo "๐Ÿ“ Summary:" echo "- FastAPI app is running at http://localhost:8000" echo "- MCP server is configured and ready" echo "- Gemini CLI integration is set up" echo "" echo "๐Ÿ›‘ To stop the FastAPI app, run: kill $FASTAPI_PID" echo "" echo "๐Ÿ“š For more examples, see the README.md file"

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/arrehman3/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server