A Model Context Protocol (MCP) server that provides access to Google's Gemini AI models with enhanced analysis capabilities. This server leverages Gemini's large context window to analyze files and directories that may exceed other models' token limits. All tests here are vibe coded.
- General AI Queries: Ask questions directly to Gemini models
- File Analysis: Analyze individual files with custom prompts and analysis types
- Directory Analysis: Analyze entire directories and their contents
- Sandbox Mode: Optional sandboxed execution for security
- Flexible Model Selection: Support for different Gemini model variants
- Python 3.10 or higher
- Google Gemini CLI installed and configured
- Clone the repository:
git clone <repository-url>
cd mcp-cli-coder- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate - Install dependencies:
pip install -r requirements.txt- Configure environment variables by creating a
.envfile:
GEMINI_TIMEOUT=30
GEMINI_MAX_RETRIES=3Ask general questions to the Gemini AI model.
Parameters:
query(required): The question or prompt to send to Geminimodel(optional): The Gemini model to use (default: "gemini-1.5")sandbox(optional): Whether to use sandbox environment (default: false)
Analyze the contents of a specific file.
Parameters:
file_path(required): Path to the file to be analyzedanalysis_type(required): Type of analysis (e.g., 'summary', 'code review', 'bug detection', 'keywords')prompt(required): Custom prompt to guide the analysissandbox(optional): Whether to use sandbox environment (default: false)
Analyze the contents of a directory and its files.
Parameters:
directory_path(required): Path to the directory to be analyzedanalysis_type(required): Type of analysis (e.g., 'summary', 'file types', 'code review', 'bug detection')prompt(required): Custom prompt to guide the analysissandbox(optional): Whether to use sandbox environment (default: false)
python src/main.pyThe server will start and listen for MCP protocol messages via stdin/stdout.
Since this MCP server communicates via stdio, you can use it from any project directory in several ways:
# From any directory
python /path/to/mcp-cli-coder/src/main.pyUse the included run_server.sh script for easier execution:
# Make the script executable (one time setup)
chmod +x /path/to/mcp-cli-coder/run_server.sh
# Run from any directory
/path/to/mcp-cli-coder/run_server.shFor system-wide access, create a symlink:
# Add to your PATH (one time setup)
sudo ln -s /path/to/mcp-cli-coder/run_server.sh /usr/local/bin/gemini-mcp
# Then use from anywhere
gemini-mcpThe most common usage is through an MCP client like Claude Desktop. Add this to your MCP settings:
{
"servers": {
"gemini-mcp": {
"command": "python",
"args": ["/path/to/mcp-cli-coder/src/main.py"],
"env": {
"PYTHONPATH": "/path/to/mcp-cli-coder/src"
}
}
}
}{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}{"jsonrpc":"2.0","id":2,"method":"tools/list"}Ask Gemini:
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"ask_gemini","arguments":{"query":"What is the capital of France?","model":"gemini-1.5-flash","sandbox":false}}}Analyze File:
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"analyze_file","arguments":{"file_path":"./src/main.py","analysis_type":"code review","prompt":"Review this Python code for best practices and potential improvements"}}}Analyze Directory:
{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"analyze_directory","arguments":{"directory_path":"./src","analysis_type":"summary","prompt":"Provide an overview of this Python project structure"}}}{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"ping","arguments":{"message":"Hello from complete test!"}}}- MCP Server: Core server implementation using the MCP protocol
- Tool Registry: Manages and dispatches tool calls
- Gemini Controller: Handles interactions with the Gemini CLI
- Tool Implementations: Individual tool classes for different functionalities
The server uses environment variables for configuration. Create a .env file in the project root:
# Gemini CLI Configuration
GEMINI_TIMEOUT=30
GEMINI_MAX_RETRIES=3
- Create a new tool class inheriting from
ToolBase - Implement required methods:
input_schemaandexecute - Register the tool in
src/tools/__init__.py
## License
This project is licensed under the MIT License.