使用说明
谷歌搜索MCP服务器
一种模型上下文协议(MCP)服务器,提供具有智能结果摘要的谷歌搜索功能。 💰 直接使用谷歌官方API,每天100次免费搜索,节省开支 -无需昂贵的第三方搜索服务!
🎯 关键卖点
- 💰 包括免费套餐:使用Google自定义搜索JSON API,每天进行100次免费搜索-与其他搜索服务一样不收取订阅费
- 🔗 直接GOOGLE API:谷歌官方集成意味着可靠、最新的结果,无需中间商成本
- 💸 成本效益高:只有当您超过免费级别时,才直接向谷歌支付费用(与其他搜索MCP的昂贵月度订阅相比)
- 🚀 生产准备就绪:企业级可靠性,无需企业定价
特性
- 谷歌搜索集成:使用Google自定义搜索JSON API获得可靠的搜索结果
- 两个搜索工具:
google_search:以JSON格式返回原始搜索结果google_search_and_summarize:返回搜索结果的全面降价摘要
- 智能摘要:按领域组织结果,提供关键发现,并包括源链接
- 全面的错误处理:处理API错误、速率限制和身份验证问题
- 详细日志记录:用于调试和监控的控制台日志记录
先决条件
1.Google自定义搜索API设置
您需要设置Google自定义搜索API凭据:
-
创建谷歌云项目:
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
-
启用自定义搜索API:
- 导航到“API和服务”>“库”
- 搜索“自定义搜索JSON API”
- 点击并启用API
-
创建API密钥:
- 转到“API和服务”>“凭据”
- 单击“创建凭据”>“API密钥”
- 复制您的API密钥(确保其安全!)
-
创建自定义搜索引擎:
- 首选 自定义搜索引擎
- 点击“添加”以创建新的搜索引擎
- 进入
google.com作为搜索的网站 - 点击“创建”
- 从设置中复制搜索引擎ID
2.环境变量
设置这些环境变量:
export GOOGLE_API_KEY="your_google_api_key_here"
export GOOGLE_SEARCH_ENGINE_ID="your_search_engine_id_here"
安装
-
克隆/下载项目:
cd google-search-mcp npm install npm run build -
测试服务器 (可选):
# Set environment variables first export GOOGLE_API_KEY="your_api_key" export GOOGLE_SEARCH_ENGINE_ID="your_engine_id" # Test the server echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | node build/index.js
MCP配置
将此服务器添加到您的MCP设置中(通常在Claude Desktop或其他MCP客户端中):
适用于克劳德桌面
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"google-search": {
"command": "node",
"args": ["/path/to/google-search-mcp/build/index.js"],
"env": {
"GOOGLE_API_KEY": "your_google_api_key_here",
"GOOGLE_SEARCH_ENGINE_ID": "your_search_engine_id_here"
},
"disabled": false,
"autoApprove": []
}
}
}
对于其他MCP客户端
使用相同的配置模式,调整路径以匹配您的安装位置。
可用工具
1. google_search
以JSON格式返回原始搜索结果。
参数:
query(必填):搜索查询字符串numResults(可选):要返回的结果数(1-10,默认值:10)
示例用法:
{
"name": "google_search",
"arguments": {
"query": "artificial intelligence trends 2024",
"numResults": 5
}
}
2. google_search_and_summarize
返回搜索结果的全面降价摘要。
参数:
query(必填):搜索查询字符串numResults(可选):要分析的结果数量(1-10,默认值:10)
示例用法:
{
"name": "google_search_and_summarize",
"arguments": {
"query": "climate change renewable energy solutions",
"numResults": 8
}
}
输出格式
原始搜索结果(google_search)
{
"query": "your search query",
"totalResults": 5,
"results": [
{
"title": "Page Title",
"url": "https://example.com/page",
"snippet": "Brief description of the page content...",
"domain": "example.com"
}
]
}
总结结果(google_search_and_summarize)
# Search Results Summary for "your query"
Found 5 relevant results:
## Key Findings:
1. **First Result Title**
Brief description from the search snippet
Source: example.com
2. **Second Result Title**
Another description
Source: another-site.com
## Sources:
1. [First Result Title](https://example.com/page1)
2. [Second Result Title](https://another-site.com/page2)
## Domain Distribution:
- example.com: 2 results
- another-site.com: 1 result
错误处理
服务器处理各种错误情况:
- 缺少API凭据:清除有关所需环境变量的错误消息
- API身份验证错误:关于检查API密钥和搜索引擎ID的具体指导
- 速率限制:关于API配额限制的信息性消息
- 网络超时:10秒超时,并显示相应的错误消息
- 无效查询:验证空的或无效的搜索查询
费率限制和成本比较
Google自定义搜索JSON API限制
- 免费套餐:每天100次查询(免费!)
- 付费层:每天最多10000次查询
- 每个请求:每次搜索最多10个结果
💰 与其他搜索服务的成本比较
| 服务 | 免费等级 | 付费计划 | 每月费用(1000次搜索) |
|---|---|---|---|
| 此MCP(谷歌直销) | ✅ 每天免费100次 | 每1000次查询5美元 | 约5美元 |
| Serper API | ❌ 无 | 50美元/月 | 50美元以上 |
| 搜索API | ❌ 无 | 20美元/月 | 20+美元 |
| SerpApi | ❌ 无 | 25美元/月 | 25美元以上 |
| 必应搜索API | 每月1000次 | 每1000次查询4美元 | ~ 4美元 |
节省:与高级搜索服务相比,每年高达600+美元!
故障排除
常见问题
-
“缺少必需的环境变量”:
- 确保
GOOGLE_API_KEY和GOOGLE_SEARCH_ENGINE_ID已设置 - 检查变量名拼写是否正确
- 确保
-
“Google API身份验证失败”:
- 验证您的API密钥是否正确
- 确保在Google Cloud项目中启用自定义搜索JSON API
- 检查您的搜索引擎ID是否正确
-
“超出费率限制”:
- 您已达到每日配额限制
- 等待配额重置或升级到付费计划
-
“未找到搜索结果”:
- 尝试不同的搜索词
- 检查您的自定义搜索引擎是否配置为搜索整个网络
调试
运行服务器时,通过检查控制台输出启用详细日志记录。所有操作都以前缀记录,如 [Setup], [API], [Error]等等。
发展
项目结构
google-search-mcp/
├── src/
│ └── index.ts # Main server implementation
├── build/ # Compiled JavaScript output
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
可用脚本
npm run build:将TypeScript编译为JavaScriptnpm run watch:监视更改并自动重建npm run inspector:运行MCP检查器进行调试
贡献
- 对以下内容进行更改
src/index.ts - 测试用
npm run build - 根据需要更新文档
- 使用实际的MCP客户端集成进行测试
许可证
这个项目是私人的,供个人/内部使用。
