返回市场
谷歌自定义搜索服务器

谷歌自定义搜索服务器

作者:limklister37 星标更新:2025-10-12

项目介绍

【技术文档摘要】

MCP Google 自定义搜索服务器

这是一个通过 Google 的自定义搜索 API 提供网络搜索功能的模型上下文协议(MCP)服务器。该服务器使语言学习模型(LLMs)能够使用标准化接口执行网络搜索。

🌟 特性

  • 无缝集成 Google 自定义搜索 API
  • 符合模型上下文协议(MCP)的服务器实现
  • 使用 TypeScript 实现类型安全
  • 环境变量配置
  • 使用 Zod 进行输入验证
  • 可配置的搜索结果(每个查询最多 10 条)
  • 格式化的搜索结果,包括标题、URL 和描述
  • 错误处理和验证
  • 兼容 Claude Desktop 和其他 MCP 客户端

📋 先决条件

在开始之前,请确保您拥有以下内容:

  1. 启用了自定义搜索 API 的 Google Cloud 项目

  2. 自定义搜索引擎 ID

  3. 本地开发需求:

    • Node.js(v18 或更高版本)
    • npm(随 Node.js 一起提供)

🚀 快速开始

  1. 克隆仓库:

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

    npm install
    
  3. 创建 .env 文件:

    GOOGLE_API_KEY=your-api-key
    GOOGLE_SEARCH_ENGINE_ID=your-search-engine-id
    
  4. 构建服务器:

    npm run build
    
  5. 启动服务器:

    npm start
    

🔧 配置

环境变量

变量名称描述是否必需
GOOGLE_API_KEY您的 Google 自定义搜索 API 密钥
GOOGLE_SEARCH_ENGINE_ID您的自定义搜索引擎 ID

Claude Desktop 集成

将此配置添加到您的 Claude Desktop 配置文件中(通常位于 ~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "google-search": {
      "command": "node",
      "args": [
        "/绝对路径/mcp-google-custom-search-server/build/index.js"
      ],
      "env": {
        "GOOGLE_API_KEY": "your-api-key",
        "GOOGLE_SEARCH_ENGINE_ID": "your-search-engine-id"
      }
    }
  }
}

📖 API 参考

可用工具

search

使用 Google 自定义搜索 API 执行网络搜索。

参数:

  • query(字符串,必需):要执行的搜索查询
  • numResults(数字,可选):返回的结果数量
    • 默认值:5
    • 最大值:1
    • 最大值:10

示例响应:

结果 1:
标题:示例搜索结果
URL:https://example.com
描述:这是示例搜索结果描述
---

结果 2:
...

🛠️ 开发

项目结构

mcp-google-custom-search-server/
├── src/
│   └── index.ts          # 主服务器实现
├── build/                # 编译后的 JavaScript 输出
├── .env                  # 环境变量
├── package.json          # 项目依赖项和脚本
├── tsconfig.json         # TypeScript 配置
└── README.md            # 项目文档

可用脚本

  • npm run build:将 TypeScript 编译为 JavaScript
  • npm start:启动 MCP 服务器
  • npm run dev:开发模式下的监视模式

测试

  1. 使用 MCP Inspector:

    npx @modelcontextprotocol/inspector node build/index.js
    
  2. 使用示例查询进行手动测试:

    # 在启动服务器后
    {"jsonrpc":"2.0","id":1,"method":"callTool","params":{"name":"search","arguments":{"query":"示例搜索"}}}
    
<a href="https://glama.ai/mcp/servers/y1s99uqqq6"> <img width="380" height="200" src="https://gips1.baidu.com/it/u=2674337390,209401610&fm=3081&app=3081&f=PNG?w=760&h=400" alt="Google 自定义搜索服务器 MCP 服务器" /> </a>

MseeP.ai 安全评估徽章

📝 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件以获取详细信息。

🙏 致谢