Google Search MCP Server

Google Search MCP Server

镜像

这是一个提供 Google 搜索功能和网页内容分析的 MCP 服务器,让 AI 模型能够执行搜索和分析网页内容。

先决条件

  • Node.js (v16+)
  • Python (v3.8+)
  • Google Cloud Platform 账户和凭证:
    • API 密钥
    • 自定义搜索引擎 ID

安装步骤

  1. 克隆仓库并安装依赖:
# 安装 Node.js 依赖
npm install

# 安装 Python 依赖
pip install flask google-api-python-client flask-cors
  1. 创建配置文件 api-keys.json:
{
    "api_key": "your-google-api-key",
    "search_engine_id": "your-custom-search-engine-id"
}
  1. 添加到 MCP 设置:
{
  "mcpServers": {
    "google-search": {
      "command": "npm",
      "args": ["run", "start:all"],
      "cwd": "/path/to/google-search-server"
    }
  }
}

运行服务器

# 构建项目
npm run build

# 启动所有服务
npm run start:all

可用工具

1. 搜索

{
  "name": "search",
  "arguments": {
    "query": "您的搜索查询",
    "num_results": 5
  }
}

2. 网页分析

{
  "name": "analyze_webpage",
  "arguments": {
    "url": "https://example.com"
  }
}

3. 批量网页分析

{
  "name": "batch_analyze_webpages",
  "arguments": {
    "urls": [
      "https://example1.com",
      "https://example2.com"
    ]
  }
}

获取 Google API 凭证

  1. 访问 Google Cloud 控制台
  2. 创建/选择项目并启用自定义搜索 API
  3. 创建 API 密钥
  4. 可编程搜索引擎页面创建搜索引擎并获取 ID

问题排查

服务器会提供以下情况的详细错误信息:

  • API 凭证问题
  • 搜索请求失败
  • 无效 URL
  • 网络连接问题