Gemini Context MCP Server
Gemini コンテキスト MCP サーバー
Geminiのコンテキスト管理とキャッシュ機能を活用する強力なMCP(Model Context Protocol)サーバー実装。このサーバーは、Geminiの2Mトークンコンテキストウィンドウの価値を最大限に高めるとともに、大規模なコンテキストを効率的にキャッシュするためのツールを提供します。
🚀 機能
コンテキスト管理
最大200万トークンのコンテキストウィンドウをサポート- Geminiの広範なコンテキスト機能を活用
セッションベースの会話- 複数のインタラクションにわたって会話状態を維持する
スマートなコンテキスト追跡- メタデータを使用してコンテキストを追加、取得、検索します
セマンティック検索- 意味的類似性を使用して関連するコンテキストを見つける
自動コンテキストクリーンアップ- セッションとコンテキストは自動的に期限切れになります
APIキャッシュ
大規模なプロンプトのキャッシュ- 大規模なシステムプロンプトと指示を効率的に再利用します
コスト最適化- 頻繁に使用されるコンテキストのトークン使用コストを削減
TTL管理- キャッシュの有効期限を制御する
自動クリーンアップ- 期限切れのキャッシュは自動的に削除されます
Related MCP server: Simple Memory Extension MCP Server
🏁 クイックスタート
前提条件
Node.js 18以上がインストールされている
Gemini API キー (こちらから取得)
インストール
# 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.jsMCPクライアント統合
この 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各コマンドは適切な構成ファイルを設定し、統合を完了するための手順を提供します。
💻 使用例
初心者向け
サーバーを直接使用する:
サーバーを起動します。
node dist/mcp-server.js提供されているテスト スクリプトを使用して対話します。
# 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ツール
コンテキスト管理ツール:
generate_text- コンテキスト付きテキストを生成するget_context- セッションの現在のコンテキストを取得するclear_context- セッションコンテキストをクリアするadd_context- 特定のコンテキストエントリを追加するsearch_context- 意味的に関連コンテキストを検索する
キャッシュツール:
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のマニフェストを調べてください。
リポジトリ内のサンプルスクリプトの使用パターンを確認する
📋 今後の改善点
コンテキストとキャッシュのデータベース永続性
キャッシュサイズの管理と削除ポリシー
ベクトルベースのセマンティック検索
分析と指標の追跡
ベクターストアとの統合
コンテキスト管理のためのバッチ操作
ハイブリッドキャッシュ戦略
自動プロンプト最適化
📄 ライセンス
マサチューセッツ工科大学
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Cloud-hosted MCP server for durable AI memory
AI memory governance & hallucination-blocking MCP server with verifiable knowledge cells.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
An MCP server that provides agents access to the KeldynAI platform
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol (MCP) server that optimizes token usage by caching data during language model interactions, compatible with any language model and MCP client.42ISC
- AlicenseNot gradedqualityBmaintenanceAn MCP server that extends AI agents' context window by providing tools to store, retrieve, and search memories, allowing agents to maintain history and context across long interactions.1MIT
- AlicenseBqualityDmaintenanceA lightweight MCP server that enables AI agents to perform deep codebase analysis by leveraging Gemini's massive context window for cross-file analysis and intelligent file selection.428MIT
- AlicenseBqualityAmaintenanceProduction-ready MCP server with session memory, Brave Search, Vertex AI Discovery Engine, Google Gemini analysis, and sandboxed code-mode transforms.43786 npm156Apache 2.0