MCP Gemini Server

by amitsh06
Verified

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • 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.

MCP ジェミニ サーバー

Claude のような AI アシスタントが Google の Gemini API と対話できるようにする Model Context Protocol (MCP) のサーバー実装。

プロジェクト概要

このプロジェクトは、モデルコンテキストプロトコル(MCP)に準拠したサーバーを実装し、AIアシスタントがGoogleのGeminiモデルと通信できるようにします。このMCPサーバーにより、AIアシスタントはGemini APIを介してテキスト生成やテキスト分析をリクエストしたり、チャット会話を維持したりできるようになります。

特徴

  • クライアント/サーバー通信: クライアントとサーバー間の安全なメッセージ交換のための MCP プロトコルを実装します。
  • メッセージ処理: クライアント要求を処理し、適切な応答を送信します。
  • エラー処理とログ記録: サーバーのアクティビティをログに記録し、スムーズなエラー回復を保証します。
  • 環境変数のサポート: 機密情報を安全に保存するために.envファイルを使用します。
  • API テストとデバッグ: Postman とテスト スクリプトを使用した手動テストと自動テストをサポートします。

インストール

前提条件

  • Python 3.7以上
  • Google AI APIキー

設定

  1. このリポジトリをクローンします:
git clone https://github.com/yourusername/mcp-gemini-server.git cd mcp-gemini-server
  1. 仮想環境を作成します。
python -m venv venv
  1. 仮想環境をアクティブ化します。
    • Windows: venv\Scripts\activate
    • macOS/Linux: source venv/bin/activate
  2. 依存関係をインストールします:
pip install -r requirements.txt
  1. Gemini API キーを使用してルート ディレクトリに.envファイルを作成します。
GEMINI_API_KEY=your_api_key_here

使用法

  1. サーバーを起動します。
python server.py
  1. サーバーはデフォルトでhttp://localhost:5000/で実行されます。
  2. POSTメソッドを使用してMCPリクエストを/mcpエンドポイントに送信する

リクエスト例

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リファレンス

エンドポイント

  • GET /health : サーバーが稼働しているかどうかを確認する
  • GET /list-models : 利用可能なGeminiモデルの一覧
  • POST /mcp : MCPリクエストのメインエンドポイント

MCPアクション

1. テキストを生成する

Gemini を使用してテキスト コンテンツを生成します。

パラメータ:

  • prompt (必須): 生成のためのテキストプロンプト
  • temperature (オプション):ランダム性(0.0~1.0)を制御
  • max_tokens (オプション): 生成するトークンの最大数

例:

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

2. テキスト分析

テキストコンテンツを分析します。

パラメータ:

  • text (必須): 分析するテキスト
  • analysis_type (オプション): 分析の種類 ('sentiment'、'summary'、'keywords'、または 'general')

例:

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

3. チャット

ジェミニと会話しましょう。

パラメータ:

  • messages (必須): 'role' と 'content' を持つメッセージオブジェクトの配列
  • temperature (オプション):ランダム性(0.0~1.0)を制御

例:

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

エラー処理

サーバーは適切な HTTP ステータス コードとエラー メッセージを返します。

  • 200 : リクエスト成功
  • 400 : 不正なリクエスト (パラメータが欠落しているか無効です)
  • 500 : サーバーエラー (API の問題など)

テスト

付属のテスト スクリプトを使用して、さまざまな機能をテストします。

# 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プロトコル仕様

ここで実装されているモデルコンテキストプロトコルは、次の仕様に従います。

  1. リクエスト形式:
    • action : 操作を指定する文字列
    • parameters : アクション固有のパラメータを含むオブジェクト
  2. 応答形式:
    • result : 操作結果を含むオブジェクト
    • error : エラーを説明する文字列(該当する場合)

ライセンス

MITライセンス

-
security - not tested
F
license - not found
-
quality - not tested

Claude などの AI アシスタントがテキスト生成、テキスト分析、チャット会話のために Google の Gemini API と対話できるようにするモデル コンテキスト プロトコルを実装するサーバー。

  1. Project Overview
    1. Features
      1. Installation
        1. Prerequisites
        2. Setup
      2. Usage
        1. Example Request
      3. API Reference
        1. Endpoints
        2. MCP Actions
      4. Error Handling
        1. Testing
          1. MCP Protocol Specification
            1. License
              ID: 6zwht8u0yo