Google Search MCP Server
Google 検索 MCP サーバー
Google Custom Search API を通じてウェブ検索と画像検索機能を提供するモデルコンテキストプロトコル(MCP)サーバー。このサーバーは MCP 仕様に準拠しており、Claude やその他の AI アシスタントと統合できます。
私たちが構築するもの
多くのAIアシスタントは最新情報やウェブ検索機能を備えていません。このMCPサーバーは、以下の2つのツールを提供することでこの問題を解決します。
google_web_search: 最新情報をウェブで検索google_image_search: クエリに関連する画像を検索
MCP 対応クライアント (Claude in Cursor、VSCode、Claude Desktop など) に接続すると、AI アシスタントは検索を実行し、現在の情報にアクセスできるようになります。
Related MCP server: Google Search MCP Server
MCPコアコンセプト
MCPサーバーはAIアシスタントに機能を提供します。このサーバーは以下の機能を実装しています。
ツール:AIが呼び出せる機能(ユーザーの承認が必要)
構造化コミュニケーション:MCPプロトコルによる標準化されたメッセージング形式
トランスポート層: 標準入出力を介した通信
前提条件
Node.js (v18以上) と npm
Google Cloud Platform アカウント
Google カスタム検索 API キーと検索エンジン ID
MCP 互換クライアント (Claude for Desktop、Cursor、VSCode with Claude など)
クイックスタート(このリポジトリをクローンする)
このサーバーを最初から構築せずに使用したい場合は、次の手順に従ってください。
# Clone the repository
git clone https://github.com/yourusername/google-search-mcp-server.git
cd google-search-mcp-server
# Install dependencies
npm install
# Set up your environment variables
# Setup .env file in the root folder of the project
# On macOS/Linux
touch .env
# On Windows
new-item .env
# Edit .env file to add your Google API credentials
# Use any text editor you prefer (VS Code, Notepad, nano, vim, etc.)
# Add these to your newly created .env
GOOGLE_API_KEY=your_api_key_here
GOOGLE_CSE_ID=your_search_engine_id_here
# Build the server
npm run build
# Test the server (optional)
# On macOS/Linux
echo '{"jsonrpc":"2.0","method":"listTools","id":1}' | node dist/index.js
# On Windows PowerShell
echo '{"jsonrpc":"2.0","method":"listTools","id":1}' | node dist/index.js
# On Windows CMD
echo {"jsonrpc":"2.0","method":"listTools","id":1} | node dist/index.jsビルド後、 「MCP クライアントへの接続」セクションに従って、サーバーを優先クライアントに接続します。
環境を設定する(ゼロから構築)
自分でサーバーを最初から構築したい場合は、次の手順に従ってください。
プロジェクト構造を作成する
macOS/Linux
# Create a new directory for our project
mkdir google-search-mcp
cd google-search-mcp
# Initialize a new npm project
npm init -y
# Install dependencies
npm install @modelcontextprotocol/sdk dotenv zod
npm install -D @types/node typescript
# Create our files
mkdir src
touch src/index.tsウィンドウズ
# Create a new directory for our project
md google-search-mcp
cd google-search-mcp
# Initialize a new npm project
npm init -y
# Install dependencies
npm install @modelcontextprotocol/sdk dotenv zod
npm install -D @types/node typescript
# Create our files
md src
new-item src\index.tsTypeScriptの設定
ルート ディレクトリにtsconfig.jsonを作成します。
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}package.json を更新する
package.jsonに以下が含まれていることを確認します。
{
"name": "google_search_mcp",
"version": "0.1.0",
"description": "MCP server for Google Custom Search API integration",
"license": "MIT",
"type": "module",
"bin": {
"google_search": "./dist/index.js"
},
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"build:unix": "tsc && chmod 755 dist/index.js",
"prepare": "npm run build",
"watch": "tsc --watch",
"start": "node dist/index.js"
}
}Google API のセットアップ
Google Cloud Platform を設定し、API 認証情報を取得する必要があります。
Google Cloud Platform のセットアップ
新しいプロジェクトを作成する
カスタム検索 API を有効にします。
Navigate to "APIs & Services" → "Library" Search for "Custom Search API" Click on "Custom Search API" → "Enable"API 資格情報を作成します。
Navigate to "APIs & Services" → "Credentials" Click "Create Credentials" → "API key" Copy your API key
カスタム検索エンジンの設定
「追加」をクリックして新しい検索エンジンを作成します
「ウェブ全体を検索」を選択し、検索エンジンに名前を付けます
コントロールパネルから検索エンジンID(cx値)を取得します
環境設定
ルート ディレクトリに.envファイルを作成します。
GOOGLE_API_KEY=your_api_key_here
GOOGLE_CSE_ID=your_search_engine_id_here資格情報を保護するために、 .gitignoreファイルに.envを追加します。
echo ".env" >> .gitignoreサーバーの構築
サーバー実装を作成する
src/index.tsにサーバー実装を作成します。
import dotenv from "dotenv"
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
Tool,
} from "@modelcontextprotocol/sdk/types.js";
dotenv.config();
// Define your tools
const WEB_SEARCH_TOOL: Tool = {
name: "google_web_search",
description: "Performs a web search using Google's Custom Search API...",
inputSchema: {
// Schema details here
},
};
const IMAGE_SEARCH_TOOL: Tool = {
name: "google_image_search",
description: "Searches for images using Google's Custom Search API...",
inputSchema: {
// Schema details here
}
};
// Server implementation
const server = new Server(
{
name: "google-search",
version: "0.1.0",
},
{
capabilities: {
tools: {},
},
},
);
// Check for API key and Search Engine ID
const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY!;
const GOOGLE_CSE_ID = process.env.GOOGLE_CSE_ID!;
if (!GOOGLE_API_KEY || !GOOGLE_CSE_ID) {
console.error("Error: Missing environment variables");
process.exit(1);
}
// Tool handlers
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [WEB_SEARCH_TOOL, IMAGE_SEARCH_TOOL],
}));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
// Implement tool handlers
});
// Run the server
async function runServer() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("Google Search MCP Server running on stdio");
}
runServer().catch((error) => {
console.error("Fatal error running server:", error);
process.exit(1);
});完全な実装の詳細については、リポジトリ ファイルを参照してください。
サーバーの構築
実装が完了したら、サーバーを構築します。
npm run buildこれにより、TypeScript コードがdistディレクトリ内の JavaScript にコンパイルされます。
MCPクライアントへの接続
MCPサーバーは様々なクライアントに接続できます。一般的なクライアントの設定手順は以下のとおりです。
デスクトップ版クロード
macOS/Linux
設定ファイルを開きます:
code ~/Library/Application\ Support/Claude/claude_desktop_config.jsonサーバー構成を追加します。
{
"mcpServers": {
"google_search": {
"command": "node",
"args": [
"/absolute/path/to/google-search-mcp/dist/index.js"
],
"env": {
"GOOGLE_API_KEY": "your_api_key_here",
"GOOGLE_CSE_ID": "your_search_engine_id_here"
}
}
}
}ウィンドウズ
設定ファイルを開きます:
code $env:AppData\Claude\claude_desktop_config.jsonサーバー構成を追加します。
{
"mcpServers": {
"google_search": {
"command": "node",
"args": [
"C:\\absolute\\path\\to\\google-search-mcp\\dist\\index.js"
],
"env": {
"GOOGLE_API_KEY": "your_api_key_here",
"GOOGLE_CSE_ID": "your_search_engine_id_here"
}
}
}
}デスクトップ版のClaudeを再起動
インターフェースのツールアイコンをクリックしてツールが表示されていることを確認します
クロードとVSCode
macOS/Linux および Windows
VSCode用のMCP拡張機能をインストールする
ワークスペースで
.vscode/settings.jsonを作成または編集します。
macOS/Linuxの場合:
{
"mcp.servers": {
"google_search": {
"command": "node",
"args": [
"/absolute/path/to/google-search-mcp/dist/index.js"
],
"env": {
"GOOGLE_API_KEY": "your_api_key_here",
"GOOGLE_CSE_ID": "your_search_engine_id_here"
}
}
}
}Windowsの場合:
{
"mcp.servers": {
"google_search": {
"command": "node",
"args": [
"C:\\absolute\\path\\to\\google-search-mcp\\dist\\index.js"
],
"env": {
"GOOGLE_API_KEY": "your_api_key_here",
"GOOGLE_CSE_ID": "your_search_engine_id_here"
}
}
}
}VSCodeを再起動します
これらのツールはVSCodeでClaudeが利用できるようになります。
カーソル
カーソル設定を開く(歯車アイコン)
「MCP」を検索し、MCP設定を開きます
「新しいMCPサーバーを追加」をクリックします
上記と同様の設定で構成します。
macOS/Linuxの場合:
{
"mcpServers": {
"google_search": {
"command": "node",
"args": [
"/absolute/path/to/google-search-mcp/dist/index.js"
],
"env": {
"GOOGLE_API_KEY": "your_api_key_here",
"GOOGLE_CSE_ID": "your_search_engine_id_here"
}
}
}
}Windowsの場合:
{
"mcpServers": {
"google_search": {
"command": "node",
"args": [
"C:\\absolute\\path\\to\\google-search-mcp\\dist\\index.js"
],
"env": {
"GOOGLE_API_KEY": "your_api_key_here",
"GOOGLE_CSE_ID": "your_search_engine_id_here"
}
}
}
}カーソルを再開
サーバーのテスト
クロードと一緒に使う
接続したら、次のような質問をして Claude にツールをテストできます。
「再生可能エネルギーに関する最新ニュースを検索」
「電気自動車の画像を探す」
「日本で最も人気のある観光地はどこですか?」
Claude は必要に応じて適切な検索ツールを自動的に使用します。
手動テスト
サーバーを直接テストすることもできます。
# Test web search
echo '{
"jsonrpc": "2.0",
"method": "callTool",
"params": {
"name": "google_web_search",
"arguments": {
"query": "test query",
"count": 2
}
},
"id": 1
}' | node dist/index.jsボンネットの下で何が起こっているのか
質問するときは:
クライアントがあなたの質問をクロードに送ります
クロードは利用可能なツールを分析し、どれを使用するかを決定します
クライアントはMCPサーバーを通じて選択したツールを実行します。
結果はクロードに送り返される
クロードは検索結果に基づいて自然言語応答を作成します
応答が表示されます
トラブルシューティング
よくある問題
環境変数
Error: GOOGLE_API_KEY environment variable is required :
# Check your .env file
cat .env
# Try setting environment variables directly:
export GOOGLE_API_KEY=your_key_here
export GOOGLE_CSE_ID=your_id_hereAPIエラー
API エラーが発生した場合:
# Test your API credentials directly
curl "https://www.googleapis.com/customsearch/v1?key=YOUR_API_KEY&cx=YOUR_CX_ID&q=test"接続の問題
クライアントがサーバーに接続できない場合:
# Verify the server runs correctly on its own
node dist/index.js
# Check file permissions
chmod 755 dist/index.js
# Ensure you're using absolute paths in your configurationAPIリファレンス
google_web_search
Google のカスタム検索 API を使用して Web 検索を実行します。
パラメータ:
query(文字列、必須): 検索クエリcount(数値、オプション): 結果の数 (1-10、デフォルトは5)start(数値、オプション):ページネーションの開始インデックス(デフォルトは1)site(文字列、オプション):検索を特定のサイトに制限します(例:'example.com')
google_image_search
Google のカスタム検索 API を使用して画像を検索します。
パラメータ:
query(文字列、必須): 画像検索クエリcount(数値、オプション): 結果の数 (1-10、デフォルトは5)start(数値、オプション):ページネーションの開始インデックス(デフォルトは1)
制限事項
Google カスタム検索 API の無料枠: 1 日あたり 100 クエリ
サーバーによるレート制限: 1 秒あたり 5 リクエスト
クエリごとに最大 10 件の結果 (Google API の制限)
ライセンス
このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細については LICENSE ファイルを参照してください。
Available Tools
2 toolsgoogle_image_searchB
Searches for images using Google's Custom Search API. Best for finding images related to specific terms, concepts, or objects. Returns image URLs, titles, and thumbnails. Use this when needing to find relevant images or visual references.
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of results (1-10, default 5) | |
| query | Yes | Image search query | |
| start | No | Pagination start index (default 1) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the API source and return values (image URLs, titles, thumbnails) but lacks details on rate limits, authentication needs, error handling, or whether this is a read-only operation. For a search tool with external API dependencies, this leaves significant behavioral gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is appropriately sized and front-loaded: it starts with the core purpose, adds context about best use cases, specifies return values, and ends with usage guidance. Every sentence adds value without redundancy, making it efficient and well-structured.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's moderate complexity (external API search with 3 parameters) and no annotations or output schema, the description is partially complete. It covers purpose, usage, and returns but lacks behavioral details like rate limits or error handling. It's adequate for basic use but insufficient for robust agent operation without additional context.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, so the schema already documents all three parameters (count, query, start) with their types, defaults, and constraints. The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high schema coverage.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Searches for images using Google's Custom Search API' with specific resources (image URLs, titles, thumbnails) and distinguishes it from the sibling google_web_search by focusing on images rather than general web content. However, it doesn't explicitly name the sibling for comparison.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides implied usage guidance: 'Best for finding images related to specific terms, concepts, or objects' and 'Use this when needing to find relevant images or visual references.' It suggests when to use it but doesn't explicitly mention when not to use it or directly compare it to the sibling google_web_search.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
google_web_searchA
Performs a web search using the Google Custom Search API, ideal for general queries, news, articles, and online content. Use this for broad information gathering, recent events, or when you need diverse web sources. Supports pagination and filtering by site or type. Maximum 10 results per request, with start index for pagination.
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of results (1-10, default 5) | |
| query | Yes | Search query | |
| site | No | Optional: Limit search to specific site (e.g., 'site:example.com') | |
| start | No | Pagination start index (default 1) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions key behavioral traits: 'maximum 10 results per request', 'supports pagination and filtering by site or type', and 'start index for pagination'. However, it doesn't cover important aspects like rate limits, authentication requirements, error conditions, or what the response format looks like.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is efficiently structured in three sentences that each serve distinct purposes: stating the core functionality, providing usage guidance, and disclosing behavioral constraints. Every sentence earns its place with no redundant information, making it appropriately sized and front-loaded.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a search tool with 4 parameters, 100% schema coverage, but no annotations and no output schema, the description provides adequate context about what the tool does and when to use it. However, it lacks information about the response format, error handling, and operational constraints like rate limits, which would be important for an API-based search tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
With 100% schema description coverage, the input schema already documents all 4 parameters thoroughly. The description adds minimal value beyond what's in the schema - it mentions 'filtering by site or type' and 'pagination' which map to the 'site' and 'start' parameters, but doesn't provide additional semantic context beyond what the schema descriptions already offer.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool 'performs a web search using the Google Custom Search API' with specific examples of use cases (general queries, news, articles, online content). It distinguishes from the sibling tool 'google_image_search' by specifying this is for web content rather than images. However, it doesn't explicitly contrast with the sibling beyond the domain difference.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides clear context for when to use this tool ('broad information gathering, recent events, or when you need diverse web sources'), which implicitly distinguishes it from the image search sibling. It doesn't explicitly state when NOT to use it or name alternatives beyond the implied contrast with image search.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
2 tool updates
v1.0.0- First observed
google_image_search - First observed
google_web_search
TDQS
Scored across 2 tools
The two tools have clearly distinct purposes: google_image_search is for finding images, while google_web_search is for general web content like articles and news. There is no overlap in functionality, making it easy for an agent to choose the correct tool based on the need for visual vs. textual information.
Both tools follow a consistent verb_noun pattern with 'google_' prefix and descriptive suffixes (_image_search, _web_search). The naming is uniform and predictable, adhering to snake_case throughout without any deviations or mixed conventions.
With only 2 tools, the server is minimal but reasonable for a search-focused domain, covering image and web searches. It might feel slightly thin if broader search capabilities (e.g., video, news-specific) were expected, but it's well-scoped for basic search needs without being overloaded.
For a Google Search server, the tools cover the core search operations: image and web searches. Minor gaps exist, such as lack of specialized search types (e.g., video, scholarly articles) or advanced filtering options, but agents can work around this with the provided tools for most common queries.
Maintenance
Related MCP Connectors
MCP server for Google search results via SERP API
Live AI-native web search with citations. One tool for every MCP client. Flat per-request pricing.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables LLMs to perform web searches using Google's Custom Search API through a standardized interface.147MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables Claude to perform Google Custom Search operations by connecting to Google's search API.2MIT
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables Claude to perform web research by integrating Google search, extracting webpage content, and capturing screenshots.31,175 npm20MIT
- AlicenseAqualityCmaintenanceA Model Context Protocol server that enables Claude to perform web research by integrating Google search, extracting webpage content, and capturing screenshots in real-time.41,175 npm9MIT