MCP_SETUP_GUIDE.mdโข4.9 kB
# ๐ MCP Server Configuration for Gemini CLI
## โ
**SUCCESS! MCP Server is Now Configured**
Your FastAPI MCP server has been successfully installed in Gemini CLI! Here's what was accomplished:
### ๐ฏ **What's Configured:**
1. **FastMCP Library**: Installed version 2.12.4
2. **MCP Server**: `gemini_mcp_server.py` with 13 tools
3. **Gemini CLI Integration**: Server installed as "FastAPI Server"
4. **Dependencies**: All required packages configured
5. **Configuration**: Proper MCP server setup
### ๐ ๏ธ **Available MCP Tools:**
Your FastAPI server now exposes these tools to Gemini CLI:
#### **Health & Info Tools:**
- `get_health_status()` - Check FastAPI server health
- `get_app_info()` - Get application information
- `get_app_statistics()` - Get application statistics
#### **User Management Tools:**
- `get_all_users()` - Retrieve all users
- `create_user(name, email, age)` - Create new user
- `get_user_by_id(user_id)` - Get specific user
- `search_users_by_name(name)` - Search users by name
#### **Task Management Tools:**
- `get_all_tasks()` - Retrieve all tasks
- `create_task(title, description)` - Create new task
- `complete_task(task_id)` - Mark task as completed
- `get_pending_tasks()` - Get incomplete tasks
- `get_completed_tasks()` - Get completed tasks
#### **Utility Tools:**
- `roll_dice(sides, count)` - Roll dice with custom parameters
## ๐ **How to Use in Gemini CLI:**
### **1. Start Your FastAPI Server:**
```bash
python app.py
```
*Keep this running in a separate terminal*
### **2. In Gemini CLI, You Can Now Ask:**
#### **Health & Status:**
- "Check the health status of my FastAPI server"
- "Get information about my FastAPI application"
- "Show me the statistics of my application"
#### **User Management:**
- "Create a new user named John Doe with email john@example.com and age 30"
- "Show me all users in the system"
- "Get user with ID 1"
- "Search for users with name John"
#### **Task Management:**
- "Create a task called 'Learn Python' with description 'Study Python programming'"
- "Show me all tasks"
- "Mark task 1 as completed"
- "Show me all pending tasks"
- "Show me all completed tasks"
#### **Utility Functions:**
- "Roll 3 dice with 6 sides each"
- "Roll 5 dice with 10 sides"
## ๐ง **Technical Details:**
### **MCP Server Configuration:**
- **Server Name**: "FastAPI Server"
- **Server File**: `gemini_mcp_server.py`
- **API Base URL**: `http://localhost:8000`
- **Transport**: stdio
- **Dependencies**: All configured via requirements.txt
### **Files Created:**
- `gemini_mcp_server.py` - FastMCP server implementation
- `fastmcp.json` - FastMCP configuration
- `mcp_config.json` - Gemini CLI configuration
- `setup_gemini_mcp.py` - Setup script
## ๐งช **Testing Your Setup:**
### **1. Test FastAPI Server:**
```bash
python app.py
```
*Should show: "Uvicorn running on http://0.0.0.0:8000"*
### **2. Test MCP Server:**
```bash
python gemini_mcp_server.py
```
*Should start the MCP server (will run indefinitely)*
### **3. Test in Gemini CLI:**
In Gemini CLI, try:
- "Check the health of my FastAPI server"
- "Create a new user named Alice"
## ๐จ **Troubleshooting:**
### **If MCP Tools Don't Appear:**
1. Make sure FastAPI server is running (`python app.py`)
2. Restart Gemini CLI
3. Check if MCP server is properly installed: `fastmcp install gemini-cli --help`
### **If FastAPI Server Won't Start:**
1. Check if port 8000 is available
2. Install dependencies: `pip install -r requirements.txt`
3. Check for Python version compatibility
### **If MCP Server Fails:**
1. Ensure FastMCP is installed: `pip install fastmcp>=2.12.3`
2. Check API_BASE_URL in `gemini_mcp_server.py`
3. Verify FastAPI server is accessible at http://localhost:8000
## ๐ฏ **Next Steps:**
1. **Start FastAPI Server**: `python app.py`
2. **Open Gemini CLI**: Use your configured Gemini CLI
3. **Test Commands**: Try the example queries above
4. **Explore**: Experiment with different combinations of tools
## ๐ **Advanced Usage:**
### **Custom Tool Development:**
You can add more tools to `gemini_mcp_server.py`:
```python
@mcp.tool
async def your_custom_tool(param1: str, param2: int) -> Dict[str, Any]:
"""Your custom tool description"""
# Your implementation here
return {"result": "success"}
```
### **Environment Variables:**
Set custom environment variables:
```bash
fastmcp install gemini-cli gemini_mcp_server.py --env API_BASE_URL=http://your-server.com
```
### **Multiple Servers:**
Install multiple MCP servers:
```bash
fastmcp install gemini-cli server1.py --name "Server 1"
fastmcp install gemini-cli server2.py --name "Server 2"
```
## ๐ **Congratulations!**
Your FastAPI application is now fully integrated with Gemini CLI through MCP! You can interact with your FastAPI server using natural language in Gemini CLI, and all the tools will work seamlessly.
**Happy coding! ๐**