Logo Gemini CLI

Gemini CLI

Tổ chức
DiversioTeam

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

Nhà phát hànhDiversioTeam
Kho mãgemini-cli-mcp
Ngôn ngữPython
Bản fork
5
Sao
12
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    Gemini CLI cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    12 sao và 5 bản fork từ kho mã được liên kết.

Gemini CLI MCP Server

CI codecov Python 3.10-3.13 License: MIT Ruff

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

Installation

Quick Start (Recommended)

bash
# Install from GitHub (latest)
uvx --from git+https://github.com/DiversioTeam/gemini-cli-mcp gemini-mcp

# Or from PyPI (when published)
uvx gemini-mcp

Development Installation

bash
git clone https://github.com/DiversioTeam/gemini-cli-mcp
cd gemini-cli-mcp
uv sync
uv run gemini-mcp

Prerequisites

1. Python 3.10-3.13

Ensure you have Python 3.10, 3.11, 3.12, or 3.13 installed. The project is tested on all these versions.

2. Gemini CLI Installation and Authentication

This MCP server requires the Gemini CLI to be installed and authenticated:

  1. Install Gemini CLI: Follow the official installation instructions for your platform
  2. Authenticate: Run gemini auth login and follow the prompts
  3. Verify: Test that it works by running gemini -p "Hello, world!"

If you see an authentication error, make sure you've completed the login process.

3. MCP-compatible Client

You'll need an MCP-compatible client such as:

  • Claude Desktop
  • Other MCP-compatible AI assistants

Usage

First Time Setup

Before running the server, verify your setup:

bash
# Check if everything is configured correctly
gemini-mcp setup

This will check:

  • Gemini CLI installation
  • Authentication status
  • Environment configuration

If you see authentication errors, run:

bash
gemini auth login

Running the Server

bash
# Method 1: Run from current directory (for development)
uv run gemini-mcp

# Method 2: Run using uvx from GitHub
uvx --from git+https://github.com/DiversioTeam/gemini-cli-mcp gemini-mcp

# Method 3: Run if installed globally
gemini-mcp

# With debug logging
LOG_LEVEL=DEBUG gemini-mcp

Configuring with Claude Code (CLI)

Method 1: Using the CLI (Recommended)

bash
# Install from GitHub (use -- separator for proper argument parsing)
claude mcp add gemini uvx -- --from git+https://github.com/DiversioTeam/gemini-cli-mcp.git gemini-mcp

# Or install from PyPI when published
claude mcp add gemini uvx -- gemini-mcp

Method 2: Manual Configuration

Add this to ~/.config/claude-code/mcp-settings.json:

json
{
  "servers": {
    "gemini": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/DiversioTeam/gemini-cli-mcp.git", "gemini-mcp"]
    }
  }
}

Configuring with Claude Desktop

Add this to your Claude Desktop configuration:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/claude/claude_desktop_config.json

json
{
  "mcpServers": {
    "gemini": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/DiversioTeam/gemini-cli-mcp.git", "gemini-mcp"],
      "env": {
        "LOG_LEVEL": "INFO"
      }
    }
  }
}

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:

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

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

    bash
    uv run pre-commit install

Local Testing with Claude Code

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

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

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

bash
# 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 .

Troubleshooting

Quick Diagnostics

Run the setup check to diagnose common issues:

bash
gemini-mcp setup

Common Issues

  1. "Gemini CLI not found in PATH"

    • Ensure Gemini CLI is installed: which gemini
    • Add Gemini to your PATH if needed
    • Follow the installation guide for your platform
  2. Authentication errors

    • The server will detect if you're not authenticated
    • Run gemini auth login to authenticate
    • Check if your credentials have expired
    • The error message will guide you on what to do
  3. File access errors

    • Check that files are within allowed directories
    • Use absolute paths or ensure relative paths are correct
    • Set GEMINI_MCP_ALLOWED_DIRS for custom directories
  4. "Command not found" errors

    • Run gemini-mcp setup to check your installation
    • Ensure you've installed the package: uv pip install -e .

Debug Logging

Enable debug logging to see detailed information:

bash
LOG_LEVEL=DEBUG gemini-mcp

Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Ensure all tests pass and code quality checks succeed
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built on top of the Model Context Protocol
  • Integrates with Google's Gemini CLI (unofficial integration)
  • Inspired by the MCP ecosystem and community

Dùng MCP Gemini CLI với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối Gemini CLI, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm Gemini CLI làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của Gemini CLI.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "gemini-cli-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của Gemini CLI, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của Gemini CLI.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng Gemini CLI giúp tôi làm việc này không?
Gemini CLI
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng Gemini CLI.

Câu hỏi thường gặp

Máy chủ MCP Gemini CLI dùng để làm gì?

Gemini CLI là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP Gemini CLI với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng Gemini CLI với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP Gemini CLI với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối Gemini CLI, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP Gemini CLI với TypingMind?

Gemini CLI hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP Gemini CLI cung cấp những công cụ nào trong TypingMind?

Gemini CLI cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP Gemini CLI không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu Gemini CLI yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇