Provides Google Custom Search functionality, allowing AI agents to perform web searches using Google's search engine API
Google Search MCP Server
A Model Context Protocol (MCP) server that provides Google Custom Search functionality.
Configuration
This server uses Dynaconf for configuration management, supporting both .env
files and environment variables.
Setup
Copy the example environment file:
cp .env.example .envEdit
.env
and add your Google API credentials:GOOGLE_API_KEY=your_actual_api_key_here GOOGLE_CX=your_custom_search_engine_id_here
Environment Variable Override
Environment variables will override .env
file values when both are present. This allows for flexible deployment scenarios:
Development: Use
.env
file for local developmentProduction: Use environment variables for production deployment
CI/CD: Environment variables can override defaults for testing
Example:
If your .env
file contains:
And you set an environment variable:
The server will use prod_key_from_env
(environment variable takes precedence).
Required Configuration
GOOGLE_API_KEY
: Your Google Custom Search API keyGOOGLE_CX
: Your Custom Search Engine ID
Get these from:
API Key: Google Cloud Console
Search Engine ID: Google Custom Search
Optional Configuration
ALLOW_DOMAINS
(GOOGLE_ALLOW_DOMAINS
env var): Comma-separated list of allowed domains (e.g.,example.com, docs.python.org
). When set, results outside these domains are filtered out.
Usage
Run the server:
Quick start
This project uses httpx with HTTP/2 support enabled for better performance. The dependency is declared as httpx[http2]
and will install the h2
package automatically when you sync the environment.
Using uv (recommended)
Try it quickly (no MCP client required)
You can also call the tool function directly for a quick smoke test (uses your env vars):
Note: When using the MCP server with a client, the search
tool parameters follow Google CSE semantics. In particular, safe
must be one of off
or active
, and num
is clamped to the CSE maximum of 10.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables users to perform Google Custom Search queries through the Model Context Protocol. Requires Google API credentials and Custom Search Engine configuration for web search functionality.