dnvriend/gemini-google-search-tool
dnvriend/gemini-google-search-tool · 0 stars · 1 plugin
Marketplace A professional CLI tool and Python library for querying Gemini with Google Search grounding
Install
/plugin marketplace add dnvriend/gemini-google-search-toolRun inside Claude Code, then install plugins from it. Check the repo's README before you run it.
Plugins 1
After adding the marketplace, install one with /plugin install <name>@gemini-google-search-tool.
- 1gemini-google-search-toolQuery Gemini with Google Search grounding
/plugin install gemini-google-search-tool@gemini-google-search-tool
Files
gemini-google-search-tool
A professional CLI tool and Python library for querying Gemini with Google Search grounding, connecting AI responses to real-time web content with automatic citations.
Table of Contents
- About
- Use Cases
- Features
- Installation
- Configuration
- Usage
- Development
- Testing
- Resources
- Contributing
- License
About
What is Google Search Grounding?
Google Search grounding connects Gemini models to real-time web content through Google Search. When you query Gemini with grounding enabled, the model:
- Automatically determines if a search would improve the answer
- Generates and executes appropriate search queries
- Processes search results and synthesizes information
- Returns a grounded response with verifiable sources
This reduces hallucinations and provides up-to-date information beyond the model's training cutoff.
Why This CLI-First Tool?
This tool provides a CLI-first architecture designed for both humans and AI agents:
- Agent-Friendly Design: Structured commands and rich error messages enable AI agents (like Claude Code) to reason and act effectively in ReAct loops
- Composable Architecture: JSON output to stdout, logs to stderr—perfect for piping and automation
- Reusable Building Blocks: Commands serve as primitives for Claude Code skills, MCP servers, shell scripts, and custom workflows
- Dual-Mode Operation: Use it as a CLI tool or import as a Python library
- Production Quality: Type-safe (strict mypy), tested (pytest), with comprehensive error handling
Use Cases
- 📚 Real-Time Information: Access current events, news, and recent developments
- 🔍 Fact Verification: Ground responses in verifiable web sources
- 💡 Research Assistance: Gather information from multiple sources automatically
- 🤖 Agent Integration: Build AI workflows with reliable, up-to-date information
- 🔗 Citation Management: Track and display source attributions automatically
Features
Core Capabilities
- Real-Time Web Search: Automatic search execution with multi-query support
- Automatic Citations: Inline citations with source URIs and titles
- Model Selection: Choose between gemini-2.5-flash (fast) or gemini-2.5-pro (powerful)
- Flexible Input: Positional arguments or stdin for automation
- Multiple Output Formats: JSON (default) or markdown with citations
- Verbose Metadata: Full grounding details including search queries and supports
CLI-First Design
- Type Safety: Strict mypy checking, comprehensive type hints
- Error Handling: Rich error messages with suggested fixes
- Composability: JSON to stdout, logs to stderr for piping
- Documentation: Agent-friendly help with inline examples
- Testing: Comprehensive test suite with pytest
Installation
Prerequisites
- Python 3.14 or higher
- uv package manager (recommended)
- Google Gemini API key (get one free)
Install Globally with uv
# 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
Install with pip
pip install gemini-google-search-tool
Install with mise (recommended for development)
cd gemini-google-search-tool mise trust mise install uv sync uv tool install .
Shell Completion
Enable tab completion for your shell to improve the CLI experience:
Bash (add to ~/.bashrc):
eval "$(gemini-google-search-tool completion bash)"
Zsh (add to ~/.zshrc):
eval "$(gemini-google-search-tool completion zsh)"
Fish (run once):
mkdir -p ~/.config/fish/completions gemini-google-search-tool completion fish > ~/.config/fish/completions/gemini-google-search-tool.fish
For more details:
gemini-google-search-tool completion --help
Configuration
API Key Setup
The tool requires a GEMINI_API_KEY environment variable.
Option 1: Environment Variable
export GEMINI_API_KEY='your-api-key-here'
Option 2: macOS Keychain (secure storage)
# Store in keychain security add-generic-password -a "production" -s "GEMINI_API_KEY" -w "your-api-key" # Retrieve and export export GEMINI_API_KEY=$(security find-generic-password -a "production" -s "GEMINI_API_KEY" -w)
Get a free API key: Google AI Studio
Usage
CLI Usage
Basic Query
gemini-google-search-tool query "Who won euro 2024?"
Output:
{
"response_text": "Spain won Euro 2024, defeating England 2-1 in the final...",
"citations": [
{"index": 1, "uri": "https://...", "title": "youtube.com"},
{"index": 2, "uri": "https://...", "title": "wikipedia.org"}
]
}
Citations are always included in JSON output by default.
Query with Inline Citations
The --add-citations flag adds inline citation links directly into the response text.
gemini-google-search-tool query "Latest AI developments" --add-citations
Output:
{
"response_text": "Recent AI developments include...[1](https://...), [2](https://...)",
"citations": [
{"index": 1, "uri": "https://...", "title": "Source Title"},
{"index": 2, "uri": "https://...", "title": "Another Source"}
]
}
Read from stdin
echo "Climate change updates" | gemini-google-search-tool query --stdin
Markdown Output
gemini-google-search-tool query "Quantum computing news" --text
Output:
Recent advances in quantum computing include... ## Citations 1. [MIT Technology Review](https://...) 2. [Nature](https://...)
Verbose Output with Grounding Metadata
gemini-google-search-tool query "Latest tech trends" --verbose
Output includes:
- Response text
- Web search queries executed
- Grounding chunks with URIs
- Grounding supports (which parts of text are supported by which sources)
Use Pro Model
gemini-google-search-tool query "Analyze quantum computing impact" --pro
All Options Combined
gemini-google-search-tool query "Machine learning breakthroughs" \ --add-citations \ --pro \ --verbose
Library Usage
Import and use 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", # or "gemini-2.5-pro"
)
# Access response
print(response.response_text)
print(f"Citations: {len(response.citations)}")
# Access citations
for citation in response.citations:
print(f"[{citation.index}] {citation.title}: {citation.uri}")
# Access metadata
if response.web_search_queries:
print(f"Search queries: {response.web_search_queries}")
# 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)
Error Handling in Library
from gemini_google_search_tool import GeminiClient, GeminiClientError, SearchError
try:
client = GeminiClient()
response = query_with_grounding(client, "Your query")
except GeminiClientError as e:
print(f"Client error: {e}")
# Handle authentication or configuration errors
except SearchError as e:
print(f"Search error: {e}")
# Handle query execution errors
Development
Setup Development Environment
# Clone repository git clone https://github.com/dnvriend/gemini-google-search-tool.git cd gemini-google-search-tool # Install dependencies make install # Show available commands make help
Available Make Commands
make install # Install dependencies make format # Format code with ruff make lint # Run linting with ruff make typecheck # Run type checking with mypy make test # Run tests with pytest make check # Run all checks (lint, typecheck, test) make pipeline # Full pipeline: format, check, build, install-global make build # Build package make clean # Remove build artifacts
Project Structure
gemini-google-search-tool/
├── gemini_google_search_tool/
│ ├── __init__.py # Public API exports
│ ├── cli.py # CLI entry point (Click group)
│ ├── core/ # Core library (importable, CLI-independent)
│ │ ├── __init__.py
│ │ ├── client.py # Gemini client management
│ │ └── search.py # Search and citation logic
│ ├── commands/ # CLI command implementations
│ │ ├── __init__.py
│ │ └── query_commands.py # Query command with Click decorators
│ └── utils.py # Shared utilities (output, validation)
├── tests/ # Test suite
│ ├── __init__.py
│ └── test_utils.py
├── pyproject.toml # Project configuration
├── Makefile # Development commands
├── README.md # User documentation (this file)
├── CLAUDE.md # Developer guide
└── LICENSE # MIT License
Architecture Principles
- Separation of Concerns: Core library (
core/) is independent of CLI - Exception-Based Errors: Core functions raise exceptions (not
sys.exit), CLI handles formatting - Importable Library: Public API exposed via
__init__.pyfor programmatic use - Type Safety: Strict mypy checks, comprehensive type hints
- Composability: JSON to stdout, logs to stderr for piping
Testing
Run the test suite:
# Run all tests make test # Run with verbose output uv run pytest tests/ -v # Run specific test file uv run pytest tests/test_utils.py # Run with coverage uv run pytest tests/ --cov=gemini_google_search_tool
Resources
Official Documentation
- Google Search Grounding Documentation
- Gemini API Documentation
- Google AI Studio - Get API keys and test models
Related Tools
- google-genai Python SDK - Official Gemini Python client
- Click - CLI framework
- uv - Fast Python package manager
Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run the full pipeline (
make pipeline) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Style
- Follow PEP 8 guidelines (enforced by ruff)
- Use type hints for all functions (strict mypy)
- Write docstrings for public functions (Google style)
- Format code with
ruff format - Pass all checks:
make check
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Dennis Vriend
- GitHub: @dnvriend
- Email: dvriend@ilionx.com
Acknowledgments
- Built with Click for CLI framework
- Developed with uv for fast Python tooling
- Uses google-genai SDK for Gemini API access
- Quality assurance with ruff and mypy
Generated with AI
This project was generated using Claude Code, an AI-powered development tool by Anthropic. Claude Code assisted in creating the project structure, implementation, tests, documentation, and development tooling.
Made with ❤️ using Python 3.14
{
"name": "gemini-google-search-tool",
"owner": {
"name": "Dennis Vriend",
"email": "dvriend@ilionx.com",
"url": "https://github.com/dnvriend/gemini-google-search-tool"
},
"plugins": [
{
"name": "gemini-google-search-tool",
"source": "./plugins/gemini-google-search-tool",
"description": "Query Gemini with Google Search grounding"
}
]
}Facts
- Kind
- Marketplace
- Repo
- dnvriend/gemini-google-search-tool
- Group
- Uncategorized
- Stars
- 0
- Marketplace name
- gemini-google-search-tool
- Owner
- Dennis Vriend
- License
- MIT
- Language
- Python
- Created
- 2025-11-14
- Last push
- 2025-12-05
- Forks
- 1
- Plugins
- 1
From the same owner
- 2181dnvriend/openai-tts-tooldnvriend/openai-tts-tool0
- 2182dnvriend/paste-image-to-file-tooldnvriend/paste-image-to-file-tool0
- 1338dnvriend/ollama-deepseek-ocr-tooldnvriend/ollama-deepseek-ocr-tool4
- 1453dnvriend/gemini-nano-banana-tooldnvriend/gemini-nano-banana-tool3
- 1689dnvriend/pdf-to-pptx-tooldnvriend/pdf-to-pptx-tool2
- 1778dnvriend/kokoro-tts-tooldnvriend/kokoro-tts-tool1