gemini-mcp
MCP server providing Google Search grounding with source citations using Gemini Code Assist.
README
Gemini CLI MCP Server
An MCP (Model Context Protocol) server that provides Google Search grounding capabilities using Gemini Code Assist. This server enables LLMs like Claude to perform web searches with citations and source attribution.
Features
- Google Search Grounding: Get answers with real-time web search results
- Source Citations: Responses include source URLs and citation mapping
- Automatic Token Refresh: OAuth credentials are automatically refreshed when expired
- Docker Support: Run as a containerized service with stdio or HTTP/SSE transport
- Multiple Models: Support for various Gemini models
Prerequisites
- Python 3.11+
- A Google account with access to Gemini Code Assist
- A Google OAuth client (set
GOOGLE_OAUTH_CLIENT_IDandGOOGLE_OAUTH_CLIENT_SECRET) it is out there somewhere , search for it
Installation
Local Installation
- Clone or download this directory
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
Docker Installation
Build the Docker image:
docker build -t gemini-mcp .
Authentication Setup
Before using any scripts, you need to authenticate with Google.
Local Authentication
# Option A: export env vars
export GOOGLE_OAUTH_CLIENT_ID="...apps.googleusercontent.com"
export GOOGLE_OAUTH_CLIENT_SECRET="..."
python manual_auth.py
Docker Authentication
docker run -it --rm -e GOOGLE_OAUTH_CLIENT_ID="..." -e GOOGLE_OAUTH_CLIENT_SECRET="..." -p 8080:8080 -v ./config:/app/config gemini-mcp
On first run (when no credentials exist), the container will:
- Display a URL to open in your browser for Google OAuth login
- Guide you to paste the redirect URL back
- Save your credentials to the config directory
- Print your credential/project info
- Start the MCP server in HTTP/SSE mode on port 8080
Important: Keep your credentials secure and never commit them to version control.
Docker Usage (HTTP/SSE)
The Docker container always starts the MCP server in HTTP/SSE mode.
Examples
# First run (interactive OAuth + start server)
docker run -it --rm -p 8080:8080 -v ./config:/app/config gemini-mcp
# Subsequent runs (no -it needed once credentials exist)
docker run -d -p 8080:8080 -v ./config:/app/config gemini-mcp
Available Scripts
server.py - MCP Server
The main MCP server that exposes the google_search tool.
# Run directly (defaults to HTTP/SSE on :8080)
python server.py
# If you need stdio transport (some MCP clients), set:
MCP_TRANSPORT=stdio python server.py
The server provides the following tool:
google_search(query, model): Search using Gemini with Google Search groundingquery: The search query or questionmodel: The model to use (default:gemini-2.5-flash)
search.py - CLI Search
A command-line interface for quick searches without running the full MCP server.
# Basic search
python search.py "What is the latest news about AI?"
# Specify a model
python search.py "Explain quantum computing" --model gemini-2.5-pro
# Get help
python search.py --help
info.py - Credential Info
Display information about your current credentials and authentication status.
python info.py
This shows:
- User email and name
- Current tier and managed project
- Available tiers
manual_auth.py - Authentication
Perform OAuth authentication and save credentials.
python manual_auth.py
Available Models
The following Gemini models are supported:
| Model | Description |
|---|---|
gemini-2.5-flash |
Fast, efficient model (default) |
gemini-2.5-pro |
More capable model for complex tasks |
gemini-2.0-flash |
Previous generation flash model |
gemini-1.5-flash |
Legacy flash model |
gemini-1.5-pro |
Legacy pro model |
MCP Client Configuration
For clients that support HTTP/SSE transport, run the server in HTTP mode:
docker run -d -p 8080:8080 -v ./config:/app/config gemini-mcp
Then configure your MCP client:
{
"mcpServers": {
"gemini-search": {
"url": "http://localhost:8080/sse"
}
}
}
Environment Variables
| Variable | Description | Default |
|---|---|---|
CREDENTIALS_PATH |
Directory containing credentials.json |
. (local) or /app/config (Docker) |
HOST |
HTTP bind address | 0.0.0.0 |
HTTP_PORT |
HTTP port (preferred) | 8080 |
PORT |
HTTP port (legacy alias) | 8080 |
MCP_TRANSPORT |
MCP transport (sse or stdio) |
sse |
Setting Environment Variables
Local:
export CREDENTIALS_PATH=/path/to/dir
python server.py
Manual Google Cloud Setup
If automatic provisioning fails, you may need to set up the project manually:
- Go to the Google Cloud Console.
- Create or select a project.
- Enable the Gemini for Google Cloud API (
cloudaicompanion.googleapis.com). - Configure the
projectIdin your Opencode config as shown above.
Gemini Admin Settings
In Google Cloud Console, search for Admin for Gemini. Open it, go to Settings, then enable Preview on release channels for Gemini Code Assist in local IDEs.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。