MCP HubMCP Hub
mixelpixx

Google-Search-MCP-Server

by: mixelpixx

MCP Server built for use with VS Code / Cline / Anthropic - enable google search and ability to follow links and research websites

39created 19/12/2024
Visit
VS Code
Anthropic

📌Overview

Purpose: To provide a Model Context Protocol (MCP) server that enables AI models to perform Google searches and analyze webpage content programmatically.

Overview: The Google Search MCP Server is designed to enhance the capabilities of AI assistants by integrating robust search and content extraction features. Through a seamless interface, users can conduct advanced searches and process webpage content efficiently, adhering to the MCP standards.

Key Features:

  • Advanced Google Search: Offers comprehensive search capabilities with filters for date, language, country, and safe search, allowing for targeted information retrieval.

  • Detailed Webpage Content Extraction: Facilitates the analysis of webpage content, extracting readable text while eliminating unnecessary clutter, thereby enhancing the relevance of returned information.

  • Batch Webpage Analysis: Allows users to analyze multiple sources simultaneously, making it ideal for comparing information or gathering extensive data on specific topics.

  • API Credential Management: Supports environment variable configuration for easy integration and credential management, streamlining the setup process.

  • MCP Compliance: Ensures smooth integration with AI assistants, supporting effective interaction between various components.


Google Search MCP Server

An MCP (Model Context Protocol) server that provides Google search capabilities and webpage content analysis tools. This server enables AI models to perform Google searches and analyze webpage content programmatically.

Features

  • Advanced Google Search with filtering options (date, language, country, safe search)
  • Detailed webpage content extraction and analysis
  • Batch webpage analysis for comparing multiple sources
  • Environment variable support for API credentials
  • Comprehensive error handling and user feedback

Prerequisites

  • Node.js (v16 or higher)
  • Python (v3.8 or higher)
  • Google Cloud Platform account
  • Custom Search Engine ID
  • Google API Key

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/google-search-mcp.git
    cd google-search-mcp
    
  2. Install Node.js dependencies:

    npm install
    
  3. Install Python dependencies:

    pip install flask google-api-python-client flask-cors beautifulsoup4 trafilatura markdownify
    
  4. Build the TypeScript code:

    npm run build
    

Configuration

API Credentials

You can provide Google API credentials in two ways:

  1. Environment Variables (Recommended):

    • Set GOOGLE_API_KEY and GOOGLE_SEARCH_ENGINE_ID in your environment.
  2. Configuration File:

    • Create an api-keys.json file in the root directory:
    {
        "api_key": "your-google-api-key",
        "search_engine_id": "your-custom-search-engine-id"
    }
    

MCP Settings Configuration

Add the server configuration to your MCP settings file.

For Cline (VS Code Extension)

File location: %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"],
      "env": {
        "GOOGLE_API_KEY": "your-google-api-key",
        "GOOGLE_SEARCH_ENGINE_ID": "your-custom-search-engine-id"
      },
      "disabled": false
    }
  }
}

Running the Server

Method 1: Start Python Servers Separately (Recommended)

  1. Start the Python servers using the helper script:

    start-python-servers.cmd
    
  2. Configure the MCP settings to run the Node.js server:

    {
      "command": "C:\\Program Files\\nodejs\\node.exe",
      "args": ["C:\\path\\to\\google-search-mcp\\dist\\google-search.js"]
    }
    

Method 2: All-in-One Script

Start both the TypeScript and Python servers with a single command:

npm run start:all

Available Tools

1. google_search

Search Google and return relevant results.

{
  "name": "google_search",
  "arguments": {
    "query": "your search query",
    "num_results": 5, // optional
    "date_restrict": "w1", // optional
    "language": "en", // optional
    "country": "us", // optional
    "safe_search": "medium" // optional
  }
}

2. extract_webpage_content

Extract and analyze content from a webpage.

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

3. extract_multiple_webpages

Extract and analyze content from multiple webpages.

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

Example Usage

  • 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.

Getting Google API Credentials

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing one.
  3. Enable the Custom Search API.
  4. Create API credentials (API Key).
  5. Create a new search engine and get your Search Engine ID.
  6. Add these credentials to your api-keys.json file.

Error Handling

The server provides detailed error messages for missing or invalid API credentials, failed search requests, invalid webpage URLs, and network connectivity issues.

Architecture

The server consists of two main components:

  1. TypeScript MCP Server: Handles MCP protocol communication and provides the tool interface.
  2. Python Flask Server: Manages Google API interactions and webpage content analysis.

License

MIT