Skip to main content
Glama

Gemini Context MCP Server

by ogoldberg

Gemini コンテキスト MCP サーバー

Geminiのコンテキスト管理とキャッシュ機能を活用する強力なMCP(Model Context Protocol)サーバー実装。このサーバーは、Geminiの2Mトークンコンテキストウィンドウの価値を最大限に高めるとともに、大規模なコンテキストを効率的にキャッシュするためのツールを提供します。

🚀 機能

コンテキスト管理

  • 最大200万トークンのコンテキストウィンドウをサポート- Geminiの広範なコンテキスト機能を活用
  • セッションベースの会話- 複数のインタラクションにわたって会話状態を維持する
  • スマートなコンテキスト追跡- メタデータを使用してコンテキストを追加、取得、検索します
  • セマンティック検索- 意味的類似性を使用して関連するコンテキストを見つける
  • 自動コンテキストクリーンアップ- セッションとコンテキストは自動的に期限切れになります

APIキャッシュ

  • 大規模なプロンプトのキャッシュ- 大規模なシステムプロンプトと指示を効率的に再利用します
  • コスト最適化- 頻繁に使用されるコンテキストのトークン使用コストを削減
  • TTL管理- キャッシュの有効期限を制御する
  • 自動クリーンアップ- 期限切れのキャッシュは自動的に削除されます

🏁 クイックスタート

前提条件

インストール

# Clone the repository git clone https://github.com/ogoldberg/gemini-context-mcp-server cd gemini-context-mcp-server # Install dependencies npm install # Copy environment variables example cp .env.example .env # Add your Gemini API key to .env file # GEMINI_API_KEY=your_api_key_here

基本的な使い方

# Build the server npm run build # Start the server node dist/mcp-server.js

MCPクライアント統合

この MCP サーバーは、さまざまな MCP 互換クライアントと統合できます。

  • Claude Desktop - Claude 設定で MCP サーバーとして追加
  • カーソル- カーソルのAI/MCP設定で設定します
  • VS Code - MCP 互換拡張機能と併用

各クライアントとの詳細な統合手順については、MCP ドキュメントの「MCP クライアント構成ガイド」を参照してください。

クイッククライアントセットアップ

簡素化されたクライアント インストール コマンドを使用します。

# Install and configure for Claude Desktop npm run install:claude # Install and configure for Cursor npm run install:cursor # Install and configure for VS Code npm run install:vscode

各コマンドは適切な構成ファイルを設定し、統合を完了するための手順を提供します。

💻 使用例

初心者向け

サーバーを直接使用する:
  1. サーバーを起動します。
    node dist/mcp-server.js
  2. 提供されているテスト スクリプトを使用して対話します。
    # Test basic context management node test-gemini-context.js # Test caching features node test-gemini-api-cache.js
Node.js アプリケーションでの使用:
import { GeminiContextServer } from './src/gemini-context-server.js'; async function main() { // Create server instance const server = new GeminiContextServer(); // Generate a response in a session const sessionId = "user-123"; const response = await server.processMessage(sessionId, "What is machine learning?"); console.log("Response:", response); // Ask a follow-up in the same session (maintains context) const followUp = await server.processMessage(sessionId, "What are popular algorithms?"); console.log("Follow-up:", followUp); } main();

パワーユーザー向け

カスタム構成の使用:
// Custom configuration const config = { gemini: { apiKey: process.env.GEMINI_API_KEY, model: 'gemini-2.0-pro', temperature: 0.2, maxOutputTokens: 1024, }, server: { sessionTimeoutMinutes: 30, maxTokensPerSession: 1000000 } }; const server = new GeminiContextServer(config);
コスト最適化のためのキャッシュ システムの使用:
// Create a cache for large system instructions const cacheName = await server.createCache( 'Technical Support System', 'You are a technical support assistant for a software company...', 7200 // 2 hour TTL ); // Generate content using the cache const response = await server.generateWithCache( cacheName, 'How do I reset my password?' ); // Clean up when done await server.deleteCache(cacheName);

🔌 MCPツール(カーソルなど)と併用する

このサーバーはモデルコンテキストプロトコル (MCP) を実装しており、Cursor などのツールやその他の AI 強化開発環境との互換性を実現しています。

利用可能なMCPツール

  1. コンテキスト管理ツール:
    • generate_text - コンテキスト付きテキストを生成する
    • get_context - セッションの現在のコンテキストを取得する
    • clear_context - セッションコンテキストをクリアする
    • add_context - 特定のコンテキストエントリを追加する
    • search_context - 意味的に関連コンテキストを検索する
  2. キャッシュツール:
    • mcp_gemini_context_create_cache - 大きなコンテキストのキャッシュを作成する
    • mcp_gemini_context_generate_with_cache - キャッシュされたコンテキストを使用して生成する
    • mcp_gemini_context_list_caches - 利用可能なすべてのキャッシュを一覧表示する
    • mcp_gemini_context_update_cache_ttl - キャッシュTTLの更新
    • mcp_gemini_context_delete_cache - キャッシュを削除する

カーソルで接続する

Cursorと一緒に使用する場合は、MCP 構成を介して接続できます。

{ "name": "gemini-context", "version": "1.0.0", "description": "Gemini context management and caching MCP server", "entrypoint": "dist/mcp-server.js", "capabilities": { "tools": true }, "manifestPath": "mcp-manifest.json", "documentation": "README-MCP.md" }

MCP ツールの詳細な使用手順については、 README-MCP.md を参照してください。

⚙️ 設定オプション

環境変数

次のオプションで.envファイルを作成します。

# Required GEMINI_API_KEY=your_api_key_here GEMINI_MODEL=gemini-2.0-flash # Optional - Model Settings GEMINI_TEMPERATURE=0.7 GEMINI_TOP_K=40 GEMINI_TOP_P=0.9 GEMINI_MAX_OUTPUT_TOKENS=2097152 # Optional - Server Settings MAX_SESSIONS=50 SESSION_TIMEOUT_MINUTES=120 MAX_MESSAGE_LENGTH=1000000 MAX_TOKENS_PER_SESSION=2097152 DEBUG=false

🧪 開発

# Build TypeScript files npm run build # Run in development mode with auto-reload npm run dev # Run tests npm test

📚 さらに詳しく

  • MCP固有の使用方法については、 README-MCP.mdを参照してください。
  • 利用可能なツールを理解するために、mcp-manifest.jsonのマニフェストを調べてください。
  • リポジトリ内のサンプルスクリプトの使用パターンを確認する

📋 今後の改善点

  • コンテキストとキャッシュのデータベース永続性
  • キャッシュサイズの管理と削除ポリシー
  • ベクトルベースのセマンティック検索
  • 分析と指標の追跡
  • ベクターストアとの統合
  • コンテキスト管理のためのバッチ操作
  • ハイブリッドキャッシュ戦略
  • 自動プロンプト最適化

📄 ライセンス

マサチューセッツ工科大学

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

複数の AI クライアント アプリケーションにわたって効率的なコンテキスト管理とキャッシュを行うツールを使用して、Gemini の 2M トークン コンテキスト ウィンドウを最大化する MCP サーバー実装。

  1. 🚀 機能
    1. コンテキスト管理
    2. APIキャッシュ
  2. 🏁 クイックスタート
    1. 前提条件
    2. インストール
    3. 基本的な使い方
    4. MCPクライアント統合
  3. 💻 使用例
    1. 初心者向け
    2. パワーユーザー向け
  4. 🔌 MCPツール(カーソルなど)と併用する
    1. 利用可能なMCPツール
    2. カーソルで接続する
  5. ⚙️ 設定オプション
    1. 環境変数
  6. 🧪 開発
    1. 📚 さらに詳しく
      1. 📋 今後の改善点
        1. 📄 ライセンス

          Related MCP Servers

          • -
            security
            A
            license
            -
            quality
            The ultimate Gemini API interface for MCP hosts, intelligently selecting models for the task at hand—delivering optimal performance, minimal token cost, and seamless integration.
            Last updated -
            18
            MIT License
          • A
            security
            A
            license
            A
            quality
            A dedicated server that wraps Google's Gemini AI models in a Model Context Protocol (MCP) interface, allowing other LLMs and MCP-compatible systems to access Gemini's capabilities like content generation, function calling, chat, and file handling through standardized tools.
            Last updated -
            16
            32
            MIT License
            • Linux
            • Apple
          • -
            security
            A
            license
            -
            quality
            A Model Context Protocol (MCP) server implementation for the Google Gemini language model. This server allows Claude Desktop users to access the powerful reasoning capabilities of Gemini-2.0-flash-thinking-exp-01-21 model.
            Last updated -
            1
            MIT License
          • A
            security
            F
            license
            A
            quality
            A Model Context Protocol server that enables AI assistants to interact with Google Gemini CLI, allowing them to leverage Gemini's large token window for analyzing files and codebases using natural language commands.
            Last updated -
            6
            40,286
            1,317
            • Apple
            • Linux

          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/ogoldberg/gemini-context-mcp-server'

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