Last active
September 19, 2025 03:59
-
-
Save lance0/3a855cdacb9168eaef214ce879b3b5d3 to your computer and use it in GitHub Desktop.
Using Gemini as an MCP Server Sub-Agent for Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Using Gemini and Context7 as MCP Server Sub-Agents for Claude Code | |
| Overview | |
| This guide explains how to integrate Google's Gemini AI models and Context7 (by Upstash) as sub-agents for Claude Code using the Model Context Protocol (MCP). Gemini provides deep code analysis and large context processing, while Context7 fetches version-specific documentation to ensure accuracy and reduce hallucinations. Claude Code orchestrates the workflow, delegating tasks to Gemini for analysis and Context7 for documentation. | |
| Why Use Gemini and Context7? | |
| Gemini Strengths: | |
| Large context window for analyzing extensive codebases or documentation. | |
| Complements Claude’s conversational and editing capabilities. | |
| Cost-effective via Gemini CLI’s free/low-cost plans. | |
| Ideal for deep code review, debugging, and brainstorming. | |
| Context7 Strengths: | |
| Fetches up-to-date, version-specific documentation for libraries like Next.js, React, or redis-py. | |
| Reduces LLM hallucinations by providing accurate code snippets. | |
| Supports fast-moving libraries with real-time documentation. | |
| Free tier with up to 50 queries per day. | |
| Combined Benefits: | |
| Claude manages workflows, Gemini handles complex analysis, and Context7 ensures documentation accuracy. | |
| Enhances code quality, debugging, and productivity with minimal token usage. | |
| How It Works | |
| Claude Code communicates with MCP servers running Gemini’s API/CLI and Context7. When Claude encounters a task, it delegates to Gemini for analysis (e.g., code review) and Context7 for documentation (e.g., latest API references). Results are integrated into Claude’s workflow for refinement or action. | |
| Instructions | |
| Step 1: Obtain a Gemini API Key | |
| Sign up for Google Cloud and generate an API key via AI Studio or Cloud Console for Gemini models (e.g., Gemini 2.5 Pro/Flash). | |
| Step 2: Install and Configure the Gemini MCP Server | |
| Choose an MCP Server: | |
| Recommended: RLabs-Inc/gemini-mcp, Garblesnarff/gemini-mcp-server, BeehiveInnovations/zen-mcp-server, or RaiAnsar/claude_code-gemini-mcp. | |
| Alternatively, build a custom server using Python and FastMCP. | |
| Installation (Example with RLabs-Inc/gemini-mcp): | |
| Clone the repository:git clone https://github.com/RLabs-Inc/gemini-mcp.git | |
| cd gemini-mcp | |
| Install dependencies:npm install # For Node.js | |
| # OR | |
| pip install google-generativeai mcp # For Python | |
| Configure with your Gemini API key:export GEMINI_API_KEY="your-gemini-api-key" | |
| Or use a one-line command:claude mcp add gemini -s user --env GEMINI_API_KEY=your-gemini-api-key npx -y https://github.com/RLabs-Inc/gemini-mcp.git | |
| Run the Server: | |
| Node.js:node dist/gemini_mcp_server.js | |
| Python:python gemini_mcp_server.py | |
| Docker (e.g., for Garblesnarff/gemini-mcp-server):docker build -t gemini-mcp-server . | |
| docker run -e GEMINI_API_KEY="your-api-key" -e OUTPUT_DIR="/app/output" -v /path/on/host:/app/output gemini-mcp-server | |
| Verify with logs or MCP Inspector. | |
| Step 3: Install and Configure the Context7 MCP Server | |
| Install Context7: | |
| Use Upstash’s Context7 MCP server via Node.js or Docker:claude mcp add --transport http context7 https://mcp.context7.com/mcp | |
| Or add to claude_desktop_config.json:{ | |
| "mcpServers": { | |
| "context7": { | |
| "command": "npx", | |
| "args": ["-y", "@upstash/context7-mcp@latest"] | |
| } | |
| } | |
| } | |
| For Docker:docker build -t context7-mcp . | |
| docker run -i --rm context7-mcp | |
| Or clone and run locally:git clone https://github.com/upstash/context7-mcp.git | |
| cd context7-mcp | |
| npm install | |
| npx tsx src/index.ts | |
| Verify Installation: | |
| Restart Claude Desktop or your editor. | |
| Check server availability:claude mcp list | |
| Test with:How do I use the Next.js 'after' function? use context7 | |
| Step 4: Configure Claude Code to Use Both Servers | |
| For Claude Desktop: | |
| Restart Claude Desktop after starting both MCP servers. | |
| Add servers manually if not detected, in ~/.claude/mcp.json or .claude/mcp.json:{ | |
| "mcpServers": { | |
| "gemini": { | |
| "command": "node", | |
| "args": ["dist/gemini_mcp_server.js"], | |
| "env": { | |
| "GEMINI_API_KEY": "your_api_key_here" | |
| } | |
| }, | |
| "context7": { | |
| "command": "npx", | |
| "args": ["-y", "@upstash/context7-mcp@latest"] | |
| } | |
| } | |
| } | |
| Or use:claude mcp add-json "gemini" '{"command":"node","args":["dist/gemini_mcp_server.js"],"env":{"GEMINI_API_KEY":"your_api_key_here"}}' | |
| claude mcp add --transport http context7 https://mcp.context7.com/mcp | |
| For Claude Code CLI: | |
| Use claude mcp add commands from Steps 2 and 3. | |
| Verify: | |
| Check servers:claude mcp list | |
| Test Gemini:/gemini-query What is quantum computing? | |
| Test Context7:/context7 What is the latest redis-py connection method? | |
| Step 5: Create Custom Commands (Optional) | |
| Define commands in a CLAUDE.md or GEMINI.md file:# Gemini + Context7 Integration | |
| - `/project:gemini [question]` - Ask Gemini a question | |
| - `/project:analyze [code]` - Analyze code with Gemini and Context7 docs | |
| - `/project:brainstorm [topic]` - Brainstorm with Gemini | |
| - `/project:summarize [text]` - Summarize text with Gemini | |
| - `/project:docs [library]` - Fetch docs with Context7 | |
| Example command setup:echo "/gemini-analyze-code general\n\n\$ARGUMENTS use context7" > .claude/commands/analyze.md | |
| Step 6: Practical Use Cases | |
| Deep Code Review: | |
| Prompt: @gemini Review this FastAPI codebase for performance issues. use context7 | |
| Context7 fetches FastAPI docs, Gemini analyzes the codebase, and Claude integrates results. | |
| Debugging: | |
| Prompt: @gemini Debug this React Query hook failing to invalidate queries. use context7 | |
| Context7 provides React Query docs, Gemini suggests fixes. | |
| Unit Test Generation: | |
| Prompt: @gemini Generate unit tests for this Next.js API route. use context7 | |
| Context7 supplies Next.js docs, Gemini generates tests. | |
| Research/Planning: | |
| Prompt: @gemini Brainstorm a real-time collaboration feature using Upstash Redis. use context7 | |
| Context7 fetches Redis docs, Gemini proposes solutions. | |
| Step 7: Optimize and Debug | |
| Logging: | |
| For Gemini:claude mcp add gemini -s user --env GEMINI_API_KEY=your-gemini-api-key VERBOSE=true npx -y https://github.com/RLabs-Inc/gemini-mcp.git | |
| For Context7, check logs via Docker or Node.js output. | |
| Error Handling: | |
| Gemini: Verify API keys and file paths with MCP Inspector. | |
| Context7: Ensure correct library IDs (e.g., /nuxt/ui) and Node.js ≥18.0.0. | |
| Token Optimization: | |
| Use Gemini for large context tasks and Context7 for concise docs to save Claude’s tokens. Clear context with /clear. | |
| Example Workflow | |
| Task: Optimize a Python function using redis-py. | |
| Prompt:@gemini Optimize this Python function for Redis operations. use context7 | |
| Context7: Fetches latest redis-py documentation. | |
| Gemini: Analyzes function and suggests optimizations. | |
| Claude: Applies changes or seeks approval. | |
| Outcome: Optimized, version-accurate Redis code. | |
| Limitations | |
| Setup Complexity: Configuring multiple MCP servers may require debugging. | |
| Gemini: | |
| CLI rate limits on free plans. | |
| Security: Use trusted MCP server sources. | |
| Context7: | |
| Limited to supported libraries (submit PRs to https://github.com/upstash/context7-mcp for new ones). | |
| 50-query daily limit on free tier. | |
| General: Claude may require a subscription; compare costs. | |
| Advanced Tips | |
| Multi-Model: Use zen-mcp-server to combine Gemini, Context7, and other models. | |
| Context Files: Create GEMINI.md or CONTEXT7.md for project-specific instructions. | |
| Sub-Agent Tasks: Spawn Gemini/Context7 sub-agents for parallel tasks via Claude’s Task tool. | |
| Prompt Engineering: Use specific prompts, e.g., “Analyze codebase for systemic bugs” or “Fetch latest FastAPI docs.” | |
| Conclusion | |
| Integrating Gemini and Context7 as MCP server sub-agents enhances Claude Code’s capabilities. Gemini provides deep analysis, Context7 ensures accurate documentation, and Claude orchestrates the workflow. Explore https://github.com/RLabs-Inc/gemini-mcp and https://context7.com/ for more details. For feedback on Context7, contact [email protected]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment