Back to MCP directory
publicPublicdnsLocal runtime

alexatnordnet_mcp-google-custom-search-server

一个基于Google自定义搜索API的MCP协议服务器,为语言模型提供标准化网络搜索接口,支持环境变量配置和类型安全实现。

article

README

🚀 MCP 谷歌自定义搜索服务器

MCP 谷歌自定义搜索服务器基于模型上下文协议(MCP)构建,借助谷歌的自定义搜索 API 为语言学习模型(LLMs)提供网络搜索功能。通过标准化接口,LLMs 能轻松执行网络搜索。

🚀 快速开始

克隆仓库

git clone https://github.com/yourusername/mcp-google-custom-search-server.git
cd mcp-google-custom-search-server

安装依赖项

npm install

创建.env 文件

GOOGLE_API_KEY=你的API密钥
GOOGLE_SEARCH_ENGINE_ID=你的搜索引擎ID

构建服务器

npm run build

启动服务器

npm start

✨ 主要特性

  • 与谷歌自定义搜索 API 无缝集成,实现高效网络搜索。
  • 符合模型上下文协议(MCP),为语言学习模型提供标准化接口。
  • 采用 TypeScript 实现安全类型,保障代码质量。
  • 支持环境变量配置,方便灵活部署。
  • 使用 Zod 进行输入验证,确保输入数据的准确性。
  • 可配置搜索结果数量,最多返回 10 条结果。
  • 搜索结果经过格式化处理,包含标题、链接和描述。
  • 具备完善的错误处理与验证机制,增强系统稳定性。
  • 适用于 Claude Desktop 和其他 MCP 客户端,具有广泛的适用性。

📦 安装指南

先决条件

在开始之前,请确保完成以下准备工作:

  1. 启用谷歌自定义搜索 API
  2. 获取自定义搜索引擎 ID
  3. 本地开发要求
    • 安装 Node.js(v18 或更高版本)。
    • 安装 npm(随 Node.js 提供)。

📚 详细文档

配置

环境变量

| 变量名称 | 描述 | 是否必填 | |-----------------------|----------------------------|----------| | GOOGLE_API_KEY | 你的谷歌自定义搜索 API 密钥 | 是 | | GOOGLE_SEARCH_ENGINE_ID | 你的自定义搜索引擎 ID | 是 |

Claude Desktop 集成

在 Claude Desktop 配置文件(通常位于~/Library/Application Support/Claude/claude_desktop_config.json)中添加以下内容:

{
  "servers": {
    "custom_search": {
      "type": "mcp",
      "host": "localhost",
      "port": "3000"
    }
  }
}

API 文档

搜索工具

参数
  • query:要搜索的关键词或短语。
  • num_results:返回的结果数量(默认为 10)。
响应格式
{
  "results": [
    {
      "title": "结果标题",
      "link": "链接地址",
      "description": "结果描述"
    }
  ]
}

🔧 技术细节

项目结构

mcp-google-custom-search-server/
├── index.js          # 主应用程序文件
├── config.js        # 配置文件
└── package.json     # 依赖项和脚本

可用脚本

  • npm run build:构建服务器。
  • npm start:启动服务器。

💻 使用示例

基础用法

使用MCP Inspector测试服务器功能。在终端运行以下命令:

npm install -g mcp-inspector
mcp-inspector

输入以下内容进行搜索:

{
  "command": "search",
  "query": "MCP协议"
}
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client