Google Search MCP Server

by mixelpixx
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Provides Google search capabilities to AI models through an MCP server interface, allowing for advanced search queries with filtering options for date, language, country, and safe search

  • Integrates with Google Cloud Platform for API credentials and Custom Search capabilities needed to power the Google search functionality

专为与 Cline + VS Code 配合使用而构建!

Google 搜索 MCP 服务器

一个 MCP(模型上下文协议)服务器,提供 Google 搜索功能和网页内容分析工具。该服务器使 AI 模型能够以编程方式执行 Google 搜索并分析网页内容。

特征

  • 带有过滤选项(日期、语言、国家、安全搜索)的高级 Google 搜索
  • 详细网页内容提取与分析
  • 批量网页分析,用于比较多个来源
  • API 凭证的环境变量支持
  • 全面的错误处理和用户反馈
  • 符合 MCP 标准的接口,可与 AI 助手无缝集成

先决条件

  • Node.js(v16 或更高版本)
  • Python(v3.8 或更高版本)
  • Google 云端平台帐户
  • 自定义搜索引擎 ID
  • Google API 密钥

安装

  1. 克隆存储库:
    git clone https://github.com/your-username/google-search-mcp.git cd google-search-mcp
  2. 安装 Node.js 依赖项:
    npm install
  3. 安装 Python 依赖项:
    pip install flask google-api-python-client flask-cors beautifulsoup4 trafilatura markdownify
  4. 构建 TypeScript 代码:
    npm run build
  5. 创建一个帮助脚本来启动 Python 服务器(Windows 示例):
    # Create start-python-servers.cmd @echo off echo Starting Python servers for Google Search MCP... REM Start Python search server start "Google Search API" cmd /k "python google_search.py" REM Start Python link viewer start "Link Viewer" cmd /k "python link_view.py" echo Python servers started. You can close this window.

配置

API 凭证

您可以通过两种方式提供 Google API 凭据:

  1. 环境变量(推荐):
    • 在您的环境中设置GOOGLE_API_KEYGOOGLE_SEARCH_ENGINE_ID
    • 服务器将自动使用这些值
  2. 配置文件
    • 在根目录下创建api-keys.json文件:GXP6

MCP 设置配置

将服务器配置添加到您的 MCP 设置文件:

对于 Cline(VS Code 扩展)

文件位置: %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json

{ "mcpServers": { "google-search": { "command": "C:\\Program Files\\nodejs\\node.exe", "args": ["C:\\path\\to\\google-search-mcp\\dist\\google-search.js"], "cwd": "C:\\path\\to\\google-search-mcp", "env": { "GOOGLE_API_KEY": "your-google-api-key", "GOOGLE_SEARCH_ENGINE_ID": "your-custom-search-engine-id" }, "disabled": false, "autoApprove": [] } } }

对于克劳德桌面应用程序

文件位置: %APPDATA%\Claude\claude_desktop_config.json

{ "mcpServers": { "google-search": { "command": "C:\\Program Files\\nodejs\\node.exe", "args": ["C:\\path\\to\\google-search-mcp\\dist\\google-search.js"], "cwd": "C:\\path\\to\\google-search-mcp", "env": { "GOOGLE_API_KEY": "your-google-api-key", "GOOGLE_SEARCH_ENGINE_ID": "your-custom-search-engine-id" }, "disabled": false, "autoApprove": [] } } }

运行服务器

方法一:单独启动 Python 服务器(推荐)

  1. 首先,使用帮助脚本启动 Python 服务器:
    start-python-servers.cmd
  2. 配置 MCP 设置以仅运行 Node.js 服务器:
    { "command": "C:\\Program Files\\nodejs\\node.exe", "args": ["C:\\path\\to\\google-search-mcp\\dist\\google-search.js"] }

方法 2:一体化脚本

使用单个命令启动 TypeScript 和 Python 服务器:

npm run start:all

可用工具

在 Google 上搜索并返回相关网页结果。此工具使用 Google 搜索引擎查找特定主题的网页、文章和信息。

{ "name": "google_search", "arguments": { "query": "your search query", "num_results": 5, // optional, default: 5, max: 10 "date_restrict": "w1", // optional, restrict to past day (d1), week (w1), month (m1), year (y1) "language": "en", // optional, ISO 639-1 language code (en, es, fr, de, ja, etc.) "country": "us", // optional, ISO 3166-1 alpha-2 country code (us, uk, ca, au, etc.) "safe_search": "medium" // optional, safe search level: "off", "medium", "high" } }

2. 提取网页内容

提取并分析网页内容,将其转换为可读文本。此工具可提取主要内容,同时移除广告、导航元素和其他杂乱内容。

{ "name": "extract_webpage_content", "arguments": { "url": "https://example.com" } }

3. extract_multiple_webpages

通过单个请求提取并分析多个网页内容。非常适合比较不同来源的信息或收集某个主题的综合信息。

{ "name": "extract_multiple_webpages", "arguments": { "urls": [ "https://example1.com", "https://example2.com" ] } }

示例用法

以下是一些如何使用 Google 搜索 MCP 工具的示例:

基本搜索

Search for information about artificial intelligence

带过滤器的高级搜索

Search for recent news about climate change from the past week in Spanish

内容提取

Extract the content from https://example.com/article

多内容比较

Compare information from these websites: - https://site1.com/topic - https://site2.com/topic - https://site3.com/topic

获取 Google API 凭证

  1. 前往Google Cloud Console
  2. 创建新项目或选择现有项目
  3. 启用自定义搜索 API
  4. 创建 API 凭证(API 密钥)
  5. 前往自定义搜索引擎页面
  6. 创建新的搜索引擎并获取您的搜索引擎 ID
  7. 将这些凭据添加到您的api-keys.json文件

错误处理

服务器提供以下详细的错误消息:

  • API 凭证缺失或无效
  • 失败的搜索请求
  • 网页网址无效
  • 网络连接问题

建筑学

该服务器由两个主要组件组成:

  1. TypeScript MCP Server:处理 MCP 协议通信并提供工具接口
  2. Python Flask 服务器:管理 Google API 交互和网页内容分析

执照

麻省理工学院

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

一个 MCP(模型上下文协议)服务器,提供 Google 搜索功能和网页内容分析工具。该服务器使 AI 模型能够以编程方式执行 Google 搜索并分析网页内容。

  1. Google Search MCP Server
    1. Features
    2. Prerequisites
    3. Installation
    4. Configuration
    5. Running the Server
    6. Available Tools
    7. Example Usage
    8. Getting Google API Credentials
    9. Error Handling
    10. Architecture
    11. License
ID: 8m8reyzrcd