Google Search MCP Server

Google Search MCP Server

Enables performing Google searches using the Custom Search Engine API with support for various parameters like date restriction, site search, and file type. Returns search results in a conversational format.

Category
访问服务器

README

Google Search MCP Server

This repository contains a Model Context Protocol (MCP) server that provides a tool-based interface to Google's Custom Search Engine (CSE) API. It is designed for use with MCP-compatible clients, such as those found in IDEs like Visual Studio Code, allowing developers and models to perform Google searches programmatically.

Features

  • Google Search Integration: Perform Google searches using the CSE API.
  • Expanded Search Parameters: Support for a wide range of search parameters, including dateRestrict, siteSearch, fileType, and more.
  • Flexible Configuration: Configure the server via environment variables or a .env file.
  • User-Friendly Tools: Provides a clear google_search tool with support for various search parameters.
  • Conversational Outputs: Returns search results in a conversational format, making it easy for clients to use the results.
  • Standalone and Asynchronous: The server runs as a standalone script and uses an asynchronous architecture for better performance.

Prerequisites

Before running the server, you need to have Python 3.12+ and uv installed. You will also need a Google API key and a Programmable Search Engine (CSE) ID. You will also need Node.js and npx to run the MCP Inspector tool for testing.

Installation

  1. Clone the repository.

    # Use gh cli to clone repository
    gh repo clone fvanevski/google_search_mcp
    
    # Alternateively, use git to clone repository
    # git clone https://github.com/fvanevski/google_search_mcp.git
    
    # Enter the repository directory
    cd google_search_mcp
    
  2. Create a virtual environment and install the required dependencies:

    # Create a virtual environment
    uv venv
    
    # Activate the virtual environment
    source .venv/bin/activate
    
    # Install the dependencies
    uv sync
    

Running and Testing the Server

The MCP server is a command-line application that communicates over standard I/O. To use it, a client (like an IDE, a coding agent, or an inspector tool) must launch the server process.

Running for Diagnostics

You can try to run the script directly from your terminal to see if it starts without errors. This is a quick way to validate your Python environment and the script's basic syntax.

python google_search_mcp.py

However, the server will simply start and wait for input, so you won't be able to interact with it directly from your terminal.

Testing with MCP Inspector

The recommended way to test the server interactively is with MCP Inspector. It runs as a command-line tool and provides an interactive shell for sending requests to your server.

  1. Launch the Inspector: You can run the inspector without a permanent installation using npx. The inspector will launch your MCP server script for you. From your project directory, run:

    # Run the inspector with `uv run --with <dependencies> -- python3 <script>`
    npx @modelcontextprotocol/inspector uv run --with requests,python-dotenv,pydantic,mcp -- python3 google_search_mcp.py
    

    Even if you have your virtual environment active, the python command as executed by the inspector will not correctly point to the interpreter with the necessary dependencies, thus we use uv instead with the --with flag.

  2. Interact with the Server: Once the inspector starts, you can click the "Connect" button to establish a session with your server. You can then use ommands like list_tools and call_tool to interact with it.

    Example session:

    # List all available tools
    > list_tools
    
    # Call the 'google_search' tool with arguments
    > call_tool google_search '''{"query": "AI news", "dateRestrict": "d7"}'''
    

    This provides a reliable way to test all the tools and verify that the server is working as expected.

Configuration

The server is configured using environment variables or a .env file in your project's root directory.

Environment Variables

  • GOOGLE_API_KEY: Your Google API key.
  • GOOGLE_CSE_ID: Your Custom Search Engine (CSE) ID.

Example .env file:

GOOGLE_API_KEY=your-secret-api-key
GOOGLE_CSE_ID=your-cse-id

Usage with an MCP Client (VS Code Example)

You can connect to this server from any standard MCP client. Here’s how to do it in a VS Code environment that supports MCP:

  1. Configure Your MCP Client: In your IDE's MCP client settings (e.g., in mcp.json for VS Code), configure a new MCP server that points to the script.

    Example mcp.json entry for VS Code:

    {
      "servers": {
        "google_search": {
          "command": "uv",
          "args": [
            "run",
            "python",
            "google_search_mcp.py"
          ],
          "cwd": "/path/to/your/project"
        }
      }
    }
    

    Note: Replace /path/to/your/project with the actual path to the project directory.

  2. Use the Tools: Once connected, you can use the exposed tools in your chat or agent interactions with natural language queries or structured calls. For example, to perform a Google search for recent PDF documents about machine learning, you could send the following structured tool call:

    {
      "tool": "google_search",
      "arguments": {
        "query": "machine learning",
        "dateRestrict": "m1",
        "fileType": "pdf"
      }
    }
    

    The server will execute the query and return the search results.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选