Google MCP Server

Google MCP Server

site icon
2025.04.24 0
TypeScript搜索服务API集成搜索工具
Google MCP Server 是一个实现了模型上下文协议(MCP)的服务,用于与Google API集成,支持AI助手和其他MCP兼容客户端的连接。该服务提供了搜索和图像搜索功能,能够返回结构化的搜索结果和图像链接。
View on GitHub

Overview

基本能力

产品定位

Google MCP Server 是一个实现了模型上下文协议(MCP)的服务,用于与Google API集成,支持AI助手和其他MCP兼容客户端的连接。

核心功能

  1. googleSearchContent: 使用Google Custom Search API执行网页搜索,并返回结构化的结果(标题、链接和摘要)。
  2. googleSearchImages: 使用Google Custom Search API执行图像搜索,并返回第一个结果的Markdown图像链接。

适用场景

  1. 需要集成Google搜索功能的AI助手。
  2. 需要结构化搜索结果的MCP兼容客户端。
  3. 需要图像搜索功能的应用程序。

工具列表

  1. googleSearchContent: 执行网页搜索并返回结构化结果。
  2. googleSearchImages: 执行图像搜索并返回图像链接。

常见问题解答

  1. 确保Google API密钥和CX ID正确设置在.env文件或环境中。
  2. 检查所有依赖是否已安装(npm install)。
  3. 确认使用Node.js 18或更新版本。
  4. 如果修改了代码,重启服务器或测试脚本。

使用教程

使用依赖

  1. Node.js 18+
  2. npm

安装教程

  1. 克隆仓库
git clone https://github.com/your-username/mcp-google-search.git
cd google-mcp-server
  1. 安装依赖
npm install
  1. 设置Google Custom Search API凭证 在项目根目录创建.env文件,内容如下:
GOOGLE_API_KEY=your_google_api_key_here
GOOGLE_CX_ID=your_custom_search_engine_id_here

调试方式

  1. 运行测试搜索
npx ts-node src/test.ts
  1. 与MCP兼容客户端集成 在MCP设置文件中添加如下条目:
{
  "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"
      }
    }
  }
}

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。