Skip to main content
Glama
amitsh06

MCP Gemini Server

by amitsh06

MCP ジェミニ サーバー

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

プロジェクト概要

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

Related MCP server: Gemini MCP Server

特徴

  • クライアント/サーバー通信: クライアントとサーバー間の安全なメッセージ交換のための 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

Resources

Looking for Admin?

Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.

Appeared in Searches

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/amitsh06/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server