gemini-mcp-server

OriShmila/gemini-mcp-server

3.2

If you are the rightful owner of gemini-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

Gemini MCP Server is a production-ready server providing Gemini AI capabilities with Google Search grounding and direct model inference.

Tools
2
Resources
0
Prompts
0

Gemini MCP Server

A production-ready Model Context Protocol (MCP) server providing Gemini AI capabilities with Google Search grounding and direct model inference.

๐ŸŒŸ Features

  • ๐Ÿ” Google Search Grounding: Real-time web search using Gemini with Google Search grounding for factual, up-to-date information
  • ๐Ÿค– Direct Model Inference: Call Gemini directly for tasks that don't require real-time information
  • ๐Ÿ“Š JSON Schema Validation: Strict input/output validation for reliable tool responses
  • ๐Ÿงช Comprehensive Testing: Full test suite with schema validation and error handling
  • โšก High Performance: Optimized for fast response times

๐Ÿš€ Quick Start

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/gemini-mcp-server.git
    cd gemini-mcp-server
    
  2. Install dependencies:

    uv sync
    
  3. Set up environment variables:

    # Copy the example environment file
    cp .env.example .env
    
    # Edit .env and add your Gemini API key
    GEMINI_API_KEY=your_api_key_here
    
  4. Test the server:

    uv run python test_server.py
    

Getting a Gemini API Key

  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Create a new API key
  4. Copy the key and add it to your .env file

๐Ÿ› ๏ธ Available Tools

1. gemini_websearch

Search the web using Gemini with Google Search grounding.

Features:

  • โœ… Real-time search results with Google Search grounding
  • ๐ŸŒ Language support - Automatically translates results to requested language
  • ๐Ÿ“Š Structured output with proper source attribution
  • ๐ŸŽฏ Custom fields - Request additional metadata per result

Parameters:

  • query (required): Search query string
  • language (optional): Language code for result translation (e.g., "es", "fr", "ja")
  • extraFieldsProperties (optional): Additional fields to include in results

Example:

{
  "query": "latest AI developments 2024",
  "language": "es"
}

2. gemini_call

Call Gemini model directly without grounding for structured responses.

Features:

  • ๐ŸŽฏ JSON Schema constraints - Get structured responses that match your schema
  • ๐Ÿ“ Flexible input - Pass arbitrary data and context
  • ๐Ÿš€ Fast responses - Direct model inference without web search
  • ๐Ÿ’ช Complex schemas - Support for nested objects and arrays

Parameters:

  • prompt (required): Instruction describing the task
  • args (optional): Structured data to include in the prompt
  • outputSchema (required): JSON Schema defining expected response structure

Example:

{
  "prompt": "Analyze this financial data and extract key metrics",
  "args": {
    "revenue": "$1.2B",
    "quarter": "Q3 2024"
  },
  "outputSchema": {
    "type": "object",
    "properties": {
      "revenue_usd": {"type": "number"},
      "growth_rate": {"type": "number"}
    }
  }
}

๐Ÿ”ง Usage with MCP Clients

Claude Desktop Configuration

Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "gemini": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/yourusername/gemini-mcp-server",
        "gemini-server"
      ],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Other MCP Clients

The server implements the standard MCP protocol and works with any compatible client:

  1. Tool Discovery: Clients call list_tools to see available tools
  2. Tool Execution: Clients call call_tool with tool name and arguments
  3. Response: Server returns structured JSON responses with validation

๐Ÿงช Testing

Run the comprehensive test suite:

uv run python test_server.py

The test suite includes:

  • โœ… Schema validation tests
  • โœ… Success case testing for both tools
  • โœ… Error handling validation
  • โœ… Input parameter validation
  • โœ… Output structure verification
  • โœ… Performance monitoring

Expected Results:

  • All 10 test cases should pass
  • Web search tests will show "AFC remote call" logs (indicating real grounding)
  • Response times should be under 10 seconds for search operations

๐Ÿ“Š Performance

  • Search Operations: ~3-6 seconds (with Google Search grounding)
  • Direct Model Calls: ~0.5-1 second
  • Schema Validation: <1ms per request
  • Memory Usage: ~50MB base + request processing

๐Ÿ—๏ธ Architecture

gemini-mcp-server/
โ”œโ”€โ”€ gemini_mcp_server/          # Main package
โ”‚   โ”œโ”€โ”€ handlers.py            # Tool implementations
โ”‚   โ”œโ”€โ”€ server.py              # MCP server core
โ”‚   โ”œโ”€โ”€ tools.json             # Tool schemas
โ”‚   โ””โ”€โ”€ __main__.py            # Entry point
โ”œโ”€โ”€ test_server.py             # Test framework
โ”œโ”€โ”€ test_cases.json            # Test definitions
โ””โ”€โ”€ pyproject.toml             # Dependencies

๐Ÿ” Key Technologies

๐Ÿšฆ Error Handling

The server includes comprehensive error handling:

  • Invalid API Key: Clear error messages for authentication issues
  • Network Errors: Graceful handling of API timeouts and connectivity
  • Schema Validation: Detailed error messages for malformed requests
  • Rate Limiting: Automatic retry logic for API rate limits

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ”— Resources

๐Ÿ†˜ Troubleshooting

Common Issues

  1. "GEMINI_API_KEY not configured"

    • Ensure your .env file exists and contains a valid API key
    • Check that the key has proper permissions
  2. Tests failing with network errors

    • Verify internet connectivity
    • Check if API key has rate limiting issues
  3. Schema validation errors

    • Ensure your requests match the expected input schemas
    • Check the tools.json file for parameter requirements

Getting Help

  • Check the test output for detailed error messages
  • Review the Gemini API documentation
  • Open an issue on GitHub with error logs

Ready to integrate powerful AI capabilities into your applications with real-time web search and structured model inference! ๐Ÿš€