MCP Gemini Server

MCP Gemini Server

A server implementing the Model Context Protocol that enables AI assistants like Claude to interact with Google's Gemini API for text generation, text analysis, and chat conversations.

amitsh06

Developer Tools
Visit Server

README

MCP Gemini Server

A server implementation of the Model Context Protocol (MCP) to enable AI assistants like Claude to interact with Google's Gemini API.

Project Overview

This project implements a server that follows the Model Context Protocol, allowing AI assistants to communicate with Google's Gemini models. With this MCP server, AI assistants can request text generation, text analysis, and maintain chat conversations through the Gemini API.

Features

  • Client-Server Communication: Implements MCP protocol for secure message exchange between client and server.
  • Message Processing: Handles and processes client requests, sending appropriate responses.
  • Error Handling & Logging: Logs server activities and ensures smooth error recovery.
  • Environment Variables Support: Uses .env file for storing sensitive information securely.
  • API Testing & Debugging: Supports manual and automated testing using Postman and test scripts.

Installation

Prerequisites

  • Python 3.7 or higher
  • Google AI API key

Setup

  1. Clone this repository:
git clone https://github.com/yourusername/mcp-gemini-server.git
cd mcp-gemini-server
  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:

    • Windows: venv\Scripts\activate
    • macOS/Linux: source venv/bin/activate
  2. Install dependencies:

pip install -r requirements.txt
  1. Create a .env file in the root directory with your Gemini API key:
GEMINI_API_KEY=your_api_key_here

Usage

  1. Start the server:
python server.py
  1. The server will run on http://localhost:5000/ by default

  2. Send MCP requests to the /mcp endpoint using POST method

Example Request

import requests

url = 'http://localhost:5000/mcp'
payload = {
    'action': 'generate_text',
    'parameters': {
        'prompt': 'Write a short poem about AI',
        'temperature': 0.7
    }
}

response = requests.post(url, json=payload)
print(response.json())

API Reference

Endpoints

  • GET /health: Check if the server is running
  • GET /list-models: List available Gemini models
  • POST /mcp: Main endpoint for MCP requests

MCP Actions

1. generate_text

Generate text content with Gemini.

Parameters:

  • prompt (required): The text prompt for generation
  • temperature (optional): Controls randomness (0.0 to 1.0)
  • max_tokens (optional): Maximum tokens to generate

Example:

{
  "action": "generate_text",
  "parameters": {
    "prompt": "Write a short story about a robot",
    "temperature": 0.8,
    "max_tokens": 500
  }
}

2. analyze_text

Analyze text content.

Parameters:

  • text (required): The text to analyze
  • analysis_type (optional): Type of analysis ('sentiment', 'summary', 'keywords', or 'general')

Example:

{
  "action": "analyze_text",
  "parameters": {
    "text": "The weather today is wonderful! I love how the sun is shining.",
    "analysis_type": "sentiment"
  }
}

3. chat

Have a conversation with Gemini.

Parameters:

  • messages (required): Array of message objects with 'role' and 'content'
  • temperature (optional): Controls randomness (0.0 to 1.0)

Example:

{
  "action": "chat",
  "parameters": {
    "messages": [
      {"role": "user", "content": "Hello, how are you?"},
      {"role": "assistant", "content": "I'm doing well! How can I help?"},
      {"role": "user", "content": "Tell me about quantum computing"}
    ],
    "temperature": 0.7
  }
}

Error Handling

The server returns appropriate HTTP status codes and error messages:

  • 200: Successful request
  • 400: Bad request (missing or invalid parameters)
  • 500: Server error (API issues, etc.)

Testing

Use the included test script to test various functionalities:

# Test all functionalities
python test_client.py

# Test specific functionality
python test_client.py text     # Test text generation
python test_client.py analyze  # Test text analysis
python test_client.py chat     # Test chat functionality

MCP Protocol Specification

The Model Context Protocol implemented here follows these specifications:

  1. Request Format:

    • action: String specifying the operation
    • parameters: Object containing action-specific parameters
  2. Response Format:

    • result: Object containing the operation result
    • error: String explaining any error (when applicable)

License

MIT License

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
MCP Package Docs Server

MCP Package Docs Server

Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.

Featured
Local
TypeScript
Claude Code MCP

Claude Code MCP

An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.

Featured
Local
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.

Featured
Local
JavaScript
Linear MCP Server

Linear MCP Server

Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.

Featured
JavaScript
mermaid-mcp-server

mermaid-mcp-server

A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.

Featured
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP server to provide Jira Tickets information to AI coding agents like Cursor

Featured
TypeScript
Linear MCP Server

Linear MCP Server

A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.

Featured
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Featured
Python