feat: add web search capability to all tools for enhanced analysis
- Add use_websearch parameter to base ToolRequest class - All tools now inherit web search capability automatically - Enhanced description emphasizes brainstorming and architectural design - Add get_websearch_instruction() helper method to base class - Update all tools to include web search in their prompts when enabled - Update README documentation with web search examples - Fix linting issues (ruff, black formatting) Web search is particularly useful for: - Brainstorming sessions and architectural design discussions - Exploring industry best practices - Working with specific frameworks/technologies - Researching solutions to complex problems - Getting current documentation and community insights 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
46
README.md
46
README.md
@@ -295,11 +295,30 @@ Completely quit and restart Claude Desktop for the changes to take effect.
|
||||
|
||||
### 5. Connect to Claude Code
|
||||
|
||||
To use the server in Claude Code, run:
|
||||
#### If you have Claude Desktop installed:
|
||||
```bash
|
||||
claude mcp add-from-claude-desktop -s user
|
||||
```
|
||||
|
||||
#### If you only have Claude Code (no desktop app):
|
||||
|
||||
**For Traditional Setup (macOS/Linux):**
|
||||
```bash
|
||||
claude mcp add gemini -s user -e GEMINI_API_KEY=your-gemini-api-key-here -- /path/to/gemini-mcp-server/run_gemini.sh
|
||||
```
|
||||
|
||||
**For Traditional Setup (Windows):**
|
||||
```bash
|
||||
claude mcp add gemini -s user -e GEMINI_API_KEY=your-gemini-api-key-here -- C:\path\to\gemini-mcp-server\run_gemini.bat
|
||||
```
|
||||
|
||||
**For Docker Setup:**
|
||||
```bash
|
||||
claude mcp add gemini -s user -- docker run --rm -i --env-file /path/to/gemini-mcp-server/.env -v /home:/workspace:ro gemini-mcp-server:latest
|
||||
```
|
||||
|
||||
Replace `/path/to/gemini-mcp-server` with the actual path where you cloned the repository.
|
||||
|
||||
### 6. Start Using It!
|
||||
|
||||
Just ask Claude naturally:
|
||||
@@ -486,6 +505,7 @@ Combine both perspectives to create a comprehensive caching implementation guide
|
||||
- Architecture and design discussions
|
||||
- Can reference files for context: `"Use gemini to explain this algorithm with context from algorithm.py"`
|
||||
- **Dynamic collaboration**: Gemini can request additional files or context during the conversation if needed for a more thorough response
|
||||
- **Web search capability**: Can search for current documentation, examples, and community solutions when exploring new technologies
|
||||
|
||||
**Triggers:** ask, explain, compare, suggest, what about, brainstorm, discuss, share my thinking, get opinion
|
||||
|
||||
@@ -503,6 +523,12 @@ Combine both perspectives to create a comprehensive caching implementation guide
|
||||
"Use gemini to extend my analysis of this distributed system architecture"
|
||||
```
|
||||
|
||||
**With Web Search (for exploring new technologies):**
|
||||
```
|
||||
"Use gemini to think deeper about using HTMX vs React for this project - enable web search to explore current best practices"
|
||||
"Get gemini to think deeper about implementing WebAuthn authentication with web search enabled for latest standards"
|
||||
```
|
||||
|
||||
**Managing Token Costs:**
|
||||
```
|
||||
# Claude will intelligently select the right mode, but you can override:
|
||||
@@ -534,6 +560,7 @@ about event ordering and failure scenarios. Then integrate gemini's insights and
|
||||
- Validates architectural decisions and design patterns
|
||||
- Can reference specific files for context: `"Use gemini to think deeper about my API design with reference to api/routes.py"`
|
||||
- **Enhanced Critical Evaluation (v2.10.0)**: After Gemini's analysis, Claude is prompted to critically evaluate the suggestions, consider context and constraints, identify risks, and synthesize a final recommendation - ensuring a balanced, well-considered solution
|
||||
- **Web search capability**: When enabled with `use_websearch`, can research current documentation, similar issues, and best practices to inform deeper analysis
|
||||
|
||||
**Triggers:** think deeper, ultrathink, extend my analysis, validate my approach
|
||||
|
||||
@@ -652,6 +679,12 @@ implementations or missing test coverage. Update the code based on gemini's find
|
||||
"Get gemini to debug why my API returns 500 errors with the full stack trace: [paste traceback]"
|
||||
```
|
||||
|
||||
**With Web Search (for unfamiliar errors):**
|
||||
```
|
||||
"Use gemini to debug this cryptic Kubernetes error with web search enabled to find similar issues"
|
||||
"Debug this React hydration error with gemini - enable web search to check for known solutions"
|
||||
```
|
||||
|
||||
**Managing Token Costs:**
|
||||
```
|
||||
# Save tokens for simple errors
|
||||
@@ -684,6 +717,7 @@ suggest preventive measures."
|
||||
- Supports runtime info and previous attempts
|
||||
- Provides structured root cause analysis with validation steps
|
||||
- Can request additional context when needed for thorough analysis
|
||||
- **Web search capability**: When enabled with `use_websearch`, can search for exact error messages, known issues, workarounds, and version-specific problems
|
||||
|
||||
**Triggers:** debug, error, failing, root cause, trace, not working
|
||||
|
||||
@@ -700,6 +734,12 @@ suggest preventive measures."
|
||||
"Get gemini to do an architecture analysis of the src/ directory"
|
||||
```
|
||||
|
||||
**With Web Search (for unfamiliar code):**
|
||||
```
|
||||
"Use gemini to analyze this GraphQL schema with web search enabled to understand best practices"
|
||||
"Analyze this Rust code with gemini - enable web search to look up unfamiliar patterns and idioms"
|
||||
```
|
||||
|
||||
**Managing Token Costs:**
|
||||
```
|
||||
# Save tokens for quick overviews
|
||||
@@ -729,6 +769,7 @@ Combine your findings with gemini's to create a comprehensive security report."
|
||||
- Supports specialized analysis types: architecture, performance, security, quality
|
||||
- Uses file paths (not content) for clean terminal output
|
||||
- Can identify patterns, anti-patterns, and refactoring opportunities
|
||||
- **Web search capability**: When enabled with `use_websearch`, can look up framework documentation, design patterns, and best practices relevant to the code being analyzed
|
||||
|
||||
**Triggers:** analyze, examine, look at, understand, inspect
|
||||
|
||||
@@ -750,6 +791,7 @@ All tools that work with files support **both individual files and entire direct
|
||||
- `analysis_type`: architecture|performance|security|quality|general
|
||||
- `output_format`: summary|detailed|actionable
|
||||
- `thinking_mode`: minimal|low|medium|high|max (default: medium)
|
||||
- `use_websearch`: Enable web search for documentation and best practices (default: false)
|
||||
|
||||
```
|
||||
"Use gemini to analyze the src/ directory for architectural patterns"
|
||||
@@ -776,6 +818,7 @@ All tools that work with files support **both individual files and entire direct
|
||||
- `runtime_info`: Environment details
|
||||
- `previous_attempts`: What you've tried
|
||||
- `thinking_mode`: minimal|low|medium|high|max (default: medium)
|
||||
- `use_websearch`: Enable web search for error messages and solutions (default: false)
|
||||
|
||||
```
|
||||
"Use gemini to debug this error with context from the entire backend/ directory"
|
||||
@@ -787,6 +830,7 @@ All tools that work with files support **both individual files and entire direct
|
||||
- `focus_areas`: Specific aspects to focus on
|
||||
- `files`: Files or directories for context
|
||||
- `thinking_mode`: minimal|low|medium|high|max (default: max)
|
||||
- `use_websearch`: Enable web search for documentation and insights (default: false)
|
||||
|
||||
```
|
||||
"Use gemini to think deeper about my design with reference to the src/models/ directory"
|
||||
|
||||
@@ -10,7 +10,7 @@ Configuration values can be overridden by environment variables where appropriat
|
||||
|
||||
# Version and metadata
|
||||
# These values are used in server responses and for tracking releases
|
||||
__version__ = "2.11.0" # Semantic versioning: MAJOR.MINOR.PATCH
|
||||
__version__ = "2.11.1" # Semantic versioning: MAJOR.MINOR.PATCH
|
||||
__updated__ = "2025-06-10" # Last update date in ISO format
|
||||
__author__ = "Fahad Gilani" # Primary maintainer
|
||||
|
||||
|
||||
2
setup.py
2
setup.py
@@ -14,7 +14,7 @@ if readme_path.exists():
|
||||
|
||||
setup(
|
||||
name="gemini-mcp-server",
|
||||
version="2.8.0",
|
||||
version="2.11.1",
|
||||
description="Model Context Protocol server for Google Gemini",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
@@ -84,6 +84,11 @@ class AnalyzeTool(BaseTool):
|
||||
"enum": ["minimal", "low", "medium", "high", "max"],
|
||||
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
|
||||
},
|
||||
"use_websearch": {
|
||||
"type": "boolean",
|
||||
"description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
"default": False,
|
||||
},
|
||||
},
|
||||
"required": ["files", "question"],
|
||||
}
|
||||
@@ -150,10 +155,20 @@ class AnalyzeTool(BaseTool):
|
||||
|
||||
focus_instruction = "\n".join(analysis_focus) if analysis_focus else ""
|
||||
|
||||
# Add web search instruction if enabled
|
||||
websearch_instruction = self.get_websearch_instruction(
|
||||
request.use_websearch,
|
||||
"""Specifically search for:
|
||||
- Documentation for technologies or frameworks found in the code
|
||||
- Best practices and design patterns relevant to the analysis
|
||||
- API references and usage examples
|
||||
- Known issues or solutions for patterns you identify""",
|
||||
)
|
||||
|
||||
# Combine everything
|
||||
full_prompt = f"""{self.get_system_prompt()}
|
||||
|
||||
{focus_instruction}
|
||||
{focus_instruction}{websearch_instruction}
|
||||
|
||||
=== USER QUESTION ===
|
||||
{request.question}
|
||||
|
||||
@@ -46,6 +46,10 @@ class ToolRequest(BaseModel):
|
||||
None,
|
||||
description="Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
|
||||
)
|
||||
use_websearch: Optional[bool] = Field(
|
||||
False,
|
||||
description="Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
)
|
||||
|
||||
|
||||
class BaseTool(ABC):
|
||||
@@ -145,6 +149,35 @@ class BaseTool(ABC):
|
||||
"""
|
||||
return "medium" # Default to medium thinking for better reasoning
|
||||
|
||||
def get_websearch_instruction(self, use_websearch: bool, tool_specific: Optional[str] = None) -> str:
|
||||
"""
|
||||
Generate web search instruction based on the use_websearch parameter.
|
||||
|
||||
Args:
|
||||
use_websearch: Whether web search is enabled
|
||||
tool_specific: Optional tool-specific search guidance
|
||||
|
||||
Returns:
|
||||
str: Web search instruction to append to prompt, or empty string
|
||||
"""
|
||||
if not use_websearch:
|
||||
return ""
|
||||
|
||||
base_instruction = """
|
||||
|
||||
WEB SEARCH ENABLED: Feel free to perform appropriate web searches to enhance your analysis."""
|
||||
|
||||
if tool_specific:
|
||||
return f"{base_instruction} {tool_specific}"
|
||||
|
||||
# Default instruction for all tools
|
||||
return f"""{base_instruction} Search for:
|
||||
- Current documentation and best practices
|
||||
- Similar issues and community solutions
|
||||
- API references and usage examples
|
||||
- Recent developments and updates
|
||||
Consider relevant findings when formulating your response."""
|
||||
|
||||
@abstractmethod
|
||||
def get_request_model(self):
|
||||
"""
|
||||
|
||||
@@ -68,6 +68,11 @@ class ChatTool(BaseTool):
|
||||
"enum": ["minimal", "low", "medium", "high", "max"],
|
||||
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
|
||||
},
|
||||
"use_websearch": {
|
||||
"type": "boolean",
|
||||
"description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
"default": False,
|
||||
},
|
||||
},
|
||||
"required": ["prompt"],
|
||||
}
|
||||
@@ -115,8 +120,18 @@ class ChatTool(BaseTool):
|
||||
# Check token limits
|
||||
self._validate_token_limit(user_content, "Content")
|
||||
|
||||
# Add web search instruction if enabled
|
||||
websearch_instruction = self.get_websearch_instruction(
|
||||
request.use_websearch,
|
||||
"""Specifically search for:
|
||||
- Documentation for any technologies or concepts mentioned
|
||||
- Current best practices and patterns
|
||||
- Recent developments or updates
|
||||
- Community discussions and solutions""",
|
||||
)
|
||||
|
||||
# Combine system prompt with user content
|
||||
full_prompt = f"""{self.get_system_prompt()}
|
||||
full_prompt = f"""{self.get_system_prompt()}{websearch_instruction}
|
||||
|
||||
=== USER REQUEST ===
|
||||
{user_content}
|
||||
|
||||
@@ -82,6 +82,11 @@ class DebugIssueTool(BaseTool):
|
||||
"enum": ["minimal", "low", "medium", "high", "max"],
|
||||
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
|
||||
},
|
||||
"use_websearch": {
|
||||
"type": "boolean",
|
||||
"description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
"default": False,
|
||||
},
|
||||
},
|
||||
"required": ["error_description"],
|
||||
}
|
||||
@@ -154,8 +159,19 @@ class DebugIssueTool(BaseTool):
|
||||
# Check token limits
|
||||
self._validate_token_limit(full_context, "Context")
|
||||
|
||||
# Add web search instruction if enabled
|
||||
websearch_instruction = self.get_websearch_instruction(
|
||||
request.use_websearch,
|
||||
"""Specifically search for:
|
||||
- The exact error message to find known solutions
|
||||
- Framework-specific error codes and their meanings
|
||||
- Similar issues in forums, GitHub issues, or Stack Overflow
|
||||
- Workarounds and patches for known bugs
|
||||
- Version-specific issues and compatibility problems""",
|
||||
)
|
||||
|
||||
# Combine everything
|
||||
full_prompt = f"""{self.get_system_prompt()}
|
||||
full_prompt = f"""{self.get_system_prompt()}{websearch_instruction}
|
||||
|
||||
{full_context}
|
||||
|
||||
|
||||
@@ -92,7 +92,15 @@ class ReviewChanges(BaseTool):
|
||||
)
|
||||
|
||||
def get_input_schema(self) -> dict[str, Any]:
|
||||
return self.get_request_model().model_json_schema()
|
||||
schema = self.get_request_model().model_json_schema()
|
||||
# Ensure use_websearch is in the schema with proper description
|
||||
if "properties" in schema and "use_websearch" not in schema["properties"]:
|
||||
schema["properties"]["use_websearch"] = {
|
||||
"type": "boolean",
|
||||
"description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
"default": False,
|
||||
}
|
||||
return schema
|
||||
|
||||
def get_system_prompt(self) -> str:
|
||||
return REVIEW_CHANGES_PROMPT
|
||||
@@ -369,6 +377,17 @@ class ReviewChanges(BaseTool):
|
||||
)
|
||||
prompt_parts.extend(context_files_content)
|
||||
|
||||
# Add web search instruction if enabled
|
||||
websearch_instruction = self.get_websearch_instruction(
|
||||
request.use_websearch,
|
||||
"""Specifically search for:
|
||||
- Best practices for new features or patterns introduced
|
||||
- Security implications of the changes
|
||||
- Known issues with libraries or APIs being used
|
||||
- Migration guides if updating dependencies
|
||||
- Performance considerations for the implemented approach""",
|
||||
)
|
||||
|
||||
# Add review instructions
|
||||
prompt_parts.append("\n## Review Instructions\n")
|
||||
prompt_parts.append(
|
||||
@@ -385,7 +404,10 @@ class ReviewChanges(BaseTool):
|
||||
"you may request them using the standardized JSON response format."
|
||||
)
|
||||
|
||||
return "\n".join(prompt_parts)
|
||||
# Combine with system prompt and websearch instruction
|
||||
full_prompt = f"{self.get_system_prompt()}{websearch_instruction}\n\n" + "\n".join(prompt_parts)
|
||||
|
||||
return full_prompt
|
||||
|
||||
def format_response(self, response: str, request: ReviewChangesRequest) -> str:
|
||||
"""Format the response with commit guidance"""
|
||||
|
||||
@@ -122,6 +122,11 @@ class ReviewCodeTool(BaseTool):
|
||||
"enum": ["minimal", "low", "medium", "high", "max"],
|
||||
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
|
||||
},
|
||||
"use_websearch": {
|
||||
"type": "boolean",
|
||||
"description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
"default": False,
|
||||
},
|
||||
},
|
||||
"required": ["files", "context"],
|
||||
}
|
||||
@@ -206,8 +211,19 @@ class ReviewCodeTool(BaseTool):
|
||||
|
||||
focus_instruction = "\n".join(review_focus) if review_focus else ""
|
||||
|
||||
# Add web search instruction if enabled
|
||||
websearch_instruction = self.get_websearch_instruction(
|
||||
request.use_websearch,
|
||||
"""Specifically search for:
|
||||
- Security vulnerabilities and CVEs for libraries/frameworks used
|
||||
- Best practices for the languages and frameworks in the code
|
||||
- Common anti-patterns and their solutions
|
||||
- Performance optimization techniques
|
||||
- Recent updates or deprecations in APIs used""",
|
||||
)
|
||||
|
||||
# Construct the complete prompt with system instructions and code
|
||||
full_prompt = f"""{self.get_system_prompt()}
|
||||
full_prompt = f"""{self.get_system_prompt()}{websearch_instruction}
|
||||
|
||||
=== USER CONTEXT ===
|
||||
{request.context}
|
||||
|
||||
@@ -83,6 +83,11 @@ class ThinkDeeperTool(BaseTool):
|
||||
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
|
||||
"default": "high",
|
||||
},
|
||||
"use_websearch": {
|
||||
"type": "boolean",
|
||||
"description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.",
|
||||
"default": False,
|
||||
},
|
||||
},
|
||||
"required": ["current_analysis"],
|
||||
}
|
||||
@@ -148,8 +153,18 @@ class ThinkDeeperTool(BaseTool):
|
||||
areas = ", ".join(request.focus_areas)
|
||||
focus_instruction = f"\n\nFOCUS AREAS: Please pay special attention to {areas} aspects."
|
||||
|
||||
# Add web search instruction if enabled
|
||||
websearch_instruction = self.get_websearch_instruction(
|
||||
request.use_websearch,
|
||||
"""Specifically search for:
|
||||
- Current documentation for technologies, frameworks, or APIs being discussed
|
||||
- Similar issues and their solutions from the community
|
||||
- Best practices and recent developments
|
||||
- Official sources to verify information""",
|
||||
)
|
||||
|
||||
# Combine system prompt with context
|
||||
full_prompt = f"""{self.get_system_prompt()}{focus_instruction}
|
||||
full_prompt = f"""{self.get_system_prompt()}{focus_instruction}{websearch_instruction}
|
||||
|
||||
{full_context}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ def find_git_repositories(start_path: str, max_depth: int = 5) -> list[str]:
|
||||
List of absolute paths to git repositories, sorted alphabetically
|
||||
"""
|
||||
repositories = []
|
||||
|
||||
|
||||
try:
|
||||
# Create Path object - no need to resolve yet since the path might be
|
||||
# a translated Docker path that doesn't exist on the host
|
||||
@@ -61,12 +61,12 @@ def find_git_repositories(start_path: str, max_depth: int = 5) -> list[str]:
|
||||
# Basic validation - must be absolute
|
||||
if not start_path.is_absolute():
|
||||
return []
|
||||
|
||||
|
||||
# Check if the path exists before trying to walk it
|
||||
if not start_path.exists():
|
||||
return []
|
||||
|
||||
except Exception as e:
|
||||
|
||||
except Exception:
|
||||
# If there's any issue with the path, return empty list
|
||||
return []
|
||||
|
||||
@@ -122,7 +122,7 @@ def run_git_command(repo_path: str, command: list[str]) -> tuple[bool, str]:
|
||||
# Verify the repository path exists before trying to use it
|
||||
if not Path(repo_path).exists():
|
||||
return False, f"Repository path does not exist: {repo_path}"
|
||||
|
||||
|
||||
try:
|
||||
# Execute git command with safety measures
|
||||
result = subprocess.run(
|
||||
|
||||
Reference in New Issue
Block a user