[![Node.js](https://img.shields.io/badge/Node.js-18%2B-339933?style=for-the-badge&logo=nodedotjs&logoColor=white)](https://nodejs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-3178C6?style=for-the-badge&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![MCP](https://img.shields.io/badge/Protocol-MCP-8A2BE2?style=for-the-badge&logo=protocolsdotio&logoColor=white)](https://modelcontextprotocol.io/) [![Google Custom Search](https://img.shields.io/badge/Google-Custom%20Search%20API-4285F4?style=for-the-badge&logo=google&logoColor=white)](https://programmablesearchengine.google.com/) [![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![Listed on mcpservers.org](https://mcpservers.org/badge.svg)](https://mcpservers.org/servers/hasinduudara/google-search-mcp.git) ### ๐Ÿ” An MCP server that lets any MCP-compatible AI client search the live web through Google's Custom Search JSON API โ€” over stdio, plug-and-play.
--- ## ๐Ÿงญ Table of Contents - [๐Ÿงญ Table of Contents](#-table-of-contents) - [โœจ Overview](#-overview) - [โš™๏ธ Requirements](#๏ธ-requirements) - [๐Ÿ”ง Google Custom Search Setup](#-google-custom-search-setup) - [โš ๏ธ Rate Limits \& Quota](#๏ธ-rate-limits--quota) - [๐Ÿ“ฆ Installation](#-installation) - [โ–ถ๏ธ Run](#๏ธ-run) - [๐Ÿณ Run with Docker](#-run-with-docker) - [Point your MCP client to Docker](#point-your-mcp-client-to-docker) - [๐Ÿ”Œ MCP Client Configuration](#-mcp-client-configuration) - [๐Ÿงฉ Using This Server in Your Own Project](#-using-this-server-in-your-own-project) - [๐Ÿ› ๏ธ Available Tool](#๏ธ-available-tool) - [`search_google`](#search_google) - [๐Ÿงช Test with MCP Inspector](#-test-with-mcp-inspector) - [๐Ÿ“ Project Structure](#-project-structure) - [๐Ÿค Contributing](#-contributing) - [๐Ÿ“„ License](#-license) - [๐Ÿ‘ค Author](#-author) --- ## โœจ Overview > This server bridges the gap between **AI agents** and **real-time web knowledge**. > It speaks the **Model Context Protocol (MCP)** over stdio, so any compatible client can call a single tool โ€” `search_google` โ€” and get back clean, structured search results straight from Google. ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” stdio (MCP) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” HTTPS โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ MCP Client โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ Google Search MCP โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ Google Custom โ”‚ โ”‚ (Claude, etc.) โ”‚ โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ Server โ”‚ โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ Search JSON API โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ results โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ results โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` --- ## โš™๏ธ Requirements | Requirement | Details | |---|---| | ๐ŸŸข **Node.js** | v18 or newer | | ๐Ÿ”‘ **Google API Key** | With access to the Custom Search JSON API | | ๐Ÿ†” **Search Engine ID** | From a Google Programmable Search Engine (`cx`) | --- ## ๐Ÿ”ง Google Custom Search Setup 1. **Create a project** in the [Google Cloud Console](https://console.cloud.google.com/) 2. **Enable** the `Custom Search API` for that project 3. **Generate** an API key 4. **Create** a [Programmable Search Engine](https://programmablesearchengine.google.com/) and copy its **Search Engine ID** --- ## โš ๏ธ Rate Limits & Quota The Google Custom Search JSON API's **free tier allows 100 queries per day**. Once that limit is hit, the API returns a `429` error and `search_google` will respond with an error message instead of results. - Need more? You can enable billing on your Google Cloud project for up to 10,000 queries/day (paid, per-query pricing). - Check your current usage in the [Google Cloud Console](https://console.cloud.google.com/) under **APIs & Services โ†’ Custom Search API โ†’ Quotas**. --- ## ๐Ÿ“ฆ Installation ```bash npm install ``` Create a `.env` file in the project root: ```env GOOGLE_API_KEY=your_google_api_key SEARCH_ENGINE_ID=your_search_engine_id ``` > โš ๏ธ **Never commit `.env`** or expose your API key in source control. --- ## โ–ถ๏ธ Run **Development** (run TypeScript directly): ```bash npm start ``` **Production** (build then run compiled output): ```bash npm run build node build/index.js ``` > โ„น๏ธ The server logs status and errors to `stderr`, keeping `stdout` clean for MCP protocol messages. --- ## ๐Ÿณ Run with Docker Prefer containers? You can build and run this server without installing Node.js locally. **Build the image:** ```bash docker build -t google-search-mcp . ``` **Run it** (make sure your `.env` file is set up first โ€” see [Installation](#-installation)): ```bash docker run -i --rm --env-file .env google-search-mcp ``` > โš ๏ธ The `-i` flag is required โ€” this is a stdio-based MCP server and needs an interactive stream to communicate with the client. **Or use Docker Compose:** ```yaml services: google-search-mcp: build: . stdin_open: true tty: true env_file: - .env ``` ```bash docker compose up --build ``` ### Point your MCP client to Docker ```json { "mcpServers": { "google-search": { "command": "docker", "args": ["run", "-i", "--rm", "--env-file", ".env", "google-search-mcp"] } } } ``` ## ๐Ÿ”Œ MCP Client Configuration After building the project, register the server with an MCP-compatible client using the compiled entry point: ```json { "mcpServers": { "google-search": { "command": "node", "args": ["/absolute/path/to/Google-Search-MCP/build/index.js"], "env": { "GOOGLE_API_KEY": "your_google_api_key", "SEARCH_ENGINE_ID": "your_search_engine_id" } } } } ``` Or keep credentials in the project's `.env` and launch from the project directory: ```json { "mcpServers": { "google-search": { "command": "node", "args": ["/absolute/path/to/Google-Search-MCP/build/index.js"] } } } ``` --- ## ๐Ÿงฉ Using This Server in Your Own Project This server isn't tied to any single client โ€” any MCP-compatible host can spawn it and call `search_google`. To use it elsewhere: 1. **Clone and build** this repo (or pull the Docker image โ€” see [Run with Docker](#-run-with-docker)). 2. **Point your MCP client's config** at the built entry point (`build/index.js`) or the Docker command, using the same JSON shown in [MCP Client Configuration](#-mcp-client-configuration). 3. **Supported clients** โ€” any tool that speaks MCP over stdio works, including: - Claude Desktop - [Cursor](https://www.cursor.com/) (`.cursor/mcp.json`) - [Cline](https://github.com/cline/cline) (VS Code extension settings) - Custom agents built with the [MCP SDK](https://modelcontextprotocol.io/) directly 4. **Calling it programmatically** โ€” if you're building your own MCP client/agent in code, connect an MCP `Client` over `StdioClientTransport` pointed at `build/index.js`, then call the `search_google` tool like any other MCP tool. See the [MCP TypeScript SDK docs](https://modelcontextprotocol.io/) for client-side examples. > Each client has its own config file location and format for `mcpServers` โ€” check that client's docs for exactly where to paste the JSON block. --- ## ๐Ÿ› ๏ธ Available Tool ### `search_google` Searches Google Custom Search for the supplied query and returns the **top 3 results**. **Input** ```json { "query": "latest TypeScript release" } ``` **Output** Each result includes: - ๐Ÿ“Œ `title` - ๐Ÿ”— `link` - ๐Ÿ“ `snippet` If nothing is found, the tool responds with `No results found.` --- ## ๐Ÿงช Test with MCP Inspector ```bash npm run build npx @modelcontextprotocol/inspector node build/index.js ``` > Make sure your environment variables are set before launching the inspector. --- ## ๐Ÿ“ Project Structure ```text ๐Ÿ“ฆ Google-Search-MCP โ”œโ”€โ”€ ๐Ÿ“‚ src โ”‚ โ””โ”€โ”€ index.ts # MCP server implementation โ”œโ”€โ”€ ๐Ÿ“‚ build # Compiled JavaScript and type declarations โ”œโ”€โ”€ .env # Local environment config (not committed) โ””โ”€โ”€ README.md ``` --- ## ๐Ÿค Contributing Contributions, bug reports, and feature requests are welcome! - **Found a bug or have an idea?** [Open an issue](../../issues) describing it. - **Want to contribute code?** 1. Fork the repo 2. Create a branch (`git checkout -b feature/your-feature`) 3. Make your changes and test locally (`npm start` or `docker compose up --build`) 4. Commit and push, then open a Pull Request Please keep PRs focused โ€” one feature or fix per PR makes review easier. --- ## ๐Ÿ“„ License This project is licensed under the [MIT License](LICENSE). ---
[![Listed on mcpservers.org](https://mcpservers.org/badge.svg)](https://mcpservers.org/servers/hasinduudara/google-search-mcp.git) ## ๐Ÿ‘ค Author
**M. Hasindu Udara** Full-Stack Developer [![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/hasindu-udara)