M

MCP-GCS API 服务器

@limklister/mcp-google-custom-search-server
0 Stars 379 次浏览 limklister 更新于 2026-08-23

一种模型上下文协议服务器,它通过标准化接口使用谷歌的自定义搜索API使大型语言模型能够进行网络搜索。

该服务暂未提供标准配置,请参考 README 手动接入

可用工具 (1 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

search 2 个参数 需填 1 项

Search the web using Google Custom Search API

必填参数:query

服务介绍

MCP Google 自定义搜索服务器

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

🌟 特性

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

📋 前提条件

在开始之前,请确保您已具备以下条件:

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

  2. 自定义搜索引擎 ID

  3. 本地开发要求:

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

🚀 快速开始

  1. 克隆仓库:

    git clone https://github.com/yourusername/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 桌面配置文件中(通常位于 ~/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 执行网络搜索。

参数:

  • query (字符串, 必需): 要执行的搜索查询
  • numResults (数字, 可选): 返回的结果数量
    • 默认值: 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 Inspector:

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

    # 启动服务器后
    {"jsonrpc":"2.0","id":1,"method":"callTool","params":{"name":"search","arguments":{"query":"example search"}}}
    

📝 许可证

本项目根据 MIT 许可证发布 - 详情请参阅 LICENSE 文件。

🙏 致谢

  • 采用 Model Context Protocol (MCP) 构建
  • 使用了 Google 的自定义搜索 API
  • 受到 LLM 应用程序中更好搜索功能需求的启发

相关 MCP 服务