Gemini Context MCP 服务器
一个强大的 MCP(模型上下文协议)服务器实现,充分利用了 Gemini 的上下文管理和缓存功能。该服务器最大限度地发挥了 Gemini 2M 令牌上下文窗口的价值,同时提供了高效缓存大型上下文的工具。
🚀 功能
上下文管理
- 高达 2M 令牌上下文窗口支持- 利用 Gemini 的广泛上下文功能
- 基于会话的对话- 在多个交互中保持对话状态
- 智能上下文跟踪- 使用元数据添加、检索和搜索上下文
- 语义搜索——利用语义相似性查找相关上下文
- 自动上下文清理- 会话和上下文自动过期
API缓存
- 大型提示缓存- 高效重用大型系统提示和指令
- 成本优化——降低常用上下文的令牌使用成本
- TTL 管理- 控制缓存过期时间
- 自动清理- 自动删除过期的缓存
🏁 快速入门
先决条件
- 已安装 Node.js 18+
- Gemini API 密钥(在此获取)
安装
基本用法
MCP 客户端集成
该 MCP 服务器可以与各种兼容 MCP 的客户端集成:
- Claude 桌面- 在 Claude 设置中添加为 MCP 服务器
- Cursor - 在 Cursor 的 AI/MCP 设置中配置
- VS Code - 与 MCP 兼容的扩展一起使用
有关每个客户端的详细集成说明,请参阅 MCP 文档中的MCP 客户端配置指南。
快速客户端设置
使用我们简化的客户端安装命令:
每个命令都会设置适当的配置文件并提供完成集成的说明。
💻 使用示例
对于初学者
直接使用服务器:
- 启动服务器:
- 使用提供的测试脚本进行交互:
在您的 Node.js 应用程序中使用:
对于高级用户
使用自定义配置:
使用缓存系统进行成本优化:
🔌 与 MCP 工具(如 Cursor)一起使用
该服务器实现了模型上下文协议 (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
- 更新缓存 TTLmcp_gemini_context_delete_cache
- 删除缓存
使用光标连接
与Cursor一起使用时,您可以通过 MCP 配置进行连接:
有关 MCP 工具的详细使用说明,请参阅README-MCP.md 。
⚙️ 配置选项
环境变量
使用以下选项创建.env
文件:
🧪 开发
📚 进一步阅读
- 有关 MCP 的具体用法,请参阅README-MCP.md
- 探索mcp-manifest.json中的清单以了解可用的工具
- 检查存储库中的示例脚本以了解使用模式
📋 未来的改进
- 上下文和缓存的数据库持久性
- 缓存大小管理和驱逐策略
- 基于向量的语义搜索
- 分析和指标跟踪
- 与向量存储集成
- 上下文管理的批量操作
- 混合缓存策略
- 自动提示优化
📄 许可证
麻省理工学院
This server cannot be installed
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.
MCP 服务器实现最大化 Gemini 的 2M 令牌上下文窗口,并带有跨多个 AI 客户端应用程序进行高效上下文管理和缓存的工具。
Related MCP Servers
- -securityAlicense-qualityThe 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 -17TypeScriptMIT License
- AsecurityAlicenseAqualityA 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 -1630TypeScriptMIT License
- -securityAlicense-qualityA 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 -1JavaScriptMIT License
- AsecurityFlicenseAqualityA 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 -42,194749TypeScript