自定义搜索服务器

一个通过Google自定义搜索API提供网页搜索功能的MCP服务器,使语言学习模型(LLM)能够使用标准化接口进行网页搜索。

  • by limklister
  • TypeScript
  • 本地部署
  • 47 星标
  • 更新于
在 GitHub 查看 limklister/mcp-google-custom-search-server

使用说明

MCP谷歌自定义搜索服务器

模型上下文协议(MCP)服务器,通过Google的自定义搜索API提供网络搜索功能。此服务器使语言学习模型(LLM)能够使用标准化界面执行网络搜索。

🌟 特性

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

📋 先决条件

在开始之前,请确保您已经:

  1. 启用自定义搜索API的谷歌云项目

  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桌面集成

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

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

📖 api参考

可用工具

搜索

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

参数:

  • query (string,必填):要执行的搜索查询
  • numResults (number,可选):要返回的结果数
    • 默认值:5
    • 最大值:10

示例响应:

Result 1:
Title: Example Search Result
URL: https://example.com
Description: This is an example search result description
---

Result 2:
...

🛠️ 发展

项目结构

mcp-google-custom-search-server/
├── src/
│   └── index.ts          # Main server implementation
├── build/                # Compiled JavaScript output
├── .env                  # Environment variables
├── package.json          # Project dependencies and scripts
├── tsconfig.json         # TypeScript configuration
└── README.md            # Project documentation

可用脚本

  • npm run build:将TypeScript编译为JavaScript
  • npm start:启动MCP服务器
  • npm run dev:观看模式用于开发

测试

  1. 使用MCP检查器:

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

    # After starting the server
    {"jsonrpc":"2.0","id":1,"method":"callTool","params":{"name":"search","arguments":{"query":"example search"}}}
    

📝 许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

🙏 致谢