Skip to main content
Glama

MCP Gemini Server

by amitsh06

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

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

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

  1. プロジェクト概要
    1. 特徴
      1. インストール
        1. 前提条件
        2. 設定
      2. 使用法
        1. リクエスト例
      3. APIリファレンス
        1. エンドポイント
        2. MCPアクション
      4. エラー処理
        1. テスト
          1. MCPプロトコル仕様
            1. ライセンス

              Related MCP Servers

              • -
                security
                A
                license
                -
                quality
                Model Context Protocol (MCP) server implementation that enables Claude Desktop to interact with Google's Gemini AI models.
                Last updated -
                53
                TypeScript
                MIT License
                • Apple
                • Linux
              • -
                security
                F
                license
                -
                quality
                A Model Context Protocol server that enables AI assistants to interact with Gmail services, supporting email operations, draft management, and calendar functionality through Google API integration.
                Last updated -
                TypeScript
              • A
                security
                A
                license
                A
                quality
                A Model Context Protocol server that enables AI assistants like Claude to interact with Google Cloud Platform environments through natural language, allowing users to query and manage GCP resources during conversations.
                Last updated -
                9
                102
                62
                TypeScript
                MIT License
              • -
                security
                F
                license
                -
                quality
                A Model Context Protocol server that enables Claude Desktop to interact with Google's Gemini 2.5 Pro Experimental AI model, with features like Google Search integration and token usage reporting.
                Last updated -
                JavaScript

              View all related MCP servers

              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