这是一个模型上下文协议(MCP)服务器,借助 Gemini API 的信息关联功能,提供由人工智能驱动的网络搜索和内容总结服务。与传统搜索工具返回原始搜索结果不同,该服务器利用 Gemini AI 整合信息,并提供带有引用来源的全面答案。
在配置完成后,google_search
工具将在 Claude Code 中可用。你可以通过向 Claude 提出搜索和总结信息的请求来使用它,例如:
git clone https://github.com/ml0-1337/mcp-gemini-grounding.git
cd mcp-gemini-grounding
make build
若要查看所有可用命令的完整列表,请运行:
make help
# 从源代码安装
make install
# 或者直接使用 go install
go install github.com/ml0-1337/mcp-gemini-grounding/cmd/gemini-grounding@latest
服务器支持两种认证方式:
~/.gemini/oauth_creds.json
中的凭证。GEMINI_API_KEY
环境变量。根据你的需求选择合适的配置范围:
重要提示:在使用以下 CLI 命令时,你必须提供二进制文件的完整绝对路径(例如,/Users/username/projects/mcp-gemini-grounding/mcp-gemini-grounding
)。像 ./mcp-gemini-grounding
这样的相对路径会导致服务器启动失败。
适用于:个人开发服务器、实验性配置或包含敏感凭证的服务器。 选项 A:使用 CLI(推荐)
# 如果是全局安装
claude mcp add gemini-grounding
# 或者使用完整绝对路径(必需 - 相对路径会失败)
claude mcp add gemini-grounding /full/path/to/mcp-gemini-grounding
# 示例:claude mcp add gemini-grounding /Users/username/projects/mcp-gemini-grounding/mcp-gemini-grounding
选项 B:手动配置
{
"mcpServers": {
"gemini-grounding": {
"command": "/path/to/mcp-gemini-grounding",
"env": {
"GEMINI_API_KEY": "$GEMINI_API_KEY"
}
}
}
}
此配置存储在你项目的 .claude/settings.local.json
文件中,不会与他人共享。
适用于:团队协作,所有成员需要相同的 MCP 服务器配置。 选项 A:使用 CLI(推荐)
# 如果是全局安装
claude mcp add gemini-grounding -s project
# 或者使用完整绝对路径(必需 - 相对路径会失败)
claude mcp add gemini-grounding -s project /full/path/to/mcp-gemini
# 示例:claude mcp add gemini-grounding -s project /Users/username/projects/mcp-gemini-grounding/mcp-gemini-grounding
选项 B:手动配置
.mcp.json
文件。{
"mcpServers": {
"gemini-grounding": {
"command": "mcp-gemini-grounding",
"env": {
"GEMINI_API_KEY": "$GEMINI_API_KEY"
}
}
}
}
GEMINI_API_KEY
环境变量。注意:永远不要直接提交实际的 API 密钥。始终使用环境变量引用(例如,$GEMINI_API_KEY
)。
适用于:你希望在所有项目中都能使用的个人实用服务器。 选项 A:使用 CLI(推荐)
# 如果是全局安装
claude mcp add gemini-grounding -s user
# 或者使用完整绝对路径(必需 - 相对路径会失败)
claude mcp add gemini-grounding -s user /full/path/to/mcp-gemini
# 示例:claude mcp add gemini-grounding -s user /Users/username/projects/mcp-gemini-grounding/mcp-gemini-grounding
选项 B:手动配置
{
"mcpServers": {
"gemini-grounding": {
"command": "gemini",
"env": {
"GEMINI_API_KEY": "$GEMINI_API_KEY"
}
}
}
}
如果你使用 go install
进行了全局安装,你可以直接使用 "command": "gemini"
。
添加服务器后,设置你的 API 密钥:
# macOS/Linux
export GEMINI_API_KEY="your-api-key-here"
# Windows (PowerShell)
$env:GEMINI_API_KEY="your-api-key-here"
# Windows (Command Prompt)
set GEMINI_API_KEY=your-api-key-here
若要进行永久配置,请将导出语句添加到你的 shell 配置文件(~/.bashrc
、~/.zshrc
等)中。
Claude Code 按以下顺序应用配置(优先级从高到低):
$GEMINI_API_KEY
。export GEMINI_API_KEY="your-api-key-here"
~/.gemini/oauth_creds.json
中的 OAuth 凭证。.mcp.json
),且不包含敏感数据。{
"name": "google_search",
"description": "通过 Gemini AI 的信息关联功能使用 Google 搜索来查找信息,并提供带有引用的整合答案。返回由人工智能生成的总结内容,而不是原始搜索结果。",
"inputSchema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "在网络上查找信息的搜索查询"
}
},
"required": ["query"]
}
}
该工具返回的搜索结果包含:
示例输出:
关于 "量子计算" 的网络搜索结果:
量子计算是一个快速发展的领域[1]。最近的突破显示了其在实际应用中的潜力[2]。
来源:
[1] 量子计算解释 - MIT (https://mit.edu/quantum)
[2] 最新量子突破 - Nature (https://nature.com/quantum)
# 安装依赖
make deps
# 构建项目
make build
# 运行测试
make test
# 运行所有质量检查
make audit
运行 make help
查看所有可用命令。主要命令包括:
make build
、make run
、make install
make test
、make cover
、make test-race
make fmt
、make vet
、make lint
、make audit
make dev
、make watch
(需要 air)make build-all
(为 Linux、macOS、Windows 构建)make mcp-install
、make mcp-config
make release
、make checksum
# 运行所有测试
make test
# 运行带覆盖率的测试
make cover
# 运行带竞态检测的测试
make test-race
# 生成 HTML 覆盖率报告
make cover-html
scripts/test/
目录中提供了各种用于 OAuth2 和 API 测试的脚本。详细信息请参阅 scripts/test/README.md。
graph TD
subgraph User
A[MCP Client e.g. Claude Code]
end
subgraph "mcp-gemini-grounding"
B[cmd/gemini-grounding/main.go]
C[internal/search]
D[internal/gemini]
E[internal/auth]
end
subgraph "Google Cloud"
F[Gemini API]
end
A -- MCP Request --> B
B -- Initializes --> C
B -- Initializes --> D
B -- Initializes --> E
C -- Uses --> D
D -- Uses --> E
D -- Makes API Calls --> F
style A fill:#f9f,stroke:#333,stroke-width:2px
style F fill:#bbf,stroke:#333,stroke-width:2px
mcp-gemini-grounding/
├── cmd/gemini-grounding/ # 主应用程序入口点
├── internal/
│ ├── auth/ # 认证处理
│ ├── gemini/ # Gemini API 客户端
│ └── search/ # MCP 工具处理程序
├── go.mod
├── go.sum
└── README.md
ls ~/.gemini/oauth_creds.json
echo $GEMINI_API_KEY
本项目采用 MIT 许可证 - 详细信息请参阅 LICENSE 文件。
欢迎贡献代码!请随时提交拉取请求。
https://github.com/ml0-1337/mcp-gemini-grounding