Exposes FastAPI application endpoints as MCP tools, enabling AI agents to interact with REST API functionality including user management, task management, dice rolling, and application health monitoring
Integrates with Google's Gemini AI model to enable natural language interaction with MCP server tools, allowing conversational access to FastAPI endpoints and application functionality
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@FastAPI + MCP + Gemini Integrationcreate a new user named Sarah with email sarah@example.com and age 28"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
FastAPI + MCP + Gemini Integration
This project demonstrates how to integrate a FastAPI application with Google's Gemini AI using a simplified MCP (Model Context Protocol) server implementation.
๐๏ธ Architecture
FastAPI App (
app.py): A sample REST API with user management, task management, and dice rollingSimple MCP Server (
simple_mcp_server.py): Simplified MCP server that exposes FastAPI endpoints as toolsGemini Integration (
simple_gemini_integration.py): Connects Gemini AI with the MCP server
๐ Features
FastAPI Application
User management (CRUD operations)
Task management with completion tracking
Dice rolling functionality
Health checks and statistics
RESTful API endpoints
MCP Server Tools
get_health_status(): Check application healthget_app_info(): Get application informationget_all_users(): Retrieve all userscreate_user(): Create new usersget_user_by_id(): Get specific userget_all_tasks(): Retrieve all taskscreate_task(): Create new taskscomplete_task(): Mark tasks as completedroll_dice(): Roll dice with custom parametersget_app_statistics(): Get application statisticssearch_users_by_name(): Search users by nameget_pending_tasks(): Get incomplete tasksget_completed_tasks(): Get completed tasks
๐ Prerequisites
Python 3.8+
Google Gemini API key (optional - demo works in simulation mode)
Basic Python packages (fastapi, uvicorn, aiohttp, google-generativeai)
๐ ๏ธ Installation
Clone or download the project files
Install dependencies:
pip install fastapi uvicorn aiohttp google-generativeai python-dotenv requestsSet up environment variables (optional): Create a
.envfile and add your Gemini API key:GEMINI_API_KEY=your_actual_api_key_hereNote: The demo works without an API key in simulation mode.
Get a Gemini API key:
Visit Google AI Studio
Create a new API key
Add it to your
.envfile
๐ฏ Usage
0. Look for the video demo
You can look for the zip file in which screen recording is present. That includes a demo question and an answer.
1. Start the FastAPI Server
python app.pyThe FastAPI server will run on http://localhost:8000
2. Test the FastAPI Endpoints
You can test the API directly:
# Health check
curl http://localhost:8000/health
# Get app info
curl http://localhost:8000/
# Create a user
curl -X POST "http://localhost:8000/users?name=John&email=john@example.com&age=30"
# Create a task
curl -X POST "http://localhost:8000/tasks?title=Learn%20FastMCP&description=Study%20FastMCP%20integration"
# Roll dice
curl "http://localhost:8000/dice/roll?sides=6&count=3"3. Run the Gemini Integration
Demo Mode (Predefined Queries)
python simple_gemini_integration.pyInteractive Mode
python simple_gemini_integration.py --interactiveAutomated Demo
python start_simple_demo.py4. Example Gemini Queries
In interactive mode, you can ask questions like:
"Check the health status of the FastAPI application"
"Create a new user named 'Alice' with email 'alice@example.com' and age 25"
"Create a task called 'Learn Python' with description 'Study Python programming'"
"Roll 5 dice with 10 sides each"
"Show me all users and get the application statistics"
"Mark the first task as completed"
"Show me all pending tasks"
๐ง Configuration
FastAPI Server
Default port: 8000
Host: 0.0.0.0 (accessible from all interfaces)
Modify
app.pyto change these settings
MCP Server
Connects to FastAPI server at
http://localhost:8000Modify
API_BASE_URLinmcp_server.pyif needed
Gemini Integration
Uses Gemini 2.0 Flash model
Configure API key via environment variable
Modify model settings in
gemini_integration.py
๐ Project Structure
.
โโโ app.py # FastAPI application
โโโ simple_mcp_server.py # Simplified MCP server with tools
โโโ simple_gemini_integration.py # Gemini + MCP integration
โโโ start_simple_demo.py # Automated startup script
โโโ test_simple_integration.py # Integration testing
โโโ requirements.txt # Python dependencies
โโโ .gitignore # Git ignore file
โโโ README.md # This file๐งช Testing
Test FastAPI Endpoints
# Start the server
python app.py
# In another terminal, test endpoints
curl http://localhost:8000/health
curl http://localhost:8000/users
curl http://localhost:8000/tasksTest MCP Server
python simple_mcp_server.pyTest Gemini Integration
# Make sure FastAPI server is running
python app.py
# In another terminal, run integration
python simple_gemini_integration.pyTest Everything
python test_simple_integration.py๐ Troubleshooting
Common Issues
"Please set GEMINI_API_KEY environment variable"
Make sure you have a
.envfile with your API keyCheck that the API key is valid
"Error connecting to MCP server"
Ensure the FastAPI server is running on port 8000
Check that all dependencies are installed
"ModuleNotFoundError"
Run
pip install -r requirements.txtMake sure you're using Python 3.8+
Debug Mode
To see more detailed error messages, you can modify the integration script to include more logging.
๐ Next Steps
Add more FastAPI endpoints
Create additional MCP tools
Implement authentication
Add database persistence
Create a web interface
Deploy to cloud platforms
๐ Learn More
๐ค Contributing
Feel free to submit issues and enhancement requests!
๐ License
This project is open source and available under the MIT License.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.