Labsco
DiversioTeam logo

Gemini CLI

โ˜… 11

from DiversioTeam

Integrates with the unofficial Google Gemini CLI, allowing file access within configured directories.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

Gemini CLI MCP Server

A Model Context Protocol (MCP) server that wraps the Gemini CLI, allowing AI assistants like Claude to use Gemini for research and analysis tasks.

Disclaimer: This is an unofficial, community-developed tool that wraps the Google Gemini CLI. It is not affiliated with, endorsed by, or sponsored by Google. All Google and Gemini trademarks, service marks, and logos are the property of Google LLC. This project is licensed under the MIT License.

Important: This tool requires that you have the Gemini CLI installed and authenticated on your system. See the Prerequisites section for details.

Features

  • gemini_prompt: Send prompts to Gemini and get responses
  • gemini_research: Research topics with optional file context
  • gemini_analyze_code: Analyze code files for reviews, explanations, optimizations, security, or testing
  • gemini_summarize: Summarize content from text or files

Available Tools

gemini_prompt

Send a simple prompt to Gemini.

Parameters:

  • prompt (required): The prompt to send
  • model (optional): The Gemini model to use (default: gemini-2.5-pro)
  • context (optional): Additional context to prepend to the prompt

gemini_research

Research a topic with optional file context.

Parameters:

  • topic (required): The research topic or question
  • files (optional): List of file paths to include as context
  • model (optional): The Gemini model to use

gemini_analyze_code

Analyze code files for various purposes.

Parameters:

  • files (required): List of code files to analyze
  • analysis_type (required): Type of analysis - one of:
    • review: Code review for issues and improvements
    • explain: Detailed explanation of the code
    • optimize: Performance and maintainability suggestions
    • security: Security vulnerability analysis
    • test: Test case suggestions
  • specific_question (optional): Additional specific question
  • model (optional): The Gemini model to use

gemini_summarize

Summarize content from text or files.

Parameters:

  • content (optional): Text content to summarize
  • files (optional): Files to summarize (alternative to content)
  • summary_type (optional): Type of summary - one of:
    • brief: 2-3 sentence summary (default)
    • detailed: Comprehensive summary
    • bullet_points: Bullet point format
    • executive: Executive summary for decision makers
  • model (optional): The Gemini model to use

Note: Either content or files must be provided.

Security

This MCP server implements several security measures:

File Access Control

  • Sandboxed file access: By default, file access is restricted to the current working directory
  • Path validation: All file paths are validated to prevent directory traversal attacks
  • Configurable allowed directories: You can specify allowed directories via:
    • Constructor parameter: GeminiMCPServer(allowed_directories=["/path/to/safe/dir"])
    • Environment variable: GEMINI_MCP_ALLOWED_DIRS=/path1:/path2:/path3

Input Sanitization

  • All user inputs are properly sanitized before being passed to the CLI
  • Command injection is prevented by using subprocess with argument lists (never shell=True)
  • File paths are resolved and validated before use

Best Practices

  • Always run the server with minimal required permissions
  • Regularly update both the MCP server and Gemini CLI
  • Monitor logs for any suspicious activity

Development

Setting up the Development Environment

  1. Clone the repository:

    git clone https://github.com/DiversioTeam/gemini-cli-mcp.git
    cd gemini-cli-mcp
  2. Install development dependencies:

    uv sync --all-extras --dev
  3. Install pre-commit hooks:

    uv run pre-commit install

Local Testing with Claude Code

You can add the server for local testing with Claude Code CLI:

# Method 1: Add from local directory (for development)
claude mcp add gemini-local -- uv run gemini-mcp

# Method 2: Add from PyPI (when published)
claude mcp add gemini uvx -- gemini-mcp

# Method 3: Add from GitHub (development version)
claude mcp add gemini uvx -- --from git+https://github.com/DiversioTeam/gemini-cli-mcp.git gemini-mcp

# Then you can test the functionality immediately
# Example: Send prompts, research topics, analyze code, etc.

Running Tests

# Run all tests with coverage
uv run pytest

# Run specific test file
uv run pytest tests/test_tools.py

# Run with verbose output
uv run pytest -v

Code Quality

# Run linting
uv run ruff check .

# Run formatting
uv run ruff format .

# Run type checking
uv run mypy src/

# Run security checks
uv run ruff check --select S .