Query Gemini with Google Search grounding
Query Gemini with real-time web search and automatic citations for up-to-date, verifiable answers. Use when you need current information beyond the model's training data or want to reduce hallucinations with grounded responses.
/plugin marketplace add dnvriend/gemini-google-search-tool/plugin install gemini-google-search-tool@gemini-google-search-toolThis skill inherits all available tools. When active, it can use any tool Claude has access to.
The gemini-google-search-tool is a Python CLI tool and library that connects Gemini AI models to real-time web content through Google Search grounding. It automatically determines when a search would improve answers, executes appropriate queries, and returns grounded responses with verifiable sources.
Use this skill when:
Do NOT use this skill for:
A professional CLI-first tool for querying Gemini with Google Search grounding, providing real-time web content with automatic citations.
# Install from source
git clone https://github.com/dnvriend/gemini-google-search-tool.git
cd gemini-google-search-tool
uv tool install .
# Verify installation
gemini-google-search-tool --version
GEMINI_API_KEY environment variable# Set API key
export GEMINI_API_KEY='your-api-key-here'
# Basic query
gemini-google-search-tool query "Who won euro 2024?"
# With inline citations
gemini-google-search-tool query "Latest AI news" --add-citations
# Using pro model
gemini-google-search-tool query "Complex analysis" --pro
Query Gemini models with automatic Google Search grounding for real-time web information.
Usage:
gemini-google-search-tool query "PROMPT" [OPTIONS]
Arguments:
PROMPT: The query prompt (positional, required unless --stdin is used)--stdin / -s: Read prompt from stdin (overrides PROMPT)--add-citations: Add inline citation links to response text--pro: Use gemini-2.5-pro model (default: gemini-2.5-flash)--text / -t: Output markdown format instead of JSON-v/-vv/-vvv: Verbosity levels (INFO/DEBUG/TRACE)Examples:
# Basic query with JSON output
gemini-google-search-tool query "Who won euro 2024?"
# Query with inline citations
gemini-google-search-tool query "Latest AI developments" --add-citations
# Read from stdin
echo "Climate change updates" | gemini-google-search-tool query --stdin
# Markdown output
gemini-google-search-tool query "Quantum computing news" --text
# Pro model with verbose output
gemini-google-search-tool query "Complex analysis" --pro -vv
# Trace mode (shows HTTP requests)
gemini-google-search-tool query "Test" -vvv
Output (JSON):
{
"response_text": "AI-generated response with grounding...",
"citations": [
{"index": 1, "uri": "https://...", "title": "Source Title"},
{"index": 2, "uri": "https://...", "title": "Another Source"}
],
"grounding_metadata": {
"web_search_queries": ["query1", "query2"],
"grounding_chunks": [...],
"grounding_supports": [...]
}
}
Output (Markdown with --text):
AI-generated response with grounding...
## Citations
1. [Source Title](https://...)
2. [Another Source](https://...)
Generate shell completion scripts for bash, zsh, or fish.
Usage:
gemini-google-search-tool completion {bash|zsh|fish}
Arguments:
SHELL: Shell type (bash, zsh, or fish)Examples:
# Generate and install bash completion
eval "$(gemini-google-search-tool completion bash)"
# Generate and install zsh completion
eval "$(gemini-google-search-tool completion zsh)"
# Install fish completion
mkdir -p ~/.config/fish/completions
gemini-google-search-tool completion fish > ~/.config/fish/completions/gemini-google-search-tool.fish
# Persistent installation (add to ~/.bashrc or ~/.zshrc)
echo 'eval "$(gemini-google-search-tool completion bash)"' >> ~/.bashrc
echo 'eval "$(gemini-google-search-tool completion zsh)"' >> ~/.zshrc
Output: Shell-specific completion script to stdout.
</details> <details> <summary><strong>⚙️ Advanced Features (Click to expand)</strong></summary>The tool uses Google Search grounding to connect Gemini to real-time web content:
Benefits:
gemini-2.5-flash (default):
gemini-2.5-pro (--pro flag):
No flag (WARNING):
-v (INFO):
[INFO] Starting query command
[INFO] GeminiClient initialized successfully
[INFO] Querying with model 'gemini-2.5-flash' and Google Search grounding
[INFO] Query completed successfully
-vv (DEBUG):
[DEBUG] Validated prompt: Who won euro 2024?...
[DEBUG] Initializing GeminiClient
[DEBUG] Calling Gemini API: model=gemini-2.5-flash
[DEBUG] Extracted 7 citations
[DEBUG] Web search queries: ['who won euro 2024', 'Euro 2024 winner']
-vvv (TRACE):
[DEBUG] connect_tcp.started host='generativelanguage.googleapis.com' port=443
[DEBUG] start_tls.started ssl_context=<ssl.SSLContext...>
[DEBUG] send_request_headers.started request=<Request [b'POST']>
The tool can also be used as a Python library:
from gemini_google_search_tool import (
GeminiClient,
query_with_grounding,
add_inline_citations,
)
# Initialize client
client = GeminiClient() # Reads GEMINI_API_KEY from environment
# Query with grounding
response = query_with_grounding(
client=client,
prompt="Who won euro 2024?",
model="gemini-2.5-flash",
)
# Access response
print(response.response_text)
print(f"Citations: {len(response.citations)}")
# Add inline citations
if response.grounding_segments:
text_with_citations = add_inline_citations(
response.response_text,
response.grounding_segments,
response.citations,
)
print(text_with_citations)
The tool follows CLI-first design principles for pipeline integration:
JSON to stdout, logs to stderr:
# Parse JSON output
gemini-google-search-tool query "test" | jq '.response_text'
# Filter citations
gemini-google-search-tool query "test" | jq '.citations[]'
# Check exit code
gemini-google-search-tool query "test" && echo "Success"
Stdin support:
# From file
cat question.txt | gemini-google-search-tool query --stdin
# From command output
echo "Who won euro 2024?" | gemini-google-search-tool query --stdin
</details>
<details>
<summary><strong>🔧 Troubleshooting (Click to expand)</strong></summary>
Issue: Missing API Key
Error: GEMINI_API_KEY environment variable is required.
Set it with: export GEMINI_API_KEY='your-api-key'
Solution:
export GEMINI_API_KEY='your-key'echo 'export GEMINI_API_KEY="your-key"' >> ~/.bashrcIssue: Empty or Invalid Response
Error: Query failed: Invalid response format
Solution:
-vv to see detailed errorIssue: Rate Limiting
Error: Query failed: Rate limit exceeded
Solution:
Issue: Module Import Error (Library Usage)
ImportError: No module named 'gemini_google_search_tool'
Solution:
uv tool install .uv sync then uv run python script.pypython -c "import gemini_google_search_tool"# General help
gemini-google-search-tool --help
# Command-specific help
gemini-google-search-tool query --help
gemini-google-search-tool completion --help
# Version info
gemini-google-search-tool --version
Use -vv or -vvv for detailed debugging:
# Debug API calls and response processing
gemini-google-search-tool query "test" -vv
# Trace HTTP requests (shows full request/response)
gemini-google-search-tool query "test" -vvv
</details>
0: Success - query completed successfully1: Error - client error, invalid arguments, or query failureJSON (default):
-vv or -vvvMarkdown (--text):
Verbosity (stderr):
-v/-vv/-vvv for progressively more detail--add-citations when you need inline source linksjq for structured data processing-vv when troubleshooting, -vvv for HTTP-level details--pro for complex analysis requiring deeper reasoninguv tool install