Provides access to Google's Gemini AI models through the Gemini CLI, allowing users to execute prompts, manage persistent chat sessions, and utilize CLI extensions with features like ANSI stripping and optional 'YOLO' mode for automated actions.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Gemini CLI MCP Serverlist my recent chat sessions"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Gemini CLI MCP Server
An MCP (Model Context Protocol) server that wraps the Gemini CLI, exposing it over both stdio and SSE (Server-Sent Events) transports.
Overview
This server allows remote clients to execute Gemini CLI commands through the MCP protocol. It can run as:
Local stdio server (
server.py) - for direct MCP client integrationNetwork SSE server (
server_sse.py) - for remote network access on port 8601
Features
Dual Transport: Supports both stdio (local) and SSE (network) transports
Gemini CLI Integration: Executes prompts through the Gemini CLI
ANSI Stripping: Cleans terminal escape codes from output
Systemd Integration: Runs as a persistent user service
Network Accessible: Binds to
0.0.0.0for external accessSession Management: Resume previous sessions, list sessions
Extension Support: List available Gemini CLI extensions
YOLO Mode: Auto-approve actions for automated use
Architecture
Directory Structure
Prerequisites
Gemini CLI: Ensure
geminiis installed and in your PATH.npm install -g @google/gemini-cliAuthentication: You must be authenticated with Google/Gemini.
gemini # Follow the authentication promptsPython: Python 3.10 or higher.
Installation
Quick Install
Full Installation with Systemd Service
Configuration
Environment Variables
Variable | Default | Description |
|
| Host to bind to (SSE server only) |
|
| Port to listen on (SSE server only) |
Network Settings
The SSE server is configured for external access:
Binds to
0.0.0.0(all interfaces)Port
8601DNS rebinding protection disabled for external clients
Usage
Option 1: Local stdio Server
For direct MCP client integration (same machine):
MCP Client Configuration:
Option 2: Network SSE Server
For remote network access:
Manual Start:
Background Start:
Option 3: Systemd Service (Recommended for SSE)
The SSE server can be configured as a systemd user service for automatic startup.
Create the service file:
Service Management:
API Reference
Endpoints (SSE Server)
Endpoint | Method | Description |
| GET | SSE connection endpoint for MCP clients |
| POST | Message posting endpoint |
MCP Tools
run_gemini
Execute a command or query using the Gemini CLI.
Parameters:
Name | Type | Required | Default | Description |
| string | Yes | - | The prompt or command to send to Gemini |
| string | No |
| Model to use (e.g., gemini-2.5-flash, gemini-2.0-flash-exp, gemini-1.5-pro) |
| boolean | No |
| Run in sandbox mode (isolated environment for safety) |
| boolean | No |
| Auto-approve all actions (recommended for automated use) |
| string | No |
| Output format: 'text', 'json', or 'stream-json' |
| boolean | No |
| Enable debug mode for verbose output |
| string | No |
| Comma-separated list of additional directories to include |
Returns: String containing the Gemini CLI output with ANSI codes stripped.
Example:
gemini_resume
Resume a previous Gemini CLI session.
Parameters:
Name | Type | Required | Default | Description |
| string | No |
| Session to resume. Use "latest" or index number |
| string | No |
| Optional prompt to continue the conversation |
Returns: String containing the session response.
Example:
gemini_list_sessions
List available Gemini CLI sessions for the current project.
Parameters: None
Returns: String listing available sessions.
Example:
gemini_list_extensions
List all available Gemini CLI extensions.
Parameters: None
Returns: String listing installed extensions.
Example:
gemini_version
Get the Gemini CLI version information.
Parameters: None
Returns: String containing version information (e.g., "0.20.0").
Example:
gemini_delete_session
Delete a Gemini CLI session by index number.
Parameters:
Name | Type | Required | Default | Description |
| string | Yes | - | The index number of the session to delete |
Returns: String confirming deletion or error message.
Example:
gemini_json
Execute a Gemini prompt and return structured JSON output. Useful for programmatic parsing of responses.
Parameters:
Name | Type | Required | Default | Description |
| string | Yes | - | The prompt or command to send to Gemini |
| string | No |
| Optional model to use |
| boolean | No |
| Whether to run in sandbox mode |
| boolean | No |
| Whether to auto-approve all actions |
Returns: JSON-formatted response from Gemini.
Example:
gemini_with_context
Execute a Gemini prompt with specific file or directory context. Uses @ syntax to include file contents in the prompt.
Parameters:
Name | Type | Required | Default | Description |
| string | Yes | - | The prompt or command to send to Gemini |
| string | No |
| Comma-separated list of file paths to include (e.g., "src/main.py,README.md") |
| string | No |
| Comma-separated list of directories to include |
| string | No |
| Optional model to use |
| boolean | No |
| Whether to auto-approve all actions |
Returns: String containing Gemini's response with file context.
Example:
gemini_shell
Execute a shell command through Gemini CLI using ! syntax. Gemini can observe the output and provide analysis.
Parameters:
Name | Type | Required | Default | Description |
| string | Yes | - | Shell command to execute (without the ! prefix) |
Returns: String containing command output and Gemini's analysis.
Example:
gemini_chat_save
Save the current Gemini chat session.
Parameters:
Name | Type | Required | Default | Description |
| string | No |
| Optional name for the saved session |
Returns: String confirming save status.
Example:
gemini_help
Get Gemini CLI help information and available commands.
Parameters: None
Returns: String containing CLI help output.
Example:
Client Configuration
MCP Configuration File Locations
Client | Configuration File Location |
Claude Desktop (macOS) |
|
Claude Desktop (Windows) |
|
Claude Desktop (Linux) |
|
Claude Code |
|
Cline (VS Code) | VS Code settings or |
Option 1: SSE Transport (Network/Remote Access) - RECOMMENDED
Use this for network access or when the server runs as a systemd service.
Claude Desktop / Claude Code:
Remote Server Access:
Cline (VS Code Extension):
Option 2: stdio Transport (Local/Direct)
Use this for local-only access without running a persistent service.
Claude Desktop (with venv):
Claude Desktop (system Python):
With Environment Variables:
Option 3: Project-Specific Configuration
Create a .mcp.json file in your project root:
Complete Configuration Examples
Full Claude Desktop config with multiple MCP servers:
Claude Code settings.json:
Verifying the Configuration
After adding the configuration, verify the MCP server is accessible:
Restart your MCP client (Claude Desktop, Claude Code, etc.) after updating the configuration.
Troubleshooting
Server won't start
Check if port is in use:
ss -tlnp | grep 8601Kill existing process:
lsof -i :8601 | awk 'NR>1 {print $2}' | xargs killCheck logs:
journalctl --user -u gemini-mcp-server -n 50
Connection refused
Verify server is running:
systemctl --user status gemini-mcp-serverCheck firewall:
sudo ufw status sudo ufw allow 8601/tcpTest locally:
curl -I http://localhost:8601/
Gemini CLI errors
Verify CLI is installed:
which gemini gemini --versionTest CLI directly:
gemini "Hello" -o text -y
Security Considerations
Warning: This server exposes Gemini CLI over the network.
The server uses YOLO mode (
-y) by default for automated useConsider using a firewall to restrict access
Consider using a reverse proxy with authentication for production use
Be mindful of API costs when exposing to network
Recommended Security Measures
Firewall rules:
# Allow only specific IPs sudo ufw allow from 192.168.1.0/24 to any port 8601Reverse proxy with auth (nginx example):
location /mcp/ { auth_basic "MCP Server"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://localhost:8601/; }
Files Reference
server.py
Original stdio transport server for local MCP client integration.
server_sse.py
SSE transport server for network access. Configured to:
Listen on
0.0.0.0:8601Disable DNS rebinding protection
Allow all hosts and origins
requirements.txt
Systemd Service File
Location: /home/ward/.config/systemd/user/gemini-mcp-server.service
Deployment & Management Commands
Quick Reference
Health Check Commands
Process Management
Log Analysis
Service Configuration
Port Registration
This service is registered in the system port log (~/.claude/PORT-LOG.md):
Port | Service | Description |
8601 | MCP SSE | Gemini CLI MCP Server with SSE transport |
Comparison with Claude Code MCP Server
Feature | Claude Code MCP Server | Gemini CLI MCP Server |
Port | 8600 | 8601 |
CLI Tool |
|
|
Primary Tool |
|
|
Auto-Approve Flag |
|
|
Session Support | No | Yes ( |
Extensions | No | Yes ( |
Transport | stdio, SSE | stdio, SSE |
License
MIT License
Author
Created with Claude Code
Changelog
v1.1.0 (2025-12-10)
Enhanced
run_geminiwith new parameters:output_format: Choose between text, json, or stream-jsondebug: Enable verbose debug outputinclude_directories: Include additional directories in context
Added new tools based on official documentation:
gemini_delete_session: Delete sessions by indexgemini_json: Get structured JSON outputgemini_with_context: Include files/directories using @ syntaxgemini_shell: Execute shell commands with ! syntaxgemini_chat_save: Save chat sessionsgemini_help: Get CLI help information
Now supports 12 MCP tools total
Improved error handling and validation
v1.0.0 (2025-12-10)
Initial release
stdio and SSE transport support
Gemini CLI integration with
run_geminitoolSession management with
gemini_resumeandgemini_list_sessionstoolsExtension listing with
gemini_list_extensionstoolVersion info with
gemini_versiontoolANSI code stripping
Comprehensive documentation
Systemd service template