mcp-gemini-assistant
Enables Claude Code to consult Gemini for complex coding problems with session management, file attachments, and conversation persistence.
README
Gemini Coding Assistant MCP Server
A powerful MCP server that allows Claude Code to consult Gemini for complex coding problems with full code context and conversation persistence.
Note: This server works standalone but is highly recommended to use with the Claude Code Development Kit for enhanced automation and context management.
Key Features
- Session Management: Maintain conversation context across multiple queries
- File Attachments: Read and include actual code files in conversations
- Hybrid Context: Combine text-based
code_contextwith file attachments - Follow-up Questions: Ask follow-up questions without resending code context
- Context Caching: Code context and file content are cached per session
- Automatic Processing: Files are processed and formatted automatically
- Multiple Sessions: Run multiple parallel conversations for different problems
- Session Expiry: Automatic cleanup of inactive sessions after 1 hour
- Latest Model: Uses Gemini 2.5 Pro (stable) by default
Integration with Claude Code Development Kit
While this MCP server works standalone, it is highly recommended and optimized to use with the Claude Code Development Kit.
Enhanced Features with Development Kit
The Development Kit transforms Claude Code into an orchestrated development environment that seamlessly integrates with this Gemini MCP server:
- Automated Context Injection: The
gemini-context-injector.shhook automatically attaches project-specific context files (MCP-ASSISTANT-RULES.md, project-structure.md) to new Gemini sessions - Multi-Agent Orchestration: Complex commands spawn specialized agents that can consult Gemini for architectural decisions and design patterns
- Enhanced System Prompt: The MCP server's system prompt is designed to work with the Development Kit's context injection system
- Security Scanning: The
mcp-security-scan.shhook prevents sensitive data from being sent to external AI services - Seamless Integration: Commands like
/full-contextautomatically leverage Gemini for complex problems
Quick Setup with Development Kit
- Install the Claude Code Development Kit
- Configure this MCP server as described in the installation section below
- The Development Kit's hooks will automatically enhance your Gemini interactions
Purpose
When Claude Code encounters difficult problems or needs a second opinion, it can:
- Send complete code files by reading them from the local filesystem
- Include text-based code context alongside file attachments
- Have multi-turn conversations about the same problem
- Get different perspectives without repeating context
- Work on multiple problems in parallel sessions
- Process files locally and include content in conversations
Installation
- Clone this repository
- Create a Python virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate - Install dependencies:
pip install -r requirements.txt - Copy
.env.exampleto.envand add your Gemini API key:cp .env.example .env # Edit .env file and set your GEMINI_API_KEY - Add to Claude Code:
Replaceclaude mcp add gemini-coding -s user -- /path/to/gemini-mcp/start_server.sh/path/to/gemini-mcp/with the actual path to this directory.
Tools Available
1. consult_gemini
Start or continue a conversation with Gemini about complex coding problems.
Parameters:
session_id(optional): Continue a previous conversationproblem_description: Description of the problem (required for new sessions)code_context: All relevant code (required for new sessions, cached afterward)attached_files(optional): Array of file paths to read and include in the conversationfile_descriptions(optional): Object mapping file paths to descriptionsspecific_question: The question you want answeredadditional_context(optional): Updates or changes since last questionpreferred_approach: Type of help needed (solution/review/debug/optimize/explain/follow-up)
2. list_sessions
List all active Gemini consultation sessions.
3. end_session
End a specific session to free up memory.
Usage Examples
Starting a New Conversation (with text code)
/consult_gemini
problem_description: "I need to implement efficient caching for a React application"
code_context: "[paste entire relevant codebase]"
specific_question: "What's the best approach for implementing LRU cache with React Query?"
preferred_approach: "solution"
Starting a New Conversation (with file attachments)
/consult_gemini
problem_description: "I need to optimize this React component for performance"
attached_files: ["/absolute/path/to/src/components/Dashboard.jsx", "/absolute/path/to/src/hooks/useData.js", "/absolute/path/to/package.json"]
file_descriptions: {
"/absolute/path/to/src/components/Dashboard.jsx": "Main dashboard component with performance issues",
"/absolute/path/to/src/hooks/useData.js": "Custom hook for data fetching",
"/absolute/path/to/package.json": "Project dependencies"
}
specific_question: "How can I improve the rendering performance of this dashboard?"
preferred_approach: "optimize"
Combining Both Approaches
/consult_gemini
problem_description: "Complex authentication flow needs debugging"
code_context: "// Additional context or pseudocode here"
attached_files: ["/absolute/path/to/auth/login.js", "/absolute/path/to/middleware/auth.js"]
specific_question: "Why is the token refresh failing?"
preferred_approach: "debug"
Response includes a session ID for follow-ups.
Follow-up Question
/consult_gemini
session_id: "abc123..."
specific_question: "I implemented your suggestion but getting stale data issues. How do I handle cache invalidation?"
additional_context: "Added the LRU cache as suggested, but users see old data after updates"
preferred_approach: "follow-up"
Managing Sessions
/list_sessions
# Shows all active sessions with IDs and summaries
/end_session
session_id: "abc123..."
# Frees up memory for completed conversations
Best Practices
- Initial Context: Include ALL relevant code via
code_contextorattached_files - File Organization: Use
attached_filesfor multiple files,code_contextfor snippets - File Descriptions: Provide clear descriptions for each attached file
- Follow-ups: Use the session ID to continue conversations
- Additional Context: When asking follow-ups, explain what changed
- Session Management: End sessions when done to free memory and clean up files
- Multiple Problems: Use different sessions for unrelated problems
- File Types: Supports JavaScript, Python, TypeScript, JSON, and other text-based files
Testing the Server
You can test the server directly before adding it to Claude Code:
# Make sure your .env file has a valid GEMINI_API_KEY
./start_server.sh
The server will start and display:
Gemini Coding Assistant MCP Server v3.0 running (Python)
Features: Session management, file attachments, context persistence, follow-up questions
Ready to help with complex coding problems!
Context Limits
- Maximum combined input: ~50,000 characters per message
- Maximum response: 8,192 tokens (~16,000 characters)
- Session timeout: 1 hour of inactivity
- Rate limiting: 1 second between requests
How It Works
- First Message: Creates a new session, caches code context
- Follow-ups: Reuses cached context, maintains conversation history
- Session Storage: In-memory storage (use Redis for production)
- Cleanup: Automatic expiry after 1 hour of inactivity
Advantages Over Stateless Design
- Efficiency: Code context sent only once per session
- Context: Gemini remembers previous questions and answers
- Natural Flow: Have real conversations about complex problems
- Cost Savings: Reduced token usage for follow-up questions
Security
- API key is never exposed
- Rate limiting prevents abuse
- Sessions expire automatically
- No persistent storage of code
- When used with Claude Code Development Kit, additional security scanning prevents sensitive data leakage
Version History
- v3.0.0: Enhanced system prompt for Claude Code Development Kit integration
- v2.1.0: Added file attachment system with automatic cleanup
- v2.0.0: Added session management and follow-up support
- v1.0.0: Initial stateless implementation
Connect
Feel free to connect with me on LinkedIn if you have questions, need clarification, or wish to provide feedback.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。