home / mcp / commands mcp server
Wraps a FastAPI app as an MCP server and enables direct tool calls via Gemini CLI for user, task, and stats management.
Configuration
View docs{
"mcpServers": {
"arrehman3-mcp": {
"command": "python",
"args": [
"mcp_server.py"
]
}
}
}You set up a FastAPI-based MCP Server that wraps your API app and exposes its capabilities as MCP tools. This lets you invoke app functionality directly from Gemini CLI as if you were calling native tools, enabling streamlined automation, testing, and orchestration of users, tasks, and statistics.
To work with this MCP server, you run the local MCP server process and then connect a Gemini CLI client to call the available tools. You can list tools, call them with parameters, and chain calls to manage users and tasks or fetch statistics.
Typical usage patterns include starting the FastAPI app and the MCP server, adding the MCP server to Gemini CLI, and then invoking tools like creating a user, listing users, or getting statistics. Once connected, each tool returns structured results that you can use in automation scripts or interactive sessions.
# 1. Run the setup script (install dependencies and prepare environment)
./setup.sh
# 2. Activate the virtual environment
source venv/bin/activate
# 3. Start the FastAPI application (available at http://localhost:8000)
python sample_app.py# 4. In a separate terminal, start the MCP server that wraps the app
source venv/bin/activate
python mcp_server.py# 5. Install Gemini CLI globally
npm install -g @google/gemini-cli@latest# 6. Register the MCP server with Gemini CLI
gemini mcp add fastapi-sample stdio python $(pwd)/mcp_server.py# 7. Test the integration by listing tools and calling a few endpoints
gemini mcp list
gemini call fastapi-sample get_app_info
gemini call fastapi-sample create_user --name "John Doe" --email "[email protected]" --age 30
gemini call fastapi-sample get_usersIf you run into issues, check common problems such as port conflicts or connectivity between the FastAPI app and the MCP server. Ensure the FastAPI app is running before starting the MCP server, and verify that Gemini CLI is installed and the MCP server was added correctly.
Debug tips include starting the FastAPI app in a non-reload mode to stabilize the process during MCP testing and using the MCP list command to confirm the server is registered.
To extend functionality, add new endpoints to the FastAPI application, then reflect those endpoints in the MCP server so they appear as new tools. Specifically, for each new endpoint you add to the app, create the corresponding tool handler in the MCP serverβs tool listing and implement the call handler to route requests to the endpoint.
You can test endpoints directly with curl against the running FastAPI server, or through Gemini CLI once the new MCP tool is wired up.
The MCP server integrates the API surface with Gemini CLI, enabling direct tool invocation for common operations like creating users, creating tasks, and retrieving statistics. Tools are exposed as distinct commands you can call from scripts or interactive sessions.
Retrieve basic information about the MCP-wrapped application.
Check the health status of the FastAPI application powered MCP server.
List all users managed by the app.
Create a new user with name, email, and age.
Fetch a user by their ID.
List all tasks.
Create a new task with a title, description, and associated user.
Fetch a task by its ID.
Update an existing task's details.
Delete a task by its ID.
Get overview statistics for users and tasks.