home / mcp / commands mcp server

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.

Installation
Add the following to your MCP client configuration file.

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.

How to use

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.

How to install

# 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_users

Troubleshooting

If 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.

Development

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.

Notes

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.

Available tools

get_app_info

Retrieve basic information about the MCP-wrapped application.

get_health

Check the health status of the FastAPI application powered MCP server.

get_users

List all users managed by the app.

create_user

Create a new user with name, email, and age.

get_user

Fetch a user by their ID.

get_tasks

List all tasks.

create_task

Create a new task with a title, description, and associated user.

get_task

Fetch a task by its ID.

update_task

Update an existing task's details.

delete_task

Delete a task by its ID.

get_stats

Get overview statistics for users and tasks.