Skip to main content

Gemini CLI MCP Server

Project description

gemini-cli-mcp Python Server

This directory contains the Python implementation of the gemini-cli-mcp server. It uses FastAPI to expose gemini-cli functionalities as MCP-compliant tools.

1. Features

This server exposes the following gemini-cli commands as MCP Tools:

  • gemini_ask: Ask a question to the Gemini model.
  • gemini_agent: Run a complex prompt with Gemini Agent in auto-execution (--yolo) mode.
  • gemini_git_commit: Generate a conventional commit message from staged changes and perform a git commit.
  • gemini_git_pr: Automatically commit, push, and create a Pull Request.
  • gemini_git_diff: Summarize code changes using Gemini AI.

2. Technology Stack

Category Technology
Language Python 3.12+
Web Framework FastAPI
Process Exec asyncio.subprocess
CLI Framework Typer (via mcp-cli)
Packaging Poetry / pyproject.toml

3. Setup

Prerequisites

  • Python 3.12 or higher.
  • gemini-cli installed globally and accessible in your system's PATH.
  • git installed and configured.

Installation

  1. Navigate to the server_py directory:
    cd server_py
    
  2. Install dependencies using uv (recommended) or pip:
    uv pip install -r requirements.txt
    # or
    pip install -r requirements.txt
    

Environment Variables

The server uses environment variables for configuration. You can set these in a .env file in the project root (/Users/hackme/workspace/ai/mcp-server/gemini-cli-mcp/.env) or directly in your environment.

  • GEMINI_MODEL: Specifies the Gemini model to use (e.g., gemini-2.5-flash).
  • GEMINI_ALL_FILES: Set to true to include all files in context (--all-files).
  • GEMINI_SANDBOX: Set to true to enable sandbox mode (--sandbox).
  • GEMINI_API_KEY: Your Gemini API key (required for Docker/server environments).
  • PROJECT_ROOT: The root directory of your project (important for gemini-cli operations).
  • QUERY_TIMEOUT: Timeout for gemini-cli commands in seconds.
  • USE_SHELL: Set to true to execute gemini-cli commands via shell (defaults to false).
  • DEBUG: Set to true to enable detailed logging to log/{date}.log.

4. Running the Server

The user can select the execution mode via a CLI flag.

  • STDIO Mode: python main.py (for direct CLI interaction)
  • HTTP Mode: uvicorn main:app --host 0.0.0.0 --port 8000 (for AI agent integration)

Docker

A Dockerfile is provided to build and run the server in a container.

  1. Build the Image: From the project root, run:

    docker build -t gemini-cli-mcp-python -f server_py/Dockerfile .
    
  2. Run the Container:

    # Using an .env file
    docker run --env-file ../.env -p 8000:8000 gemini-cli-mcp-python
    
    # Passing environment variables directly
    docker run -e GEMINI_API_KEY=your_api_key -p 8000:8000 gemini-cli-mcp-python
    

5. Packaging & Distribution

The package will be distributed on PyPI. The pyproject.toml file defines a script entry point for the gemini-cli-mcp command, which will be deployed using poetry build and twine.

CLI Usage

After installing the package via pip, you can use the CLI entry point:

$ gemini-cli-mcp

This will launch the server in STDIO mode. To run in HTTP mode, use:

$ gemini-cli-mcp --http

6. Tool Usage

The server acts as a smart wrapper around gemini-cli. It constructs and executes the appropriate gemini-cli command based on the MCP tool invocation.

For example:

  • gemini_ask(question="What is AI?") translates to gemini ask --model {model} --all-files --sandbox --prompt "What is AI?"
  • gemini_agent(prompt="Do something complex.") translates to gemini agent --model {model} --all-files --sandbox --yolo --prompt "Do something complex."

7. Logging

Set the DEBUG environment variable to true to enable detailed logging to server_py/log/{YYYY-MM-DD}.log.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini_cli_mcp-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_cli_mcp-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file gemini_cli_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: gemini_cli_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for gemini_cli_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc3cd08a6600f8335ddd142f5d2aa0e7bfc8cf112971a7ed6d56a779575c3046
MD5 336cdf8394e4da5054edd49139e6b76b
BLAKE2b-256 fd4ce2540695514c2ee84652b875a38001c168e871edf9c34bc29b817f947ee2

See more details on using hashes here.

File details

Details for the file gemini_cli_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gemini_cli_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for gemini_cli_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55079d2be0ad7ef40b527963c3bf9acb194a450b3d5d0f48b75e280df266d029
MD5 66bebe0b9b656aa2f4e6a43ce18825f1
BLAKE2b-256 07f10a92901b0e79a4daefc5628302cbd3dc35e642bc14afabd6afe11bb7dc47

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page