A bridge between Claude and Google's Gemini CLI that goes beyond simple API calls. Exposes 33 tools including direct Gemini prompting, OpenRouter integration for 400+ models, and multi-AI collaboration workflows. You can orchestrate debates between Gemini 2.5 and GPT-4, run comparative analyses across different models, or set up verification workflows where one AI checks another's work. Works with both Claude Desktop and Claude Code. The standout feature is structured AI collaboration where multiple models engage in conversations while Claude maintains full context, enabling sophisticated multi-model workflows that would be painful to coordinate manually.
A production-ready Model Context Protocol (MCP) server that bridges Google's Gemini CLI with MCP-compatible clients like Claude Code and Claude Desktop. This enterprise-grade Gemini MCP server features OpenRouter AI API integration for access to 400+ AI models and provides 33 specialized tools for seamless multi-AI workflows between Claude, Gemini, and 400+ additional models.
On Claude Desktop:


Example 1: Claude Code calling one of the 33 MCP tools, gemini_prompt:
@gemini_prompt("Analyse @mcp_server.py codebase and modules explaining what this code does, think deeply before responding")

Example 2: Claude Code Custom Slash Command Prompt + Claude & Gemini CLI MCP Server Teamwork
Setup Claude Code custom slash command prompt /test-gemini-prompt-analyse-teamwork within Git repo project at .claude/commands/test-mcp/test-gemini-prompt-analyse-teamwork.md. When you invoke this command, Claude Code Sonnet 4 first performs a deep analysis of the Gemini CLI MCP server code. It then delegates the same codebase to Google Gemini 2.5 Flash via the MCP tool’s @gemini_prompt() (note that Flash may be rate-limited on free tiers). Finally, Claude Code Sonnet 4 synthesizes both sets of insights into a single, consolidated report.
Click View Screenshots to see example.




Example 3: Claude Code Custom Slash Command Prompt + Claude & Gemini CLI MCP Server Comphrensive Review
Setup Claude Code custom slash command prompt .claude/commands/workflow-orchestrators/comprehensive-review.md within Git repo project at .claude/commands/workflow-orchestrators/comprehensive-review.md. When you invoke this command, Claude Code Sonnet 4 first performs a comphrensive review of the Gemini CLI MCP server code and writes a report. It then asks Google Gemini 2.5 Flash via the MCP tool’s @gemini_prompt() (note that Flash may be rate-limited on free tiers) to verify and evaluate the generated report and add it's findings to the report.
Click View Screenshots to see example.




Example 4: Extended: Claude Code Custom Slash Command Prompt + Claude & Gemini CLI MCP Server Comphrensive Review + Claude Response To Gemini Analysis.
Setup Claude Code custom slash command prompt .claude/commands/workflow-orchestrators/comprehensive-review.md within Git repo project at .claude/commands/workflow-orchestrators/comprehensive-review.md. When you invoke this command, Claude Code Sonnet 4 first performs a comphrensive review of the Gemini CLI MCP server code and writes a report. It then asks Google Gemini 2.5 Flash via the MCP tool’s @gemini_prompt() (note that Flash may be rate-limited on free tiers) to verify and evaluate the generated report and add it's findings to the report. Then finally ask Claude to respond to Gemini CLI MCP server's analysis.
Click View Screenshots to see example.




Example 5: Claude Code with Gemini CLI MCP Server With OpenRouter API support
Extended Gemini CLI MCP server with Openrouter API support to access 400+ LLM models. Click View Screenshots to see example of Claude Code chatting with Openai GP4 4.1-nano, Mistral AI devstral-small and DeepSeek R1 0528.


Example 6: Claude Code with Gemini CLI MCP Server AI Collaboration
The Gemini CLI MCP server includes OpenRouter API support for accessing 400+ LLM models. The @gemini_ai_collaboration MCP tool enables multiple AI models to engage in structured conversations, collaborations, or debates. This allows Gemini 2.5 models (via Gemini CLI) to collaborate with OpenRouter-based models like OpenAI GPT-4, Anthropic Claude, and others.
In the example below, Gemini 2.5 Flash debates with OpenAI GPT-4.1-mini through Claude Code. Claude Code (Sonnet 4) orchestrates the debate and has full access to the conversation context, enabling sophisticated multi-AI workflows.
@gemini_ai_collaboration(
collaboration_mode="debate",
content="Should we use microservices or monolith?",
models="gemini-2.5-flash,openai/gpt-4.1-mini",
rounds=4,
debate_style="constructive"
)

Using Gemini CLI MCP in Claude Desktop with same MCP tool:


Or validation mode with Gemini 2.5 Flash, OpenAI GPT-4.1-mini and Anthropic Claude 3 Haiku.
@gemini_ai_collaboration(
collaboration_mode="validation",
content="@mcp_server.py", # or multiple files
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/cla
ude-3-haiku",
validation_criteria="code_quality,performance,security,mai
ntainability,best_practices,documentation",
confidence_threshold=0.8,
consensus_method="weighted_majority",
conflict_resolution="detailed_analysis",
context="Code review for production deployment",
budget_limit=5.00
)

Example 7: Claude Code natural language prompt calling Gemini CLI MCP server's Openrouter LLM model, OpenAI GPT 4.1-nano.
Claude Code natural language prompt calling Gemini CLI MCP server's Openrouter LLM model, OpenAI GPT 4.1-nano.
Click View Screenshots to see example.
Seems there is a bug in that it says it gets 4o-mini but I wanted/do get 4.1-nano model as asked.


OpenRouter Usage Activity for OpenAI GPT 4.1-nano

Gemini CLI MCP server uses Cloudflare AI Gateway proxies for Gemini CLI itself and also for OpenRouter integration. But AI Gateway records it as 4.1-mini and not 4.1-nano.


The Gemini CLI MCP Server features a modular, enterprise-grade architecture designed for reliability, performance, and maintainability. Built on proven architectural patterns and production-ready design decisions.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Claude Code │ ← → │ MCP Protocol │ ← → │ Gemini CLI │
│ MCP Client │ │ (JSON-RPC 2.0) │ │ Integration │
└─────────────────┘ └──────────────────┘ └─────────────────┘
↑ ↑ ↑
┌─────────┐ ┌─────────────┐ ┌─────────────┐
│ 33 MCP │ │ FastMCP │ │ Google │
│ Tools │ │ Server │ │ Gemini AI │
└─────────┘ └─────────────┘ └─────────────┘
🔧 Refactored Modular Architecture (83 Python files across multiple specialized modules):
Core Server Layer (6 modules):
mcp_server.py - Streamlined main coordinator with tool registration pattern (741 lines, 83.5% reduction from 4,502 lines)modules/core/mcp_core_tools.py - Pure MCP tool implementations for core Gemini CLI tools (487 lines)modules/core/mcp_collaboration_engine.py - AI collaboration system with advanced workflow modes (1,103 lines)modules/core/mcp_service_implementations.py - System and service tools coordination layer (1,228 lines)modules/core/mcp_code_review_tools.py - Specialized code review and analysis tools (386 lines)modules/core/mcp_content_comparison_tools.py - Multi-source content comparison capabilities (299 lines)Configuration & Infrastructure (7 modules):
modules/config/gemini_config.py - Main configuration interface with modular imports (1,835 lines)modules/config/environment_config.py - Environment variable parsing and validation (NEW)modules/config/model_config.py - Gemini model definitions and scaling configuration (NEW)modules/config/feature_config.py - Feature flags, OpenRouter, monitoring, and conversations (NEW)modules/utils/gemini_utils.py - Core utilities and helper functions (3,996 lines)modules/services/conversation_manager.py - Stateful conversation management with Redis support (1,048 lines)modules/services/monitoring.py - OpenTelemetry, Prometheus, and health check integration (1,534 lines)Integration Modules (2 modules):
modules/services/openrouter_client.py - OpenRouter API client for 400+ AI models (881 lines)modules/services/redis_cache.py - Redis caching with graceful memory fallback (914 lines)Template System (17 modules):
prompts/ - Template module with TTL caching and integrity verificationSecurity Framework (6 modules):
security/ - Enterprise security framework with 22 critical security fixesRate Limiting & Utility Scripts (5 modules):
📝 Template System Architecture:
prompts/
├── __init__.py # Module exports and imports
├── template_loader.py # Template loading with 30-min TTL caching
├── base_template.py # Common components and utilities
├── summarize_template.py # Content summarization templates
├── review_template.py # Code review templates
├── eval_template.py # Plan evaluation templates
└── verify_template.py # Solution verification templates
Key Template Features:
⚡ Enterprise Features:
🛡️ Security & Reliability:
🏛️ Design Philosophy:
The server provides 33 specialized MCP tools organized into six categories:
gemini_cliExecute any Gemini CLI command directly with comprehensive error handling.
gemini_cli(command="--prompt 'Hello world'")
gemini_cli(command="--model gemini-2.5-pro --prompt 'Explain AI'")
gemini_helpGet cached Gemini CLI help information (30-minute TTL).
gemini_help()
gemini_versionGet cached Gemini CLI version information (30-minute TTL).
gemini_version()
gemini_promptSend prompts with structured parameters and validation (100,000 char limit).
gemini_prompt(
prompt="Explain quantum computing",
model="gemini-2.5-flash",
sandbox=False,
debug=False
)
gemini_modelsList all available Gemini AI models.
gemini_models()
gemini_metricsGet comprehensive server performance metrics and statistics.
gemini_metrics()
gemini_sandboxExecute prompts in sandbox mode for code execution (200,000 char limit).
gemini_sandbox(
prompt="Write and run a Python script to analyze data",
model="gemini-2.5-pro",
sandbox_image="python:3.11-slim" # optional
)
gemini_cache_statsGet cache statistics for all cache backends.
gemini_cache_stats()
gemini_rate_limiting_statsGet comprehensive rate limiting and quota statistics.
gemini_rate_limiting_stats()
gemini_summarizeSummarize content with focus-specific analysis (400,000 char limit).
gemini_summarize(
content="Your code or text content here",
focus="architecture and design patterns",
model="gemini-2.5-pro"
)
gemini_summarize_filesFile-based summarization optimized for @filename syntax (800,000 char limit).
Key Advantages over gemini_summarize:
gemini_summarize_files(
files="@src/ @docs/ @tests/", # @filename syntax
focus="complete system analysis", # optional
model="gemini-2.5-pro" # optional
)
gemini_eval_planEvaluate Claude Code implementation plans (500,000 char limit).
gemini_eval_plan(
plan="Implementation plan from Claude Code",
context="Node.js REST API with MongoDB",
requirements="Must support 10,000 concurrent users",
model="gemini-2.5-pro"
)
gemini_review_codeReview specific code suggestions with detailed analysis (300,000 char limit).
gemini_review_code(
code="Code snippet or @filename to review",
purpose="Security review of authentication",
context="Express.js REST API",
language="javascript",
model="gemini-2.5-pro"
)
gemini_verify_solutionComprehensive verification of complete solutions (800,000 char limit).
gemini_verify_solution(
solution="Complete implementation including code, tests, docs",
requirements="Original requirements specification",
test_criteria="Performance and security criteria",
context="Production deployment environment",
model="gemini-2.5-pro"
)
gemini_start_conversationStart a new conversation with ID for stateful interactions.
gemini_start_conversation(
title="Python Development Help",
description="Ongoing assistance with Python project",
tags="python,development",
expiration_hours=24
)
gemini_continue_conversationContinue an existing conversation with context history.
gemini_continue_conversation(
conversation_id="conv_12345",
prompt="How do I optimize this function?",
model="gemini-2.5-flash"
)
gemini_list_conversationsList active conversations with metadata.
gemini_list_conversations(
limit=20,
status_filter="active"
)
gemini_clear_conversationClear/delete a specific conversation.
gemini_clear_conversation(conversation_id="conv_12345")
gemini_conversation_statsGet conversation system statistics and health.
gemini_conversation_stats()
gemini_code_reviewComprehensive code analysis with structured output (NEW).
gemini_code_review(
code="Your code to review",
language="python", # optional, auto-detected
focus_areas="security,performance,quality,best_practices", # optional
severity_threshold="info", # optional: info, warning, error, critical
output_format="structured" # optional: structured, markdown, json
)
gemini_extract_structuredExtract structured data using JSON schemas (NEW).
# Define a schema for code analysis
schema = {
"type": "object",
"properties": {
"functions": {"type": "array"},
"classes": {"type": "array"},
"issues": {"type": "array"}
}
}
gemini_extract_structured(
content="Code or text to analyze",
schema=json.dumps(schema),
examples="Optional examples of expected output", # optional
strict_mode=True, # optional
model="gemini-2.5-flash" # optional
)
gemini_git_diff_reviewAnalyze git diffs with contextual feedback (NEW).
gemini_git_diff_review(
diff="Git diff content or patch",
context_lines=3, # optional
review_type="comprehensive", # optional: comprehensive, security_only, performance_only, quick
base_branch="main", # optional
commit_message="Fix authentication bug" # optional
)
gemini_content_comparisonAdvanced multi-source content comparison and analysis (NEW).
# Compare documentation versions
gemini_content_comparison(
sources='["@README.md", "@docs/README.md", "https://github.com/user/repo/README.md"]',
comparison_type="semantic", # semantic, textual, structural, factual, code
output_format="structured", # structured, matrix, summary, detailed, json
include_metrics=True, # optional, include similarity scores
focus_areas="completeness,accuracy,structure" # optional, what to focus on
)
# Code version analysis
gemini_content_comparison(
sources='["@src/auth_v1.py", "@src/auth_v2.py"]',
comparison_type="code",
output_format="detailed",
focus_areas="differences,security,performance"
)
gemini_ai_collaborationEnhanced multi-platform AI collaboration with cross-platform capabilities.
# Sequential analysis pipeline
gemini_ai_collaboration(
collaboration_mode="sequential",
content="Your task or code to analyze",
models="gemini-2.5-flash,openai/gpt-4.1-nano,anthropic/claude-3-haiku",
pipeline_stages="analysis,security_review,optimization,final_validation"
)
# Multi-round AI debate
gemini_ai_collaboration(
collaboration_mode="debate",
content="Should we use microservices or monolith?",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku",
rounds=4,
debate_style="constructive"
)
gemini_ai_collaborationAvailable Collaboration Modes:
sequential - Progressive refinement through ordered analysis pipelinedebate - Multi-round discussions with consensus buildingvalidation - Cross-platform validation with conflict resolutionAvailable Debate Styles (for debate mode):
constructive (default) - Focus on building understanding rather than winning argumentsadversarial - Challenge assumptions and arguments rigorouslycollaborative - Work together to explore topics comprehensivelysocratic - Use questioning to explore underlying assumptionsdevil_advocate - Deliberately argue for challenging positionsUniversal Parameters:
collaboration_mode (required): sequential | debate | validationcontent (required): Content to be analyzed/processedmodels (optional): Comma-separated list of AI models (auto-selected if not provided)context (optional): Additional context for collaborationconversation_id (optional): For stateful conversation historybudget_limit (optional): USD cost limit for OpenRouter modelsSequential Mode Parameters:
pipeline_stages (optional): Comma-separated stages (auto-generated if not provided)handoff_criteria (optional): completion_of_stage | quality_threshold | consensus_reached | time_basedquality_gates (optional): none | basic | standard | strict | comprehensivefocus (optional): Focus area (default: "progressive refinement")Debate Mode Parameters:
rounds (optional): Number of debate rounds (1-10, default: 3)debate_style (optional): See debate styles above (default: "constructive")convergence_criteria (optional): substantial_agreement | consensus | majority_view | all_viewpointsfocus (optional): Focus area (default: "comprehensive analysis")Validation Mode Parameters:
validation_criteria (optional): Comma-separated criteria (auto-generated if not provided)confidence_threshold (optional): 0.0-1.0 (default: 0.7)consensus_method (optional): simple_majority | weighted_majority | unanimous | supermajority | expert_panelconflict_resolution (optional): ignore | flag_only | detailed_analysis | additional_validation | expert_arbitrationDifferent Debate Styles:
# Adversarial debate for critical analysis
gemini_ai_collaboration(
collaboration_mode="debate",
content="Should our startup use microservices architecture?",
models="gemini-2.5-flash,openai/gpt-4.1-mini",
rounds=3,
debate_style="adversarial",
convergence_criteria="majority_view"
)
# Socratic questioning for deep exploration
gemini_ai_collaboration(
collaboration_mode="debate",
content="What makes code maintainable?",
models="gemini-2.5-flash,anthropic/claude-3-haiku",
rounds=4,
debate_style="socratic",
focus="fundamental principles"
)
# Devil's advocate for stress testing ideas
gemini_ai_collaboration(
collaboration_mode="debate",
content="Our new feature implementation plan",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku",
rounds=2,
debate_style="devil_advocate",
focus="identifying potential failures"
)
Sequential Pipeline Examples:
# Quality-gated sequential analysis
gemini_ai_collaboration(
collaboration_mode="sequential",
content="@src/authentication.py",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku",
pipeline_stages="code_review,security_analysis,performance_optimization,documentation",
quality_gates="strict",
handoff_criteria="quality_threshold"
)
# Time-based handoffs for rapid iteration
gemini_ai_collaboration(
collaboration_mode="sequential",
content="Product requirements analysis",
models="gemini-2.5-flash,openai/gpt-4.1-nano",
pipeline_stages="initial_analysis,stakeholder_review,final_recommendations",
handoff_criteria="time_based",
focus="user experience"
)
Validation Examples:
# High-confidence consensus validation
gemini_ai_collaboration(
collaboration_mode="validation",
content="Critical system design decisions",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku",
validation_criteria="scalability,security,maintainability,cost_efficiency",
confidence_threshold=0.9,
consensus_method="unanimous",
conflict_resolution="expert_arbitration"
)
# Supermajority validation with detailed conflict analysis
gemini_ai_collaboration(
collaboration_mode="validation",
content="API design specification",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku",
validation_criteria="usability,performance,consistency,documentation",
consensus_method="supermajority",
conflict_resolution="detailed_analysis"
)
Auto-Selection Behavior:
When models parameter is not provided, the function automatically selects appropriate models:
"gemini-2.5-flash,openai/gpt-4.1-nano,anthropic/claude-3-haiku""gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku""gemini-2.5-flash,openai/gpt-4.1-nano,anthropic/claude-3-haiku"gemini_test_openrouterTest OpenRouter connectivity and client functionality.
gemini_test_openrouter()
gemini_openrouter_opinionGet responses from any of 400+ AI models via OpenRouter with @filename support.
gemini_openrouter_opinion(
prompt="Analyze @config.yaml for security issues",
model="anthropic/claude-3-haiku",
temperature=0.7,
max_tokens=2000,
file_handling_strategy="auto"
)
gemini_openrouter_modelsList all available OpenRouter models (400+) with advanced filtering and output options.
gemini_openrouter_models(
category="programming",
provider_filter="openai",
sort_by="usage",
include_pricing=True
)
gemini_cross_model_comparisonCompare responses across Gemini CLI and OpenRouter models with @filename support.
gemini_cross_model_comparison(
prompt="Design a REST API for user authentication",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku"
)
gemini_openrouter_usage_statsGet OpenRouter usage statistics and costs for the current session.
gemini_openrouter_usage_stats()
gemini_cross_model_comparisonCompare responses across Gemini CLI and OpenRouter models with @filename support.
gemini_cross_model_comparison(
prompt="Design a REST API for user authentication",
models="gemini-2.5-flash,openai/gpt-4.1-mini,anthropic/claude-3-haiku"
)
# Install uv (recommended package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone https://github.com/centminmod/gemini-cli-mcp-server.git
cd gemini-cli-mcp-server
# Create and activate virtual environment
uv venv
source .venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
# Install and configure Gemini CLI
npm install -g @google-ai/gemini-cli
gemini config set api_key YOUR_GEMINI_API_KEY
# Verify installation
gemini --version
python mcp_server.py --help
# Install uv via Homebrew (or use curl installer above)
brew install uv
# Clone the repository
git clone https://github.com/centminmod/gemini-cli-mcp-server.git
cd gemini-cli-mcp-server
# Create and activate virtual environment
uv venv
source .venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
# Install Gemini CLI (if not already installed)
npm install -g @google-ai/gemini-cli
# Or via Homebrew: brew install gemini-cli
# Configure Gemini CLI
gemini config set api_key YOUR_GEMINI_API_KEY
# Verify installation
gemini --version
python mcp_server.py --help
# Using standard Python tools
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
# Configure Gemini CLI
gemini config set api_key YOUR_GEMINI_API_KEY
Add the server using the Claude Code MCP command for user scope:
claude mcp add gemini-cli /absolute/path/to/.venv/bin/python /absolute/path/to/mcp_server.py -s user -e GEMINI_API_KEY='YOUR_GEMINI_API_KEY'
Use the -s or --scope flag to specify where the configuration is stored:
local (default): Available only to you in the current project (was called project in older versions)project: Shared with everyone in the project via .mcp.json fileuser: Available to you across all projects (was called global in older versions)Add the following to your Claude Desktop settings file:
Location:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/claude/claude_desktop_config.jsonConfiguration:
{
"mcpServers": {
"gemini-cli": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["/absolute/path/to/mcp_server.py"]
}
}
}
Important: Use absolute paths for both the Python executable and the mcp_server.py script.
For other MCP-compatible clients, use the stdio transport with:
mcp_server.pySimple Q&A:
# Quick question with fast model
gemini_prompt(
prompt="What is machine learning?",
model="gemini-2.5-flash"
)
# Complex analysis with advanced model
gemini_prompt(
prompt="Analyze the trade-offs between REST and GraphQL APIs",
model="gemini-2.5-pro"
)
File Analysis:
# Review code file directly
gemini_review_code(
code="@src/auth.py",
purpose="Security vulnerability assessment",
language="python"
)
# Summarize multiple files (standard approach)
gemini_summarize(
content="@src/ @tests/ @docs/",
focus="architecture and design patterns"
)
# Large-scale file analysis (optimized approach)
gemini_summarize_files(
files="@src/ @lib/ @components/ @tests/ @docs/",
focus="complete system architecture and dependencies"
)
Code Execution:
# Interactive development
gemini_sandbox(
prompt="Create a data visualization of sales trends",
model="gemini-2.5-pro"
)
# Custom environment
gemini_sandbox(
prompt="Test this Node.js API endpoint",
sandbox_image="node:18-alpine"
)
The dual-AI workflow enables powerful collaboration between Claude Code and Gemini AI:
# Claude Code generates an implementation plan
plan = """
1. Create JWT authentication middleware
2. Implement rate limiting with Redis
3. Add input validation with Joi
4. Set up comprehensive error handling
5. Create user registration/login endpoints
"""
# Gemini AI evaluates the plan
gemini_eval_plan(
plan=plan,
context="Express.js REST API for e-commerce platform",
requirements="Must support 50,000 concurrent users, GDPR compliant",
model="gemini-2.5-pro"
)
# Claude Code suggests implementation
code = """
const jwt = require('jsonwebtoken');
const authMiddleware = (req, res, next) => {
const token = req.header('Authorization')?.replace('Bearer ', '');
if (!token) {
return res.status(401).json({ error: 'Access denied' });
}
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
next();
} catch (error) {
res.status(401).json({ error: 'Invalid token' });
}
};
"""
# Gemini AI reviews the code
gemini_review_code(
code=code,
purpose="JWT authentication middleware for Express.js",
context="E-commerce API with high security requirements",
language="javascript",
model="gemini-2.5-pro"
)
# Complete implementation ready for deployment
solution = """
[Complete implementation including:]
- Authentication system with JWT and refresh tokens
- Rate limiting middleware with Redis
- Input validation with comprehensive schemas
- Error handling with structured responses
- User management endpoints
- Security headers and CORS configuration
- Comprehensive test suite
- API documentation
- Deployment configuration
"""
# Final verification before deployment
gemini_verify_solution(
solution=solution,
requirements="Secure authentication system with rate limiting",
test_criteria="Handle 50k concurrent users, 99.9% uptime, sub-200ms response",
context="Production deployment on AWS ECS with Redis ElastiCache",
model="gemini-2.5-pro"
)
Large Codebase Analysis:
# Enterprise-scale project analysis (recommended)
gemini_summarize_files(
files="@src/ @lib/ @components/ @utils/ @tests/ @docs/",
focus="architectural patterns and dependencies",
model="gemini-2.5-pro"
)
# Alternative for smaller projects
gemini_summarize(
content="@src/ @lib/ @components/ @utils/ @tests/",
focus="architectural patterns and dependencies",
model="gemini-2.5-pro"
)
Performance Analysis:
# Review code for performance issues
gemini_review_code(
code="@src/api/handlers/ @src/database/",
purpose="Performance optimization and bottleneck identification",
context="High-traffic API serving 1M requests/day",
model="gemini-2.5-pro"
)
Security Assessment:
# Comprehensive security review
gemini_review_code(
code="@auth/ @middleware/ @validators/",
purpose="Security vulnerability assessment",
context="Financial services application with PCI compliance requirements",
model="gemini-2.5-pro"
)
Structured Code Analysis:
# Comprehensive code review with structured output
gemini_code_review(
code="@src/api/handlers/",
language="python",
focus_areas="security,performance,maintainability",
severity_threshold="warning",
output_format="structured"
)
Schema-Based Data Extraction:
# Extract API endpoints from codebase
schema = {
"type": "object",
"properties": {
"endpoints": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {"type": "string"},
"method": {"type": "string"},
"authentication": {"type": "boolean"}
}
}
}
}
}
gemini_extract_structured(
content="@src/routes/",
schema=json.dumps(schema),
strict_mode=True
)
Git Diff Analysis:
# Review pull request changes
gemini_git_diff_review(
diff="@pull_request.diff",
review_type="comprehensive",
base_branch="main",
commit_message="Add user authentication feature"
)
Multi-Source Content Comparison:
# Compare API documentation versions
gemini_content_comparison(
sources='["@docs/api_v1.md", "@docs/api_v2.md", "https://api.example.com/docs"]',
comparison_type="semantic",
output_format="matrix",
focus_areas="breaking_changes,new_features,deprecations"
)
Each tool has optimized character limits based on typical use cases:
| Tool | Limit | Use Case |
|---|---|---|
gemini_prompt | 100K chars | General purpose interactions |
gemini_sandbox | 200K chars | Code execution & development |
gemini_eval_plan | 500K chars | Architecture evaluation |
gemini_review_code | 300K chars | Code review & analysis |
gemini_verify_solution | 800K chars | Complete solution verification |
gemini_summarize | 400K chars | Large content summarization |
gemini_summarize_files | 800K chars | File-based analysis with @filename syntax |
gemini_ai_collaboration | 500K chars | Multi-AI workflow collaboration |
gemini_openrouter_opinion | 150K chars | OpenRouter model interactions |
gemini_code_review | 300K chars | Structured code analysis (NEW) |
gemini_extract_structured | 200K chars | Schema-based data extraction (NEW) |
gemini_git_diff_review | 150K chars | Git diff analysis (NEW) |
gemini_content_comparison | 400K chars | Multi-source content comparison (NEW) |
| Conversation Tools | Variable | Context-aware with token management |
Limits automatically scale based on the selected model's capabilities:
When quota limits are exceeded, the server automatically falls back from premium to standard models:
gemini-2.5-pro (quota exceeded) → gemini-2.5-flash (automatic retry)
This ensures continuous operation during high-usage periods without user intervention.
Access to 400+ AI models from 20+ providers including OpenAI, Anthropic, Meta, Google, and more:
Key Benefits:
Popular Models Available:
Stateful multi-turn conversations with persistent context:
Key Features:
TTL-Based Caching:
Cache Features:
32 of the 33 tools support Gemini CLI's native @filename syntax for optimal token efficiency. OpenRouter tools include enhanced large file handling:
# Single file
gemini_prompt(prompt="Analyze @config.py")
# Multiple files
gemini_review_code(code="@src/auth.py @src/middleware.py")
# Directories and wildcards
gemini_summarize(content="@src/ @tests/ @**/*.js")
# OpenRouter with intelligent file processing
gemini_openrouter_opinion(
prompt="Review @large_codebase/ for security",
model="anthropic/claude-3-haiku",
file_handling_strategy="auto" # auto, full, chunk, summarize
)
# Mixed content
gemini_eval_plan(plan="Based on @requirements.md, implement @design.py")
Benefits:
The modular template system provides significant advantages for enterprise deployments:
📈 Maintainability:
⚡ Performance:
🔧 Development Experience:
The server supports extensive configuration through environment variables:
export GEMINI_TIMEOUT=300 # Command timeout (10-3600 seconds)
export GEMINI_LOG_LEVEL=INFO # Logging level (DEBUG, INFO, WARNING, ERROR)
export GEMINI_COMMAND_PATH=gemini # Path to Gemini CLI executable
export GEMINI_OUTPUT_FORMAT=json # Response format (json, text)
export RETRY_MAX_ATTEMPTS=3 # Maximum retry attempts (1-10)
export RETRY_BASE_DELAY=1.0 # Base delay for exponential backoff (0.1-10.0)
export RETRY_MAX_DELAY=30.0 # Maximum delay between retries (5.0-300.0)
export GEMINI_PROMPT_LIMIT=100000 # gemini_prompt character limit
export GEMINI_SANDBOX_LIMIT=200000 # gemini_sandbox character limit
export GEMINI_EVAL_LIMIT=500000 # gemini_eval_plan character limit
export GEMINI_REVIEW_LIMIT=300000 # gemini_review_code character limit
export GEMINI_VERIFY_LIMIT=800000 # gemini_verify_solution character limit
export GEMINI_SUMMARIZE_LIMIT=400000 # gemini_summarize character limit
export GEMINI_SUMMARIZE_FILES_LIMIT=800000 # gemini_summarize_files character limit
export GEMINI_ENABLE_FALLBACK=true # Enable automatic model fallback
export GEMINI_RATE_LIMIT_REQUESTS=100 # Requests per time window
export GEMINI_RATE_LIMIT_WINDOW=60 # Time window in seconds
export OPENROUTER_API_KEY="sk-or-v1-your-api-key" # OpenRouter API key for 400+ models
export OPENROUTER_DEFAULT_MODEL="openai/gpt-4.1-nano" # Default OpenRouter model
export OPENROUTER_COST_LIMIT_PER_DAY="10.0" # Daily cost limit in USD
export OPENROUTER_ENABLE_STREAMING="true" # Enable streaming responses
export OPENROUTER_MAX_FILE_TOKENS="50000" # Per-file token limit for @filename
export OPENROUTER_MAX_TOTAL_TOKENS="150000" # Total prompt token limit
export GEMINI_CONVERSATION_ENABLED="true" # Enable conversation history
export GEMINI_CONVERSATION_STORAGE="redis" # Storage backend (redis, memory, auto)
export GEMINI_CONVERSATION_EXPIRATION_HOURS="24" # Auto-cleanup time
export GEMINI_CONVERSATION_MAX_MESSAGES="10" # Message history limit
export GEMINI_CONVERSATION_MAX_TOKENS="20000" # Token history limit
export GEMINI_REDIS_HOST="localhost" # Redis host for conversation storage
export GEMINI_REDIS_PORT="6479" # Redis port (custom to avoid conflicts)
# Route OpenRouter requests through Cloudflare AI Gateway for enhanced performance
export CLOUDFLARE_AI_GATEWAY_ENABLED="true" # Enable Cloudflare AI Gateway
export CLOUDFLARE_ACCOUNT_ID="your-account-id" # Cloudflare Account ID
export CLOUDFLARE_GATEWAY_ID="your-gateway-id" # Cloudflare Gateway ID
export CLOUDFLARE_AI_GATEWAY_TIMEOUT="300" # Gateway timeout in seconds
export CLOUDFLARE_AI_GATEWAY_MAX_RETRIES="3" # Maximum retry attempts
export ENABLE_MONITORING=true # Master control for all monitoring features
export ENABLE_OPENTELEMETRY=true # Enable OpenTelemetry distributed tracing
export ENABLE_PROMETHEUS=true # Enable Prometheus metrics collection
export ENABLE_HEALTH_CHECKS=true # Enable health check system
export PROMETHEUS_PORT=8000 # Prometheus metrics endpoint port
export OPENTELEMETRY_ENDPOINT="https://otel-collector:4317" # OpenTelemetry endpoint
export OPENTELEMETRY_SERVICE_NAME="gemini-cli-mcp-server" # Service name for tracing
export JSONRPC_MAX_REQUEST_SIZE=1048576 # Max JSON-RPC request size (1MB default)
export JSONRPC_MAX_NESTING_DEPTH=10 # Max object/array nesting depth
export JSONRPC_STRICT_MODE=true # Enable strict JSON-RPC validation
export GEMINI_SUBPROCESS_MAX_CPU_TIME=300 # Subprocess CPU time limit (seconds)
export GEMINI_SUBPROCESS_MAX_MEMORY_MB=512 # Subprocess memory limit (MB)
Standard Development:
# Use defaults - no configuration needed
With OpenRouter (400+ Models):
export OPENROUTER_API_KEY="sk-or-v1-your-api-key"
export OPENROUTER_COST_LIMIT_PER_DAY="10.0"
export OPENROUTER_DEFAULT_MODEL="anthropic/claude-3-haiku"
Full Enterprise Setup:
# Core configuration
export GEMINI_TIMEOUT=600
export GEMINI_EVAL_LIMIT=750000
export GEMINI_REVIEW_LIMIT=600000
export GEMINI_VERIFY_LIMIT=1200000
export RETRY_MAX_ATTEMPTS=5
# OpenRouter integration
export OPENROUTER_API_KEY="sk-or-v1-your-api-key"
export OPENROUTER_COST_LIMIT_PER_DAY="25.0"
export OPENROUTER_DEFAULT_MODEL="openai/gpt-4.1-mini"
# Cloudflare AI Gateway (optional)
export CLOUDFLARE_AI_GATEWAY_ENABLED="true"
export CLOUDFLARE_ACCOUNT_ID="your-account-id"
export CLOUDFLARE_GATEWAY_ID="your-gateway-id"
# Conversation history with Redis
export GEMINI_CONVERSATION_ENABLED="true"
export GEMINI_CONVERSATION_STORAGE="redis"
export GEMINI_REDIS_PORT="6479"
# Enterprise monitoring
export ENABLE_MONITORING="true"
export ENABLE_PROMETHEUS="true"
export PROMETHEUS_PORT="8000"
High-Performance Setup:
export GEMINI_LOG_LEVEL=WARNING
export RETRY_BASE_DELAY=0.5
export RETRY_MAX_DELAY=10.0
export GEMINI_RATE_LIMIT_REQUESTS=500
export OPENROUTER_ENABLE_STREAMING="true"
Debug Configuration:
export GEMINI_LOG_LEVEL=DEBUG
export GEMINI_OUTPUT_FORMAT=json
export GEMINI_TIMEOUT=120
export ENABLE_STDIN_DEBUG="1"
{
"status": "success",
"return_code": 0,
"stdout": "Response from Gemini AI",
"stderr": ""
}
Response from Gemini AI
Operation Times:
Concurrency:
Memory Usage:
Total Lines of Code: ~15,000+ lines across 83 modules
Cache Effectiveness:
For High-Throughput Scenarios:
export GEMINI_LOG_LEVEL=WARNING # Reduce logging overhead
export RETRY_BASE_DELAY=0.5 # Faster retry cycles
export GEMINI_RATE_LIMIT_REQUESTS=1000 # Higher rate limits
For Large Content Processing:
export GEMINI_TIMEOUT=1800 # Extended timeout (30 minutes)
export GEMINI_EVAL_LIMIT=1500000 # Maximum evaluation capacity
export GEMINI_VERIFY_LIMIT=2000000 # Maximum verification capacity
For Development Speed:
export GEMINI_OUTPUT_FORMAT=text # Faster response parsing
export RETRY_MAX_ATTEMPTS=1 # Fail fast for debugging
Use the gemini_metrics tool to monitor server performance:
gemini_metrics()
Key Metrics:
Test Server Import:
python -c "from mcp_server import mcp; print('✅ Server imports successfully')"
Test Gemini CLI Integration:
python -c "
import asyncio
from gemini_utils import validate_gemini_setup
print('✅ Gemini CLI setup valid' if validate_gemini_setup() else '❌ Gemini CLI setup invalid')
"
Test the server with the official MCP development tools:
# Install MCP development tools
uv pip install "mcp[dev]"
# Test server with MCP inspector
mcp dev mcp_server.py
This opens an interactive interface to test all MCP tools directly.
Test Basic Functionality:
# In Python REPL or script
import asyncio
from mcp_server import gemini_help, gemini_version, gemini_models
async def test_basic():
print("Testing basic functionality...")
# Test cached operations
help_result = await gemini_help()
print(f"Help: {len(help_result)} characters")
version_result = await gemini_version()
print(f"Version: {version_result[:50]}...")
models_result = await gemini_models()
print(f"Models: {models_result[:100]}...")
print("✅ Basic tests passed")
asyncio.run(test_basic())
Test Prompt Functionality:
import asyncio
from mcp_server import gemini_prompt
async def test_prompts():
print("Testing prompt functionality...")
result = await gemini_prompt(
prompt="Say hello and confirm you're working",
model="gemini-2.5-flash"
)
print(f"Prompt result: {result[:200]}...")
print("✅ Prompt tests passed")
asyncio.run(test_prompts())
The server has been comprehensively tested with:
Cause: MCP client can't connect to server or server isn't running.
Solutions:
python mcp_server.pyCause: Gemini CLI not installed or not in PATH.
Solutions:
npm install -g @google-ai/gemini-cligemini --versionexport GEMINI_COMMAND_PATH=/path/to/geminiCause: Gemini API key not configured or invalid.
Solutions:
gemini config set api_key YOUR_API_KEYgemini --versionCause: Too many requests in short time period.
Solutions:
export GEMINI_RATE_LIMIT_REQUESTS=500gemini-2.5-flashCause: Content exceeds tool-specific character limits.
Solutions:
wc -c your_file.txtexport GEMINI_EVAL_LIMIT=1000000gemini_summarize_files for file-based analysisDiagnostic Steps:
python --version (must be 3.10+)pip list | grep mcppython -c "import mcp"GEMINI_LOG_LEVEL=DEBUG python mcp_server.pyOptimization Steps:
gemini_metrics() toolexport GEMINI_LOG_LEVEL=WARNINGexport GEMINI_TIMEOUT=120Enable comprehensive debugging:
export GEMINI_LOG_LEVEL=DEBUG
export GEMINI_OUTPUT_FORMAT=json
python mcp_server.py
This provides detailed information about:
If you encounter issues not covered here:
gemini --helpgemini_version()gemini_metrics()mcp>=0.3.0
httpx>=0.24.0
cachetools>=5.3.0
pytest>=7.0.0 # For development and testing
pytest-mock>=3.10.0 # For mocking in tests
uvicorn[standard]>=0.20.0 # For alternative server deployment
io.github.ericm1018/skillfm-llm-cost-optimizer-openai-anthropic-usage
io.github.mikerawsonnz/llm-orchestration-agent
io.github.mikerawsonnz/authenticated-llm-agent
labforgedev/copilot-memory-mcp
csoai-org/agent-prompt-injection-firewall-mcp
io.github.mikerawsonnz/authenticated-multi-llm-agent