Gemini Context MCP Server

Integrations

  • Provides a Node.js application interface for integrating the MCP server into custom applications, with support for context management and caching features

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. 🚀 Features
    1. Context Management
    2. API Caching
  2. 🏁 Quick Start
    1. Prerequisites
    2. Installation
    3. Basic Usage
    4. MCP Client Integration
  3. 💻 Usage Examples
    1. For Beginners
    2. For Power Users
  4. 🔌 Using with MCP Tools (like Cursor)
    1. Available MCP Tools
    2. Connecting with Cursor
  5. ⚙️ Configuration Options
    1. Environment Variables
  6. 🧪 Development
    1. 📚 Further Reading
      1. 📋 Future Improvements
        1. 📄 License

          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
          • A
            security
            F
            license
            A
            quality
            A Model Context Protocol (MCP) server that optimizes token usage by caching data during language model interactions, compatible with any language model and MCP client.
            Last updated -
            4
            JavaScript
          • -
            security
            A
            license
            -
            quality
            An MCP server implementation that standardizes how AI applications access tools and context, providing a central hub that manages tool discovery, execution, and context management with a simplified configuration system.
            Last updated -
            9
            Python
            MIT License
          • -
            security
            -
            license
            -
            quality
            An MCP server implementation that allows using Google's Gemini AI models (specifically Gemini 1.5 Pro) through Claude or other MCP clients via the Model Context Protocol.
            Last updated -
            1
            JavaScript

          View all related MCP servers

          ID: 0pj55vyt1r