谷歌搜索服务

一个与Google自定义搜索JSON API集成的MCP服务器实现,提供网页搜索功能,支持高级筛选和结构化结果。

  • by ayush-rudani
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 ayush-rudani/google-search-mcp-server

使用说明

谷歌搜索MCP服务器

MCP服务器实现与Google的自定义搜索JSON API集成,提供网络搜索功能。

特性

  • 网页搜索:使用全面的查询选项搜索谷歌
  • 高级过滤:按日期、语言、国家和安全搜索级别控制结果
  • 速率限制:内置速率限制,以防止API配额耗尽
  • 结构化结果:返回带有标题、URL和片段的格式化搜索结果

工具

  • 谷歌搜索
    • 使用高级过滤选项执行谷歌搜索
    • 输入:
      • query (string):搜索词(必填)
      • num_results (数字,可选):结果数量(1-10,默认值:5)
      • date_restrict (字符串,可选):按日期筛选(例如,“d1”表示最后一天)
      • language (字符串,可选):2个字母的语言代码(例如“en”)
      • country (字符串,可选):2个字母的国家代码(例如“us”)
      • safe_search (字符串,可选):安全级别(“关闭”、“中等”、“高”)

配置

获取API密钥

  1. 在以下位置创建Google Cloud项目 谷歌云控制台
  2. 通过激活项目的自定义搜索JSON API API仪表盘
  3. 通过“凭据”部分或按照生成API密钥 自定义搜索API指南
  4. 通过在中设置自定义搜索引擎来获取搜索引擎ID 谷歌的可编程搜索

环境变量

在运行服务器之前设置这些:

export GOOGLE_API_KEY="your-api-key"
export GOOGLE_SEARCH_ENGINE_ID="your-search-engine-id"

从本地存储库运行

要直接从源运行服务器,请执行以下操作:

  1. 克隆存储库

     git clone https://github.com/ayush-rudani/google-search-mcp-server.git
     cd google-search-mcp-server
    
  2. 安装依赖项

     pnpm install
     # or
     npm install
    
  3. 构建项目

     pnpm run build
     # or
     npm run build
    
  4. 配置Claude桌面 更新您的 claude_desktop_config.json:

    {
      "mcpServers": {
        "google-search": {
          "command": "/path/to/node", // <--- Important to add the following, run in your terminal `echo "$(which node)"` to get the path
          "args": ["/full/path/to/google-search-mcp/index.js"],
          "env": {
            "GOOGLE_API_KEY": "your-api-key",
            "GOOGLE_SEARCH_ENGINE_ID": "your-search-engine-id"
          }
        }
      }
    }
    
    • 替换 /path/to/node 带有Node.js可执行文件的完整路径(您可以通过运行以下命令找到它 which node 在您的终端中)
  5. 测试服务器

     export GOOGLE_API_KEY=your_api_key_here
     export GOOGLE_SEARCH_ENGINE_ID=your_engine_id_here
     node dist/index.js
    

速率限制

默认情况下,服务器强制执行每分钟10次请求的速率限制,以防止超过Google的API配额。如果需要,您可以在代码中进行调整。

许可证

此MCP服务器根据MIT许可证获得许可。有关详细信息,请参阅LICENSE文件。