Metadata-Version: 2.4
Name: google-analytics-mcp-python
Version: 0.1.3
Summary: MCP Server for Google Analytics API access
Author-email: Locomotive Agency <cloud@locomotive.agency>, Josh Radcliff <jradcliff@users.noreply.github.com>, Matt Landers <matt-landers@users.noreply.github.com>
License-Expression: Apache-2.0
Project-URL: homepage, https://github.com/locomotive-agency/google-analytics-mcp
Project-URL: repository, https://github.com/locomotive-agency/google-analytics-mcp
Project-URL: issues, https://github.com/locomotive-agency/google-analytics-mcp/issues
Keywords: mcp,google-analytics,ai,tools,ga4,analytics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: google-analytics-data==0.18.19
Requires-Dist: google-analytics-admin==0.25.0
Requires-Dist: google-auth~=2.40
Requires-Dist: mcp[cli]>=1.2.0
Requires-Dist: httpx>=0.28.1
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: nox<2026,>=2025.5.1; extra == "dev"
Dynamic: license-file

# Google Analytics MCP Server

[![PyPI version](https://img.shields.io/pypi/v/google-analytics-mcp-python.svg)](https://pypi.org/project/google-analytics-mcp-python/)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

A Model Context Protocol (MCP) server for comprehensive Google Analytics API access. Built with FastMCP and maintained by [Locomotive Agency](https://locomotive.agency) for use with [mcpanywhere.com](https://mcpanywhere.com).

This server provides access to the [Google Analytics Admin API](https://developers.google.com/analytics/devguides/config/admin/v1) and [Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1) through MCP tools for LLM integration.

## Features

The server provides the following MCP tools:

### Account & Property Information

- `get_account_summaries` - Retrieves information about Google Analytics accounts and properties
- `get_property_details` - Returns details about a specific property
- `list_google_ads_links` - Lists Google Ads account links for a property

### Core Reports

- `run_report` - Runs a Google Analytics report using the Data API
- `get_custom_dimensions_and_metrics` - Retrieves custom dimensions and metrics for a property

### Realtime Reports

- `run_realtime_report` - Runs a Google Analytics realtime report using the Data API

## Installation

### Recommended (via uv)

```bash
uv tool install google-analytics-mcp-python
```

### Alternative (via pip)

```bash
pip install google-analytics-mcp-python
```

### Alternative (via pipx)

```bash
pipx install google-analytics-mcp-python
```

## Configuration

### 1. Enable Google Analytics APIs

Enable the following APIs in your Google Cloud project:

- [Google Analytics Admin API](https://console.cloud.google.com/apis/library/analyticsadmin.googleapis.com)
- [Google Analytics Data API](https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com)

### 2. Create Service Account

1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
2. Create a service account with the Analytics API scope
3. Download the JSON key file

### 3. Set Environment Variables

```bash
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"
```

#### Domain-Wide Delegation (Optional)

If you need to access Analytics properties on behalf of a user:

```bash
export ANALYTICS_MCP_SUBJECT="user@yourdomain.com"
```

**Note:** For backward compatibility, `GOOGLE_IMPERSONATED_SUBJECT` is also supported.

Required OAuth scope:
```
https://www.googleapis.com/auth/analytics.readonly
```

## Usage with MCP Clients

### Claude Desktop / Gemini

Add to your MCP settings file (`~/.gemini/settings.json` or Claude Desktop config):

```json
{
  "mcpServers": {
    "google-analytics": {
      "command": "uvx",
      "args": ["google-analytics-mcp-python"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account-key.json",
        "ANALYTICS_MCP_SUBJECT": "user@yourdomain.com"
      }
    }
  }
}
```

## Docker Deployment

Example Dockerfile for containerized deployment:

```dockerfile
FROM python:3.12-slim

RUN pip install --no-cache-dir google-analytics-mcp-python

ENV GOOGLE_APPLICATION_CREDENTIALS=/var/secrets/service-account.json

CMD ["google-analytics-mcp"]
```

Required environment variables:
- `GOOGLE_APPLICATION_CREDENTIALS` - Path to service account JSON
- `ANALYTICS_MCP_SUBJECT` (optional) - User email for domain-wide delegation

## Example Prompts

Once configured, you can interact with your Google Analytics data:

```
What are the most popular events in my Google Analytics property in the last 180 days?
```

```
Give me details about my Google Analytics property with 'xyz' in the name
```

```
What are the custom dimensions and custom metrics in my property?
```

```
Were most of my users in the last 6 months logged in?
```

## Development

This server is maintained by [Locomotive Agency](https://locomotive.agency) as part of the MCP Anywhere ecosystem.

Original implementation by Google Analytics team. Enhanced with domain-wide delegation support for enterprise use cases.

## License

Apache License 2.0 - See LICENSE file for details.

## Contributing

Contributions welcome! See the [Contributing Guide](CONTRIBUTING.md).
