Skip to main content
Glama
Google Analytics MCP Plus

Google Analytics MCP Plus

by marcvrn
README.md
# Google Analytics MCP Plus

An independent MCP server for Google Analytics 4 reporting and property configuration. It connects an MCP client to the official Analytics Admin and Data APIs through a local Python process.

The official Google Analytics MCP is read-only. This server adds controlled writes: key events, custom dimensions and metrics, Google Ads links, data streams, Measurement Protocol secrets, audiences, annotations, and the rest of the Admin API.

This project is not affiliated with Google.

## Tools

| Tool | Purpose |
| --- | --- |
| `list_account_summaries` | Accounts and properties, filtered by the property allowlist |
| `get_metadata` | Dimensions and metrics available to a property, including custom ones |
| `run_report` | Data API reports: `report`, `pivot`, `batch`, `batch_pivot`, `realtime`, `compatibility`, `funnel` |
| `list_admin_methods` | Admin API v1alpha methods grouped as read, write, and blocked |
| `get_request_schema` | Protobuf fields for any Admin method or `data.<kind>`, without credentials |
| `admin_read` | Any `get_`, `list_`, `search_`, `batch_get_`, or `run_` Admin method |
| `admin_write` | Any other Admin method, validate-only by default |

`admin_read` and `admin_write` take the method name and its request JSON, so the whole Admin API is reachable without a tool per resource:

```json
{"method": "create_key_event",
 "request": {"parent": "properties/123",
             "key_event": {"event_name": "purchase", "counting_method": "ONCE_PER_EVENT"}}}
```

Update masks accept snake_case (`"display_name,description"`).

## Write safety

- **Writes are disabled by default.** Execution requires `GOOGLE_ANALYTICS_ENABLE_WRITES=true` in the server environment and `validate_only=false` in the call.
- **Validation is local.** The Admin API has no server-side dry run. Validation parses the request against the API schema, applies the allowlist, and returns the parsed request. Permissions and business rules are checked only on execution.
- **Property allowlist.** With `GOOGLE_ANALYTICS_ALLOWED_PROPERTY_IDS` set, every `properties/N` reference in a request must be allowed, and writes that reference no property (account-level changes) are refused.
- **Blocked methods.** Account and property deletion, account provisioning, roll-up properties, user deletion, user data collection acknowledgement, and access binding (user permission) changes are refused regardless of settings.
- **No automatic retries on writes.** A timed-out write may have succeeded. Read the property before retrying.

## Authentication

The server uses Application Default Credentials. The credential needs both Analytics scopes: the Admin API accepts `analytics.edit` for writes, but the Data API rejects it and requires `analytics.readonly`. One credential can serve this server and Google Ads MCP Plus:

```sh
gcloud auth application-default login \
	--client-id-file=/absolute/path/to/oauth-client.json \
	--scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/analytics.edit,https://www.googleapis.com/auth/adwords,https://www.googleapis.com/auth/cloud-platform
```

Enable the Google Analytics Admin API and Google Analytics Data API in the Cloud project that owns the OAuth client. Set `GOOGLE_CLOUD_QUOTA_PROJECT` if quota should be billed to a different project.

| Variable | Default | Meaning |
| --- | --- | --- |
| `GOOGLE_APPLICATION_CREDENTIALS` | Standard ADC lookup | Absolute path to the credential file |
| `GOOGLE_ANALYTICS_ENABLE_WRITES` | `false` | `true` permits execution |
| `GOOGLE_ANALYTICS_ALLOWED_PROPERTY_IDS` | Empty | Comma-separated property IDs. Empty permits every property the user can access |
| `GOOGLE_ANALYTICS_TIMEOUT_SECONDS` | `30` | Timeout per API call, 1 to 300 |

## Install and verify

```sh
uv sync --locked
export GOOGLE_APPLICATION_CREDENTIALS="/absolute/path/to/application_default_credentials.json"
uv run python scripts/smoke_test.py --property-id 123456789               # read-only
uv run python scripts/smoke_test.py --property-id 123456789 --write-test  # creates and deletes one annotation
```

## Connect a client

```json
{
	"mcpServers": {
		"google-analytics-mcp-plus": {
			"command": "/absolute/path/to/uv",
			"args": ["run", "--directory", "/absolute/path/to/google-analytics-mcp-plus", "--locked", "google-analytics-mcp-plus"],
			"env": {
				"GOOGLE_APPLICATION_CREDENTIALS": "/absolute/path/to/application_default_credentials.json",
				"GOOGLE_ANALYTICS_ALLOWED_PROPERTY_IDS": "123456789",
				"GOOGLE_ANALYTICS_ENABLE_WRITES": "false"
			}
		}
	}
}
```

## Limits

- Local stdio only.
- The Admin API surface is v1alpha, which includes every v1beta method. Alpha methods can change.
- List methods return one page. Pass `page_token` in the request to continue.
- Measurement Protocol event sending and Data API audience exports are not exposed.

## License

[MIT](LICENSE).

TDQS

A3.7/5.0

Scored across 7 tools

Disambiguation4/5

The Data API path (run_report) and Admin API path (admin_read/admin_write) are clearly separated, and read vs write is explicit. The only mild overlap is between the discovery tools list_admin_methods and get_request_schema, plus get_metadata vs get_request_schema, but descriptions clarify that one lists dimensions/metrics and the other inspects protobuf fields.

Naming Consistency4/5

Five tools follow a verb_noun pattern (list_account_summaries, get_metadata, run_report, list_admin_methods, get_request_schema), while admin_read/admin_write use a noun_verb grouping that still reads predictably as a pair. Minor deviation only, no chaotic mixing.

Tool Count5/5

Seven tools is well-scoped: instead of one tool per GA method, the server uses generic dispatch (admin_read/admin_write) with schema discovery, keeping the surface small while covering a large API. Each tool earns its place.

Completeness4/5

Reporting (report, pivot, batch, realtime, funnel), metadata, account listing, and full Admin read/write with validation and schema inspection cover the domain end to end. The main gap is that write execution requires an env flag and there is no built-in pagination helper beyond manually passing page_token.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues