基本能力
产品定位
Google MCP Server 是一个实现了模型上下文协议(MCP)的服务,用于与Google API集成,支持AI助手和其他MCP兼容客户端的连接。
核心功能
- googleSearchContent: 使用Google Custom Search API执行网页搜索,并返回结构化的结果(标题、链接和摘要)。
- googleSearchImages: 使用Google Custom Search API执行图像搜索,并返回第一个结果的Markdown图像链接。
适用场景
- 需要集成Google搜索功能的AI助手。
- 需要结构化搜索结果的MCP兼容客户端。
- 需要图像搜索功能的应用程序。
工具列表
- googleSearchContent: 执行网页搜索并返回结构化结果。
- googleSearchImages: 执行图像搜索并返回图像链接。
常见问题解答
- 确保Google API密钥和CX ID正确设置在
.env
文件或环境中。 - 检查所有依赖是否已安装(
npm install
)。 - 确认使用Node.js 18或更新版本。
- 如果修改了代码,重启服务器或测试脚本。
使用教程
使用依赖
- Node.js 18+
- npm
安装教程
- 克隆仓库
sh
git clone https://github.com/your-username/mcp-google-search.git
cd google-mcp-server - 安装依赖
sh
npm install - 设置Google Custom Search API凭证
在项目根目录创建.env
文件,内容如下:
GOOGLE_API_KEY=your_google_api_key_here
GOOGLE_CX_ID=your_custom_search_engine_id_here
调试方式
- 运行测试搜索
sh
npx ts-node src/test.ts - 与MCP兼容客户端集成
在MCP设置文件中添加如下条目:
json
{
"mcpServers": {
"google-api": {
"command": "npx",
"args": ["ts-node", "src/index.ts"],
"env": {
"GOOGLE_API_KEY": "your_google_api_key_here",
"GOOGLE_CX_ID": "your_custom_search_engine_id_here"
}
}
}
}