Skip to content

Rohitp/mcp-cli-coder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gemini MCP Server

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.

Features

  • 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

Prerequisites

  • Python 3.10 or higher
  • Google Gemini CLI installed and configured

Installation

  1. Clone the repository:
git clone <repository-url>
cd mcp-cli-coder
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment variables by creating a .env file:
GEMINI_TIMEOUT=30
GEMINI_MAX_RETRIES=3

Available Tools

1. ask_gemini

Ask general questions to the Gemini AI model.

Parameters:

  • query (required): The question or prompt to send to Gemini
  • model (optional): The Gemini model to use (default: "gemini-1.5")
  • sandbox (optional): Whether to use sandbox environment (default: false)

2. analyze_file

Analyze the contents of a specific file.

Parameters:

  • file_path (required): Path to the file to be analyzed
  • analysis_type (required): Type of analysis (e.g., 'summary', 'code review', 'bug detection', 'keywords')
  • prompt (required): Custom prompt to guide the analysis
  • sandbox (optional): Whether to use sandbox environment (default: false)

3. analyze_directory

Analyze the contents of a directory and its files.

Parameters:

  • directory_path (required): Path to the directory to be analyzed
  • analysis_type (required): Type of analysis (e.g., 'summary', 'file types', 'code review', 'bug detection')
  • prompt (required): Custom prompt to guide the analysis
  • sandbox (optional): Whether to use sandbox environment (default: false)

Usage

Starting the Server

python src/main.py

The server will start and listen for MCP protocol messages via stdin/stdout.

Using from Another Project Directory

Since this MCP server communicates via stdio, you can use it from any project directory in several ways:

1. Direct Execution

# From any directory
python /path/to/mcp-cli-coder/src/main.py

2. Using the Wrapper Script

Use 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.sh

3. Global Installation

For 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-mcp

4. MCP Client Configuration

The 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"
      }
    }
  }
}

MCP Protocol Examples

Initialize Connection

{"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"}

List Available Tools

{"jsonrpc":"2.0","id":2,"method":"tools/list"}

Example Tool Calls

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"}}}

Test Sequence

{"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!"}}}

Architecture

Components

  • 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

Configuration

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

Development

Adding New Tools

  1. Create a new tool class inheriting from ToolBase
  2. Implement required methods: input_schema and execute
  3. Register the tool in src/tools/__init__.py

## License

This project is licensed under the MIT License.

About

An MCP server that can extend Geminis capabilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors