FastAPI MCP Server
Exposes FastAPI REST endpoints as MCP tools, providing user management (create, read, delete), task management (create, read, update, delete), mathematical calculations, and health check monitoring capabilities.
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 Servercreate a task titled 'Prepare project report' with description 'Compile Q3 results and analysis'"
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 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 fileRelated MCP server: FastAPI + FastMCP + Gemini Integration
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.txt2. Start the FastAPI Application
In one terminal, start the FastAPI server:
python app.pyOr using uvicorn directly:
uvicorn app:app --reload --host 0.0.0.0 --port 8000The 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@latest4. Configure Gemini CLI
Add the MCP server to Gemini CLI configuration. The configuration file is typically located at:
Windows:
%APPDATA%\Gemini CLI\config.jsonmacOS/Linux:
~/.config/gemini-cli/config.json
Or use the Gemini CLI command:
gemini mcp add fastapi-mcp-server python mcp_server.pyAlternatively, 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 listPractical 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 applicationGemini 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 30This will invoke the create_user tool with the provided parameters.
Example 3: List All Users
gemini> Show me all usersThis 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 4Or:
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 completedThis will call the complete_task tool.
Example 7: Get Task Details
gemini> Show me task number 1Uses the get_task tool to retrieve task details.
Example 8: Delete a User
gemini> Delete user with ID 1Invokes 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/docsReDoc:
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 correctVerify 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 URLVerify there are no firewall restrictions
Import Errors
If you encounter import errors:
Make sure all dependencies are installed:
pip install -r requirements.txtVerify 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.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityDmaintenanceEnables Gemini AI to interact with a FastAPI application through MCP tools for user management, task management, and dice rolling functionality. Provides natural language access to REST API endpoints including CRUD operations, health checks, and application statistics.
- Flicense-qualityDmaintenanceEnables natural language interaction with FastAPI applications through Google's Gemini AI using MCP tools. Provides CRUD operations for user management and application health monitoring through conversational prompts.
- Flicense-qualityDmaintenanceWraps a FastAPI application as an MCP server, enabling user and task management operations through Gemini CLI tool calling with full CRUD functionality.
- Alicense-qualityDmaintenanceExposes OpenAPI endpoints as MCP tools, enabling LLMs to discover and interact with REST APIs through the MCP protocol.13MIT
Related MCP Connectors
MCP server exposing the Backtest360 engine API as tools for AI agents.
MCP server for Pentest-Tools.com: run scans, manage findings and reports via your preffered LLM.
Point Gecko at an OpenAPI spec; get first-call-correct, auth-hidden agent tools.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/teeps-heisenberg/MCP-Server-Fast-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server