gemini-cli-mcp

gemini-cli-mcp

MCP server for Google's Gemini CLI with OAuth, enabling use of Gemini through Claude Desktop/Code without API keys – just log in with a Google account.

Category
访问服务器

README

Gemini CLI MCP Server

A Model Context Protocol (MCP) server and CLI wrapper for Google's Gemini CLI with OAuth authentication support. This allows you to use Gemini through Claude Desktop/Code without needing API keys - just login with your Google account.

Features

  • OAuth Authentication: Login with your Google account, no API keys required
  • MCP Server: Full integration with Claude Desktop and Claude Code
  • CLI Tool: Command-line interface for direct usage
  • Multi-Model Support: Use different Gemini models (gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite)
  • File Analysis: Analyze code and documents with context
  • Session Persistence: Maintains authentication across sessions
  • Headless Mode: Support for environments without browser access

Installation

npm install -g @jacob/gemini-cli-mcp

Prerequisites

You need to have Google's Gemini CLI installed:

# Install globally
npm install -g @google/gemini-cli

# Or use npx
npx @google/gemini-cli

The Gemini CLI provides 60 requests/minute and 1,000 requests/day with a personal Google account.

Quick Start

1. Initial Authentication

# The Gemini CLI handles authentication automatically on first use
# Just run any command and it will prompt for auth if needed
gemini-mcp query "Hello"

# Check authentication status
gemini-mcp auth-status

2. CLI Usage

# Send a query
gemini-mcp query "Explain quantum computing in simple terms"

# Query with specific model (defaults to 2.5-pro)
gemini-mcp query "Write a Python function for binary search" --model gemini-2.5-flash

# Analyze files
gemini-mcp analyze --files src/main.ts src/utils.ts --instruction "Find potential bugs"

# Query with context files
gemini-mcp query "Explain this code" --context main.py utils.py

3. MCP Server Configuration

Add to your Claude Desktop or Claude Code configuration:

{
  "mcpServers": {
    "gemini": {
      "command": "npx",
      "args": ["-y", "@jacob/gemini-cli-mcp"],
      "env": {
        "GEMINI_MODEL": "gemini-2.5-pro",
        "GEMINI_TIMEOUT": "30000",
        "GEMINI_AUTO_LOGIN": "true",
        "GEMINI_THINKING_ENABLED": "true"
      }
    }
  }
}

Available MCP Tools

gemini_query

Query Gemini with a prompt and optional context files.

{
  prompt: string;          // Your question or prompt
  model?: string;          // Optional: "gemini-2.5-pro" (default), "gemini-2.5-flash", or "gemini-2.5-flash-lite"
  context?: string[];      // Optional: Array of file paths for context
}

gemini_analyze

Analyze files with specific instructions.

{
  files: string[];         // Files to analyze
  instruction: string;     // Analysis instruction
  model?: string;          // Optional: Model to use
}

gemini_auth_status

Check current authentication status.

gemini_login

Initiate authentication flow.

{
  headless?: boolean;      // Show URL instead of opening browser
  account?: string;        // Specific Google account to use
}

gemini_list_models

List available Gemini models.

CLI Commands

Authentication Commands

# Login
gemini-mcp login [options]
  --headless              # Display URL instead of opening browser
  --account <email>       # Specify Google account

# Logout
gemini-mcp logout

# Check auth status
gemini-mcp auth-status

Query Commands

# Send query
gemini-mcp query <prompt> [options]
  -m, --model <model>     # Model to use
  -c, --context <files>   # Context files
  -t, --timeout <ms>      # Timeout in milliseconds

# Analyze files
gemini-mcp analyze [options]
  -f, --files <files>     # Files to analyze (required)
  -i, --instruction <text> # Analysis instruction (required)
  -m, --model <model>     # Model to use

Configuration

# Set configuration
gemini-mcp config --set key=value

# Get configuration
gemini-mcp config --get key

# List all configuration
gemini-mcp config --list

Configuration options:

  • model: Default model (gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite)
  • timeout: Request timeout in milliseconds
  • headlessDefault: Default to headless authentication
  • autoLogin: Automatically login if not authenticated
  • thinkingEnabled: Enable thinking mode by default (shows model's reasoning)
  • thinkingBudget: Default token budget for thinking process

Environment Variables

  • GEMINI_MODEL: Default model to use (gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite)
  • GEMINI_TIMEOUT: Request timeout (ms)
  • GEMINI_AUTH_CACHE: Authentication cache directory
  • GEMINI_HEADLESS: Default to headless mode
  • GEMINI_AUTO_LOGIN: Auto-login on first use
  • GEMINI_THINKING_ENABLED: Enable thinking mode by default
  • GEMINI_THINKING_BUDGET: Default thinking token budget

Examples

Example 1: Code Review

# Analyze a TypeScript project for issues
gemini-mcp analyze \
  --files "src/**/*.ts" \
  --instruction "Review this code for potential bugs, security issues, and suggest improvements"

Example 2: Documentation Generation

# Generate documentation for a module with thinking mode
gemini-mcp query "Generate comprehensive JSDoc documentation for this module" \
  --context src/auth-manager.ts \
  --model gemini-2.5-flash \
  --thinking-enabled

Example 3: Using in Scripts

#!/bin/bash

# Check if authenticated
if ! gemini-mcp auth-status > /dev/null 2>&1; then
  echo "Please login first: gemini-mcp login"
  exit 1
fi

# Run analysis
gemini-mcp analyze --files "$@" --instruction "Find security vulnerabilities"

Troubleshooting

Authentication Issues

  1. Browser doesn't open: Use --headless flag and manually visit the URL
  2. Session expired: Run gemini-mcp login again
  3. Wrong account: Use --account email@gmail.com to specify account

Connection Issues

  1. Ensure Gemini CLI is installed and in PATH
  2. Check internet connectivity
  3. Verify Google account has access to Gemini

MCP Server Issues

  1. Restart Claude Desktop/Code after configuration changes
  2. Check logs for error messages
  3. Verify the MCP server is running: npx @jacob/gemini-cli-mcp

Security

  • Authentication tokens are stored locally in ~/.gemini-cli-mcp/auth/
  • Tokens are only accessible by your user account
  • Use gemini-mcp logout to clear stored credentials
  • Never share your authentication cache directory

Development

# Clone the repository
git clone https://github.com/yourusername/gemini-cli-mcp.git
cd gemini-cli-mcp

# Install dependencies
npm install

# Build
npm run build

# Run locally
npm start

# Development mode
npm run dev

License

MIT

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.

Support

For issues and feature requests, please use the GitHub issue tracker.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选