Skip to main content
Glama

GA4 MCP Server

プロダクション対応、マルチテナントのGoogle Analytics 4 MCPサーバー(Claude用)。

これはより大きなプラットフォームにおける最初のコネクターです。共有インフラ(認証、クライアント、Google OAuthトークンストレージ、認可、ログ、エラー)は再利用可能です。GA4固有のコードはsrc/connectors/ga4src/mcp/ga4に置かれます。これをモノリシックなGoogle Marketing MCPとして扱わないでください。

アーキテクチャ

Claude
  |  MCP OAuth 2.1 + Streamable HTTP
  v
Next.js / Vercel  (/mcp)
  |-- MCP tools (ga4_*)
  |-- Authorization (client_members only)
  |-- GA4 service
  |-- Google OAuth token manager
  v
Supabase
  |-- clients
  |-- client_members   (application identity)
  |-- google_connections (Google credential, not app identity)
  |-- ga4_properties

アプリケーションユーザーはSupabase Authユーザーです。テナントアクセスはのみclient_members(user_id, client_id, role)です。Google接続アカウントはクライアント所有の認証情報であり、アプリケーションユーザーになることはありません。

ローカルセットアップ

npm install
cp .env.example .env.local
# fill in the values documented below
npx supabase start   # or link a remote project
npx supabase db reset --local
npm run dev

http://localhost:3000を開き、アプリケーションアカウントを作成し、クライアントを作成して、Google Analyticsに接続します。

Google Cloudセットアップ

  1. Google Cloudプロジェクトを作成または選択します。

  2. Google Analytics Data APIGoogle Analytics Admin APIを有効にします。

  3. OAuth同意画面を構成します(外部または内部)。

  4. OAuth 2.0 クライアントID認証情報(ウェブアプリケーション)を作成します。

  5. 認証済みリダイレクトURI:

    • ローカル:http://localhost:3000/api/auth/google/callback

    • プロダクション:https://<your-domain>/api/auth/google/callback

  6. GA4スコープのみをリクエストします:

    • https://www.googleapis.com/auth/analytics.readonly

    • openid

    • email

このコネクターにDV360またはGoogle Adsのスコープを追加しないでください。

GA4セットアップ

  1. このアプリにメール/パスワードでサインインします(アプリケーションID)。

  2. クライアントを作成します(client_membersownerになります)。

  3. 他のアプリケーションユーザーをownerまたはmemberとして追加できます。

  4. Google Analyticsに接続をクリックします。これにより、Google認証情報がクライアントにアタッチされます。

  5. そのGoogleアカウントから見つかった1つ以上のGA4プロパティをリンクします。

「Connect」をクリックしなかったメンバーでも、client_members行があればクエリを実行できます。

Supabaseセットアップ

このリポジトリにはsupabase/migrationsにSQLマイグレーションが含まれています。CLIで作成してください。ファイル名を独自に発明しないでください。

ローカル:

npx supabase start
npx supabase db reset --local

リモート:

npx supabase link --project-ref <project-ref>
npx supabase db push

サービスロールキーはサーバー専用です。SUPABASE_SERVICE_ROLE_KEYやGoogleリフレッシュトークンをブラウザに公開しないでください。

環境変数

.env.exampleを参照してください。必須:

変数

目的

NEXT_PUBLIC_SUPABASE_URL

SupabaseプロジェクトURL

NEXT_PUBLIC_SUPABASE_ANON_KEY

ブラウザ/サーバーユーザークライアント

SUPABASE_SERVICE_ROLE_KEY

サーバー側管理(決してNEXT_PUBLIC_にしない)

GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET

Google OAuthアプリ

GOOGLE_REDIRECT_URI

Google Cloudと一致する必要あり

GOOGLE_OAUTH_SCOPES

GA4のみのスコープ

MCP_BASE_URL

公開オリジン、例:https://your-app.vercel.app

MCP_TOKEN_SIGNING_SECRET

MCPアクセストークンへの署名

TOKEN_ENCRYPTION_KEY

Googleトークン暗号化用の64 hex文字(32バイト)

.envにGA4プロパティIDを入れないでください。プロパティはSupabaseのクライアントに属します。

トークン暗号化キーを生成:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

MCPセットアップ(Claude)

リモートエンドポイント:

https://<your-domain>/mcp

このサーバーはMCP OAuth 2.1を実装しています:

  • 保護リソースメタデータ:/.well-known/oauth-protected-resource

  • 認可サーバーメタデータ:/.well-known/oauth-authorization-server

  • 認可:/oauth/authorize(アプリケーションログイン + 同意)

  • トークン:/oauth/token(authorization_code + refresh_token、PKCE S256)

  • 登録:/oauth/register(DCRフォールバック)

  • CIMDがアドバタイズされます(client_id_metadata_document_supported

Claudeで:設定 → コネクター → カスタムコネクターを追加https://<your-domain>/mcpを貼り付けます。ClaudeがOAuthを実行します。承認後、ツールが利用可能になります。

ローカルインスペクター:

npx @modelcontextprotocol/inspector

Streamable HTTPでhttp://localhost:3000/mcpに接続します。それでもOAuthフローからの有効なMCP Bearerトークンが必要です。

ツール

ツール

目的

ga4_run_report

プライマリレポート(日付、指標、ディメンション、制限、順序、基本フィルター)

ga4_realtime

リアルタイムのアクティブユーザー / トラフィックの内訳

ga4_metadata

プロパティの指標とディメンションを発見

ga4_list_properties

クライアントのGoogle接続から見えるプロパティ

ga4_compare_periods

現在の期間と前の期間の絶対値/変化率の比較

すべてのツールはclient_idを必要とします。プロパティスコープのツールはリンクされたproperty_idも必要とします。認可は常にGoogleが呼び出される前にclient_membersをチェックします。

例:ga4_run_report

{
  "client_id": "11111111-1111-1111-1111-111111111111",
  "property_id": "123456789",
  "date_start": "2026-08-01",
  "date_end": "2026-08-15",
  "dimensions": ["country"],
  "metrics": ["activeUsers", "sessions", "totalRevenue"],
  "limit": 10
}

例:ga4_compare_periods

{
  "client_id": "11111111-1111-1111-1111-111111111111",
  "property_id": "123456789",
  "current_start": "2026-08-01",
  "current_end": "2026-08-15",
  "previous_start": "2026-07-17",
  "previous_end": "2026-07-31",
  "metrics": ["activeUsers", "sessions", "totalRevenue"]
}

すると、Claudeは次のような質問に答えることができます:

  • 昨日のユーザー数は?

  • 今月のトップ10カ国

  • 今月と先月の比較

  • 現在サイトにアクティブユーザーは何人?

テスト

npm test

テストはモックされたGoogleとSupabaseを使用します。プロダクションのOAuthトークンは決して使用しません。

Vercel

Next.jsアプリをデプロイし、同じ環境変数を設定します。MCP_BASE_URLGOOGLE_REDIRECT_URIはプロダクションドメインを使用する必要があります。/mcpルートはNode.jsランタイムで60秒の最大継続時間で実行されます。

プロジェクト構成

src/
  auth/              application authentication
  authorization/     authorizeClient via client_members
  oauth/             Google OAuth + token manager
  mcp-oauth/         MCP OAuth 2.1 authorization server
  connectors/ga4/    Google Analytics APIs
  mcp/ga4/           MCP tools
  repositories/      Supabase data access
  app/mcp/           Streamable HTTP transport

将来のコネクター(DV360、Google Ads)はsrc/connectors/<name>src/mcp/<name>を追加し、共有コアを再利用する必要があります。汎用的なGoogle APIのダンプグラウンドを作成しないでください。

-
license - not tested
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

  • Query Churn Solution cancellation-flow metrics, revenue, and feedback analytics (read-only).

  • Ask your app anything — revenue, errors, read-cost, growth — and get rendered charts back.

  • Privacy-first web analytics. Query pageviews, referrers, trends, and AI insights.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/devopsbrandmirchi/GoogleMcpServer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server