Supports environment variables through .env file for storing sensitive information like API keys securely.
Provides repository access through GitHub for cloning and installing the server.
Enables interaction with Google's Gemini API, allowing text generation, text analysis, and chat conversations through the Gemini models.
Supports running on Linux with specific virtual environment activation instructions.
Supports running on macOS with specific virtual environment activation instructions.
Supports testing and debugging API requests using Postman for manual testing.
Built using Python, requiring version 3.7 or higher for server implementation.
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.
Related MCP server: Gemini MCP Server
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
.envfile 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
Clone this repository:
Create a virtual environment:
Activate the virtual environment:
Windows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activate
Install dependencies:
Create a
.envfile in the root directory with your Gemini API key:
Usage
Start the server:
The server will run on
http://localhost:5000/by defaultSend MCP requests to the
/mcpendpoint using POST method
Example Request
API Reference
Endpoints
GET /health: Check if the server is runningGET /list-models: List available Gemini modelsPOST /mcp: Main endpoint for MCP requests
MCP Actions
1. generate_text
Generate text content with Gemini.
Parameters:
prompt(required): The text prompt for generationtemperature(optional): Controls randomness (0.0 to 1.0)max_tokens(optional): Maximum tokens to generate
Example:
2. analyze_text
Analyze text content.
Parameters:
text(required): The text to analyzeanalysis_type(optional): Type of analysis ('sentiment', 'summary', 'keywords', or 'general')
Example:
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:
Error Handling
The server returns appropriate HTTP status codes and error messages:
200: Successful request400: Bad request (missing or invalid parameters)500: Server error (API issues, etc.)
Testing
Use the included test script to test various functionalities:
MCP Protocol Specification
The Model Context Protocol implemented here follows these specifications:
Request Format:
action: String specifying the operationparameters: Object containing action-specific parameters
Response Format:
result: Object containing the operation resulterror: String explaining any error (when applicable)
License
MIT License