teeps-heisenberg/MCP-Server-Fast-MCP
If you are the rightful owner of MCP-Server-Fast-MCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This project demonstrates the integration of a FastAPI application with an MCP server and Gemini CLI for natural language interactions.
FastAPI MCP Server Integration with Gemini CLI
This project demonstrates how to create a FastAPI application, wrap it with an MCP (Model Context Protocol) server, and integrate it with Gemini CLI for natural language interactions.
Project Structure
.
├── app.py # FastAPI application with REST endpoints
├── mcp_server.py # MCP server that exposes FastAPI endpoints as tools
├── requirements.txt # Python dependencies
├── gemini-config.json # Gemini CLI configuration file
└── README.md # This file
Features
FastAPI Application (app.py)
- User Management: Create, read, and delete users
- Task Management: Create, read, update (complete), and delete tasks
- Calculations: Perform mathematical operations (add, subtract, multiply, divide)
- Health Check: Monitor application status
MCP Server (mcp_server.py)
Exposes 11 FastAPI endpoints as MCP tools:
get_health- Check API health statusget_users- Retrieve all usersget_user- Get a specific user by IDcreate_user- Create a new userdelete_user- Delete a user by IDget_tasks- Retrieve all tasksget_task- Get a specific task by IDcreate_task- Create a new taskcomplete_task- Mark a task as completeddelete_task- Delete a task by IDcalculate- Perform mathematical calculations
Setup Instructions
1. Install Dependencies
pip install -r requirements.txt
2. Start the FastAPI Application
In one terminal, start the FastAPI server:
python app.py
Or using uvicorn directly:
uvicorn app:app --reload --host 0.0.0.0 --port 8000
The API will be available at http://localhost:8000
3. Install Gemini CLI
Install the Gemini CLI globally using npm:
npm install -g @google/gemini-cli@latest
4. Configure Gemini CLI
Add the MCP server to Gemini CLI configuration. The configuration file is typically located at:
- Windows:
%APPDATA%\Gemini CLI\config.json - macOS/Linux:
~/.config/gemini-cli/config.json
Or use the Gemini CLI command:
gemini mcp add fastapi-mcp-server python mcp_server.py
Alternatively, you can manually add this to your Gemini CLI config file:
{
"mcpServers": {
"fastapi-mcp-server": {
"command": "python",
"args": ["mcp_server.py"],
"env": {
"PYTHONPATH": "."
}
}
}
}
Note: Make sure to provide the full path to mcp_server.py if running from a different directory.
5. Verify Setup
Verify that the MCP server is properly configured:
gemini mcp list
Practical Demonstration with Gemini CLI
Once everything is set up, you can interact with your FastAPI application through Gemini CLI using natural language. Here are some examples:
Example 1: Check API Health
gemini> Check the health of the FastAPI application
Gemini CLI will call the get_health tool and return the API status.
Example 2: Create a User
gemini> Create a new user named John Doe with email john@example.com and age 30
This will invoke the create_user tool with the provided parameters.
Example 3: List All Users
gemini> Show me all users
This uses the get_users tool to retrieve all users from the API.
Example 4: Create a Task
gemini> Create a task titled "Complete MCP integration" with description "Integrate MCP server with Gemini CLI"
The create_task tool will be called to create the task.
Example 5: Perform Calculation
gemini> Calculate 25 multiplied by 4
Or:
gemini> What is 100 divided by 5?
This will use the calculate tool to perform the mathematical operation.
Example 6: Complete a Task
gemini> Mark task with ID 1 as completed
This will call the complete_task tool.
Example 7: Get Task Details
gemini> Show me task number 1
Uses the get_task tool to retrieve task details.
Example 8: Delete a User
gemini> Delete user with ID 1
Invokes the delete_user tool.
Testing the API Directly
You can also test the FastAPI endpoints directly using curl or a REST client:
# Health check
curl http://localhost:8000/health
# Get all users
curl http://localhost:8000/users
# Create a user
curl -X POST http://localhost:8000/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "john@example.com", "age": 30}'
# Create a task
curl -X POST http://localhost:8000/tasks \
-H "Content-Type: application/json" \
-d '{"title": "Test Task", "description": "This is a test task"}'
# Perform calculation
curl -X POST http://localhost:8000/calculate \
-H "Content-Type: application/json" \
-d '{"operation": "multiply", "a": 25, "b": 4}'
API Documentation
Once the FastAPI application is running, you can access interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
Troubleshooting
MCP Server Not Found
If Gemini CLI cannot find the MCP server:
- Ensure you're in the correct directory when starting Gemini CLI
- Check that the path to
mcp_server.pyin the config is correct - Verify Python is in your PATH
Connection Errors
If you get connection errors:
- Ensure the FastAPI application is running on port 8000
- Check that the
API_URLinmcp_server.pymatches your FastAPI server URL - Verify there are no firewall restrictions
Import Errors
If you encounter import errors:
- Make sure all dependencies are installed:
pip install -r requirements.txt - Verify you're using the correct Python environment
- Check that the
mcppackage is installed correctly
Requirements
- Python 3.8 or higher
- Node.js and npm (for Gemini CLI)
- All packages listed in
requirements.txt
License
This is a sample project for educational purposes.