Skip to main content

MCP server for Google Analytics Data API

Project description

Google Analytics Data API MCP Server

Base URL: https://analyticsdata.googleapis.com

API Info


Install

Quick Start (recommended)

OAUTH2_CLIENT_ID=YOUR_OAUTH2_CLIENT_ID \
OAUTH2_CLIENT_SECRET=YOUR_OAUTH2_CLIENT_SECRET \
OAUTH2_SCOPES=YOUR_OAUTH2_SCOPES \
uvx mcparmory-google-analytics

With pip

pip install mcparmory-google-analytics
OAUTH2_CLIENT_ID=YOUR_OAUTH2_CLIENT_ID \
OAUTH2_CLIENT_SECRET=YOUR_OAUTH2_CLIENT_SECRET \
OAUTH2_SCOPES=YOUR_OAUTH2_SCOPES \
mcparmory-google-analytics

MCP Client Configuration

Add to your MCP client config (e.g. Claude Desktop, Cursor, Codex):

{
  "mcpServers": {
    "google-analytics": {
      "command": "uvx",
      "args": ["mcparmory-google-analytics"],
      "env": {
        "OAUTH2_CLIENT_ID": "YOUR_OAUTH2_CLIENT_ID",
        "OAUTH2_CLIENT_SECRET": "YOUR_OAUTH2_CLIENT_SECRET",
        "OAUTH2_SCOPES": "YOUR_OAUTH2_SCOPES"
      }
    }
  }
}

Set OAUTH2_SCOPES to a comma-separated list of scopes your app requires (e.g. OAUTH2_SCOPES=scope_a,scope_b). Open .env to see all available scopes with descriptions.


Credentials

Set the following environment variables (via MCP client env config, shell export, or .env file):

  • OAUTH2_CLIENT_ID — OAuth2 client ID
  • OAUTH2_CLIENT_SECRET — OAuth2 client secret
  • OAUTH2_SCOPES — OAuth2 scopes (comma-separated) Do not commit credentials to version control.

OAuth2

Add this redirect URI to your OAuth provider's allowed redirect URIs:

http://localhost:9400/callback

If you change OAUTH2_CALLBACK_PORT in .env, update the redirect URI to match.

On first use, a browser window opens automatically for OAuth authorization. Grant access when prompted — tokens are saved to tokens/oauth2_tokens.json and refreshed automatically.

Re-authorization: Delete tokens/oauth2_tokens.json and restart the server.


Run Locally

First, configure your credentials in .env (see Credentials above).

pip install -r requirements.txt
python server.py

Connect MCP Client

Edit .mcp.json and replace <SERVER_DIR> with the absolute path to this directory, then add to your MCP client configuration.

Example (if server is at /home/user/mcp-servers/google-analytics):

{
  "mcpServers": {
    "google-analytics": {
      "command": "python",
      "args": ["/home/user/mcp-servers/google-analytics/server.py"]
    }
  }
}

Docker

First, configure your credentials in .env (see Credentials above).

docker build -t google-analytics .
mkdir -p tokens
docker run -p 8000:8000 -p 9400:9400 -v ./tokens:/app/tokens --env-file .env google-analytics

Before running, make sure ports 8000, 9400 are free. If you changed the callback port in .env, update the -p port mapping and your OAuth provider's redirect URI to match.

On first run, the server prints an authorization URL — check docker logs for the URL. Open it in your browser to complete OAuth consent. Tokens are persisted to ./tokens/ via the volume mount so re-authorization is not needed on subsequent runs. For Docker, use SSE transport in your MCP client config:

{
  "mcpServers": {
    "google-analytics": {
      "type": "sse",
      "url": "http://localhost:8000/sse"
    }
  }
}

Files

  • .env - Credentials and server configuration
  • .mcp.json - MCP client config template
  • Dockerfile - Container build
  • LICENSE - MIT license for this generated code
  • requirements.txt - Python dependencies
  • README.md - This file
  • server.py - MCP server entry point
  • _auth.py - Authentication handlers
  • _models.py - Request/response models
  • _validators.py - Input validation

Note: Files starting with . are hidden by default on macOS/Linux. Use ls -a in terminal or enable "Show hidden files" in your file manager to see .env and .mcp.json.


MCP Blacksmith
Generated by MCP Blacksmith · Quickstart docs · Report a bug

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcparmory_google_analytics-1.0.0-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file mcparmory_google_analytics-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcparmory_google_analytics-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54dee652fab19d82f66e21efe0bc191d1de74d641164dedb92100096f86c2d55
MD5 bd61119c8dff891c4e4401d79b53620b
BLAKE2b-256 6970cfae5dfac191a16cb3370b9db321c63e8b76d1fbd01491face6452a930f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page