Google Search MCP Server について
Google Search MCP Serverは、Google Custom Search APIを通じてAIアシスタントやMCPクライアントにウェブ検索と画像検索を提供します。最新情報の検索や画像の取得に対応し、ウェブ検索では件数やサイトを指定できます。
主な機能
- 01ウェブ検索
- 02画像検索
- 03検索件数とページ指定
- 04特定サイトに絞ったウェブ検索
活用シーン
- 01ウェブから最新情報を探す
- 02クエリに関連する画像を探す
- 03特定のウェブサイト内を検索
- 04AIの回答に使う検索結果を取得
MCP 対応
Google Custom Search APIを利用し、google_web_searchとgoogle_image_searchをMCPクライアント向けのツールとして提供します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
Google Search MCP Server
Google の Custom Search API を通じて、ウェブ検索と画像検索の機能を提供する Model Context Protocol(MCP)サーバーです。このサーバーは MCP 仕様に準拠しており、Claude やその他の AI アシスタントと連携できます。
構築するもの
多くの AI アシスタントには、最新情報やウェブを検索する機能がありません。この MCP サーバーは、次の 2 つのツールを提供することで、その問題を解決します。
google_web_search:最新情報をウェブで検索しますgoogle_image_search:クエリに関連する画像を検索します
MCP 対応クライアント(Cursor、VSCode、Claude Desktop の Claude など)に接続すると、AI アシスタントが検索を実行し、最新情報にアクセスできるようになります。
MCP の基本概念
MCP サーバーは AI アシスタントに機能を提供します。このサーバーでは、次の機能を実装しています。
- ツール:AI が呼び出せる関数(ユーザーの承認が必要です)
- 構造化された通信:MCP プロトコルによる標準化されたメッセージ形式
- トランスポート層:標準入出力による通信
前提条件
- Node.js(v18 以降)および npm
- Google Cloud Platform アカウント
- Google Custom Search API キーと Search Engine ID
- MCP 対応クライアント(Claude for Desktop、Cursor、Claude 搭載の VSCode など)
クイックスタート(このリポジトリをクローンする)
このサーバーを一から構築せずに使用する場合は、次の手順に従ってください。
# 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
Windows
# 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.ts
TypeScript の設定
ルートディレクトリに 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 のセットアップ
- Google Cloud Console にアクセスします
- 新しいプロジェクトを作成します
- Custom Search 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
Custom Search Engine のセットアップ
- Programmable Search Engine にアクセスします
- 「Add」をクリックして、新しい検索エンジンを作成します
- 「Search the entire web」を選択し、検索エンジンに名前を付けます
- コントロールパネルから Search Engine ID(cx 値)を取得します
環境設定
ルートディレクトリに .env ファイルを作成します。
GOOGLE_API_KEY=your_api_key_here
GOOGLE_CSE_ID=your_search_engine_id_here
認証情報を保護するため、.env を .gitignore ファイルに追加します。
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 サーバーはさまざまなクライアントに接続できます。よく使われるクライアントの設定手順を以下に示します。
Claude for Desktop
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"
}
}
}
}
Windows
- 設定ファイルを開きます。
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 for Desktop を再起動します
- インターフェースのツールアイコンをクリックして、ツールが表示されることを確認します
Claude 搭載の VSCode
macOS/Linux & Windows
- MCP Extension for VSCode をインストールします
- ワークスペースに
.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 でツールを利用できるようになります
Cursor
- Cursor の設定(歯車アイコン)を開きます
- 「MCP」を検索し、MCP の設定を開きます
- 「Add new MCP server」をクリックします
- 上記と同様の設定を行います:
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"
}
}
}
}
- Cursor を再起動します
サーバーのテスト
Claude での使用
接続したら、次のような質問を 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
内部での動作
質問すると、次の処理が行われます:
- クライアントが質問を Claude に送信します
- Claude が利用可能なツールを分析し、使用するツールを決定します
- クライアントが MCP サーバーを通じて選択されたツールを実行します
- 結果が Claude に返されます
- Claude が検索結果に基づいて自然言語で回答を作成します
- 回答が表示されます
トラブルシューティング
よくある問題
環境変数
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_here
API エラー
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 configuration
API リファレンス
google_web_search
Google Custom Search API を使用してウェブ検索を実行します。
パラメーター:
query(string、必須):検索クエリcount(number、任意):結果の件数(1~10、デフォルトは 5)start(number、任意):ページネーションの開始インデックス(デフォルトは 1)site(string、任意):検索対象を特定のサイトに限定します(例:'example.com')
google_image_search
Google Custom Search API を使用して画像を検索します。
パラメーター:
query(string、必須):画像検索クエリcount(number、任意):結果の件数(1~10、デフォルトは 5)start(number、任意):ページネーションの開始インデックス(デフォルトは 1)
制限事項
- Google Custom Search API の無料枠:1 日あたり 100 クエリ
- サーバー側で適用されるレート制限:毎秒 5 リクエスト
- 1 クエリあたりの最大結果数は 10 件(Google API の制限)
ライセンス
このプロジェクトは MIT License の下でライセンスされています。詳細は LICENSE ファイルを参照してください。
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。