google-analytics-mcp-server 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. google_analytics_mcp_server-0.1.0/LICENSE +21 -0
  2. google_analytics_mcp_server-0.1.0/PKG-INFO +266 -0
  3. google_analytics_mcp_server-0.1.0/README.md +243 -0
  4. google_analytics_mcp_server-0.1.0/pyproject.toml +98 -0
  5. google_analytics_mcp_server-0.1.0/pyproject.toml.orig +79 -0
  6. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/__init__.py +18 -0
  7. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/auth.py +71 -0
  8. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/capabilities.py +172 -0
  9. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/catalog.py +219 -0
  10. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/client.py +207 -0
  11. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/config.py +42 -0
  12. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/contracts.py +349 -0
  13. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/discovery/SOURCES.md +10 -0
  14. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/discovery/analyticsadmin.v1alpha.json +9477 -0
  15. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/discovery/analyticsadmin.v1beta.json +3572 -0
  16. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/discovery/analyticsdata.v1alpha.json +3442 -0
  17. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/discovery/analyticsdata.v1beta.json +2380 -0
  18. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/discovery/routes.json +766 -0
  19. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/examples/README.md +15 -0
  20. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/examples/admin.json +63 -0
  21. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/examples/data.json +58 -0
  22. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/names.py +75 -0
  23. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/policy.py +133 -0
  24. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/projection.py +220 -0
  25. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/registry.py +60 -0
  26. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/render.py +281 -0
  27. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/server.py +75 -0
  28. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/__init__.py +5 -0
  29. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/admin.py +359 -0
  30. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/chat.py +37 -0
  31. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/generic.py +233 -0
  32. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/jobs.py +110 -0
  33. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/meta.py +91 -0
  34. google_analytics_mcp_server-0.1.0/src/google_analytics_mcp_server/tools/reports.py +264 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jinchao Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,266 @@
1
+ Metadata-Version: 2.4
2
+ Name: google-analytics-mcp-server
3
+ Version: 0.1.0
4
+ Summary: A stdio MCP server for Google Analytics with full coverage of the Admin and Data APIs.
5
+ Keywords: mcp,google-analytics,ga4,analytics,llm
6
+ Author: Jinchao Liu
7
+ Author-email: Jinchao Liu <jinchaoliu09@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Dist: google-api-python-client>=2.200.0
17
+ Requires-Dist: mcp>=2.2,<3
18
+ Requires-Python: >=3.14
19
+ Project-URL: Repository, https://github.com/jinchliu/google-analytics-mcp-server
20
+ Project-URL: Issues, https://github.com/jinchliu/google-analytics-mcp-server/issues
21
+ Project-URL: Changelog, https://github.com/jinchliu/google-analytics-mcp-server/blob/main/CHANGELOG.md
22
+ Description-Content-Type: text/markdown
23
+
24
+ # google-analytics-mcp-server
25
+
26
+ A stdio [MCP](https://modelcontextprotocol.io/) server for Google Analytics with
27
+ full coverage of the [Admin](https://developers.google.com/analytics/devguides/config/admin/v1)
28
+ and [Data](https://developers.google.com/analytics/devguides/reporting/data/v1) APIs.
29
+ Empower your AI agent to explore data, run reports, manage configuration and
30
+ control access in Google Analytics. 🚀
31
+
32
+ ## ✨ Highlights
33
+
34
+ - **Full API surface, compact tool set.** 28 tools cover the pinned Admin and Data
35
+ alpha/beta APIs, with 26 enabled by default.
36
+ - **Built for context windows.** Returns Markdown tables by default, with `json`
37
+ and `json_full` available.
38
+ - **Controlled writes.** Writable leaf patches, confirmation for sensitive
39
+ operations and a strict read-only mode.
40
+ - **Runs as you.** Your own OAuth client through Application Default Credentials
41
+ (ADC).
42
+
43
+ Compared with [Google's official MCP](https://github.com/googleanalytics/google-analytics-mcp),
44
+ this server adds configuration and access management, pivot/batch reports and async
45
+ jobs.
46
+
47
+ ## 🧰 Tools
48
+
49
+ | Tier | Tools |
50
+ |---|---|
51
+ | Read (13) | `ga_list`, `ga_get`, `ga_query`, `ga_run_report`, `ga_run_realtime_report`, `ga_run_pivot_report`, `ga_batch_run_reports`, `ga_run_funnel_report`, `ga_check_compatibility`, `ga_get_metadata`, `ga_run_access_report`, `ga_search_change_history`, `ga_describe_schema` |
52
+ | Write (6) | `ga_create`, `ga_update`, `ga_provision_account_ticket`, `ga_create_rollup_property`, `ga_provision_subproperty`, `ga_reorder_event_edit_rules` |
53
+ | Destructive (6), explicit confirm required | `ga_delete`, `ga_update_settings`, `ga_manage_access_bindings`, `ga_submit_user_deletion`, `ga_acknowledge_user_data_collection`, `ga_review_dv360_link_proposal` |
54
+ | Job (1) | `ga_start_async_job` |
55
+ | Optional (2) | `ga_chat` (job/session), `ga_call_api` (mixed effects) |
56
+
57
+ Chat and raw API access are optional. For feature settings and strict read-only
58
+ mode, see [Appendix A: Environment Variables](#appendix-a-environment-variables).
59
+
60
+ Available operations depend on your Google Analytics permissions and property
61
+ eligibility. See [Coverage and known limitations](#-coverage-and-known-limitations)
62
+ for current limitations.
63
+
64
+ ## 🔑 Setup
65
+
66
+ You need a Google Cloud project and the
67
+ [gcloud CLI](https://cloud.google.com/sdk/docs/install).
68
+
69
+ ### 1. Enable the APIs
70
+
71
+ Enable both APIs on the project that will carry the quota:
72
+
73
+ ```bash
74
+ gcloud services enable analyticsadmin.googleapis.com analyticsdata.googleapis.com --project=YOUR_PROJECT
75
+ ```
76
+
77
+ ### 2. Create an OAuth client
78
+
79
+ Create a **Desktop app** OAuth client in your Google Cloud project and download
80
+ its JSON file. See [Manage OAuth Clients](https://support.google.com/cloud/answer/15549257).
81
+
82
+ - If your OAuth app's user type is set to **External**, check its publishing
83
+ status before logging in.
84
+ - With the Analytics scopes used here, refresh tokens issued for an **External**
85
+ app in **Testing** expire after seven days. For ongoing use, switch to
86
+ **In production**. See [Google's OAuth guidance](https://developers.google.com/identity/protocols/oauth2#expiration).
87
+
88
+ ### 3. Authorize access
89
+
90
+ Log in with the scopes needed for your work. Remove the scopes you don't need.
91
+ A limited grant produces an error when a tool requires an additional scope:
92
+
93
+ ```bash
94
+ gcloud auth application-default login \
95
+ --client-id-file=YOUR_DESKTOP_CLIENT.json \
96
+ --scopes=https://www.googleapis.com/auth/analytics.readonly,\
97
+ https://www.googleapis.com/auth/analytics.edit,\
98
+ https://www.googleapis.com/auth/analytics.manage.users,\
99
+ https://www.googleapis.com/auth/analytics.chatbot.read,\
100
+ https://www.googleapis.com/auth/cloud-platform
101
+ ```
102
+
103
+ | Scope | Unlocks |
104
+ |---|---|
105
+ | `analytics.readonly` | Most resource reads and reports |
106
+ | `analytics.edit` | Configuration writes and change-history reads |
107
+ | `analytics.manage.users` | Access-binding reads and writes |
108
+ | `analytics.manage.users.readonly` | Access-binding reads with limited credentials |
109
+ | `analytics.chatbot.read` | Optional [Analytics Chat](https://developers.google.com/analytics/devguides/reporting/data/v1/advisor-basics) |
110
+ | `cloud-platform` | [Cloud quota-project setup](https://docs.cloud.google.com/docs/authentication/troubleshoot-adc) where required; grants no GA access |
111
+
112
+ For limited read credentials, use:
113
+
114
+ - `https://www.googleapis.com/auth/analytics.readonly`
115
+ - `https://www.googleapis.com/auth/analytics.manage.users.readonly`
116
+
117
+ Change-history reads still require `analytics.edit`.
118
+
119
+ Already using [google-tag-manager-mcp](https://github.com/jinchliu/google-tag-manager-mcp)?
120
+ If both servers read the same ADC file, include both sets in one login:
121
+
122
+ ```bash
123
+ gcloud auth application-default login \
124
+ --client-id-file=YOUR_DESKTOP_CLIENT.json \
125
+ --scopes=https://www.googleapis.com/auth/analytics.readonly,\
126
+ https://www.googleapis.com/auth/analytics.edit,\
127
+ https://www.googleapis.com/auth/analytics.manage.users,\
128
+ https://www.googleapis.com/auth/analytics.chatbot.read,\
129
+ https://www.googleapis.com/auth/tagmanager.readonly,\
130
+ https://www.googleapis.com/auth/tagmanager.edit.containers,\
131
+ https://www.googleapis.com/auth/tagmanager.delete.containers,\
132
+ https://www.googleapis.com/auth/tagmanager.edit.containerversions,\
133
+ https://www.googleapis.com/auth/tagmanager.publish,\
134
+ https://www.googleapis.com/auth/tagmanager.manage.users,\
135
+ https://www.googleapis.com/auth/tagmanager.manage.accounts,\
136
+ https://www.googleapis.com/auth/cloud-platform
137
+ ```
138
+
139
+ Enable chat with `GA_MCP_ENABLE_CHAT=1` after authorization.
140
+ See [Appendix A: Environment Variables](#appendix-a-environment-variables) for the full list.
141
+
142
+ To use different identities or grants, set `GOOGLE_APPLICATION_CREDENTIALS` for
143
+ each MCP process to its ADC credentials file.
144
+
145
+ ## 🔌 Connect an MCP client
146
+
147
+ Install from PyPI with [uv](https://docs.astral.sh/uv/guides/tools/) (recommended) or pipx:
148
+
149
+ ```bash
150
+ uv tool install --python 3.14 google-analytics-mcp-server
151
+ ```
152
+
153
+ The client examples below pin an explicit quota project. The identity needs
154
+ permission to consume services on it.
155
+
156
+ The quota project is selected in this order:
157
+
158
+ 1. `GOOGLE_CLOUD_QUOTA_PROJECT` overrides credential configuration.
159
+ 2. Otherwise, a configured ADC `quota_project_id` is used.
160
+ 3. Without an explicit quota project, attribution depends on the credentials and
161
+ API, commonly the OAuth client's project.
162
+
163
+ ### Claude
164
+
165
+ Claude Code:
166
+
167
+ ```bash
168
+ claude mcp add --scope user google-analytics-mcp-server \
169
+ -e GOOGLE_CLOUD_QUOTA_PROJECT=YOUR_PROJECT \
170
+ -- google-analytics-mcp-server
171
+ ```
172
+
173
+ Claude Desktop:
174
+
175
+ Open **Settings > Developer > Edit Config** and add:
176
+
177
+ ```json
178
+ {
179
+ "mcpServers": {
180
+ "google-analytics-mcp-server": {
181
+ "command": "google-analytics-mcp-server",
182
+ "env": { "GOOGLE_CLOUD_QUOTA_PROJECT": "YOUR_PROJECT" }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ If Claude Desktop cannot find the command, use its absolute path instead.
189
+
190
+ ### ChatGPT / Codex
191
+
192
+ In the desktop app, go to **Settings > MCP servers > Add server** and choose
193
+ **STDIO**. Use `google-analytics-mcp-server` as the command.
194
+
195
+ Or add the server with the Codex CLI:
196
+
197
+ ```bash
198
+ codex mcp add google-analytics-mcp-server \
199
+ --env GOOGLE_CLOUD_QUOTA_PROJECT=YOUR_PROJECT \
200
+ -- google-analytics-mcp-server
201
+ ```
202
+
203
+ ### Try it out
204
+
205
+ After connecting the server, try asking your AI agent:
206
+
207
+ - “List my Google Analytics accounts and properties.”
208
+ - “Compare purchase revenue by country over the last 28 days.”
209
+ - “Create an event-scoped custom dimension for `membership_level`.”
210
+
211
+ ## 🛡️ Safety model
212
+
213
+ - **Your approval.** Sensitive actions require you to approve what will change
214
+ and where.
215
+ - **Read-only mode.** Limits your agent to viewing data and running reports;
216
+ changes, new background jobs and chat are disabled.
217
+ - **Access management.** Specify every role a user should have when changing
218
+ their access. Removing all roles deletes that direct access assignment.
219
+ - **Sensitive output.** Detailed results may include Measurement Protocol API
220
+ secrets. Summary lists hide those values.
221
+
222
+ ## 🧪 Coverage and known limitations
223
+
224
+ This server is in alpha. It supports the [bundled Admin/Data API versions](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/src/google_analytics_mcp_server/discovery/SOURCES.md).
225
+ Features depend on your Analytics permissions and property eligibility.
226
+
227
+ - **Chat:** Experimental and disabled by default. Successful sessions remain
228
+ unverified.
229
+ - **Account provisioning and Analytics 360:** These workflows
230
+ remain unverified; see [known limitations](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/CHANGELOG.md#known-limitations).
231
+ - **Outside scope:** Universal Analytics, Measurement Protocol event collection
232
+ and BigQuery export queries.
233
+
234
+ ## Development
235
+
236
+ For development from a source checkout:
237
+
238
+ ```bash
239
+ uv sync --locked
240
+ uv run pytest
241
+ ```
242
+
243
+ Tests run offline by default. See the [test guide](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/tests/README.md) for packaging
244
+ checks and opt-in live tests.
245
+
246
+ ## License
247
+
248
+ MIT, see [LICENSE](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/LICENSE).
249
+
250
+ ## Appendix A: Environment Variables
251
+
252
+ | Variable | Default | Effect |
253
+ |---|---|---|
254
+ | `GOOGLE_APPLICATION_CREDENTIALS` | unset | Standard ADC credentials file, before the gcloud ADC file |
255
+ | `GOOGLE_CLOUD_QUOTA_PROJECT` | unset | Quota project override |
256
+ | `GOOGLE_CLOUD_PROJECT` | unset | Optional project ID; avoids gcloud project lookup |
257
+ | `GA_MCP_READ_ONLY` | `0` | Registers the 13 read tools and blocks mutations at execution |
258
+ | `GA_MCP_ENABLE_CHAT` | `0` | Enables experimental chat outside read-only mode; requires its extra scope |
259
+ | `GA_MCP_ENABLE_RAW_API` | `0` | Enables `ga_call_api` outside read-only mode |
260
+ | `GA_MCP_MAX_LIST_ITEMS` | `1000` | Maximum requested list size; upstream limits also apply |
261
+ | `GA_MCP_MAX_ROWS` | `10000` | Aggregate requested report/query rows; pivot limits multiply |
262
+ | `GA_MCP_MAX_OUTPUT_BYTES` | `65536` | Combined text and structured read-output budget |
263
+ | `GA_MCP_HTTP_TIMEOUT` | `60` | Timeout in seconds per HTTP request |
264
+ | `GA_MCP_LOG_LEVEL` | `INFO` | Log level; output goes to stderr |
265
+
266
+ Flags accept `1`, `true` or `yes`. Restart after environment changes.
@@ -0,0 +1,243 @@
1
+ # google-analytics-mcp-server
2
+
3
+ A stdio [MCP](https://modelcontextprotocol.io/) server for Google Analytics with
4
+ full coverage of the [Admin](https://developers.google.com/analytics/devguides/config/admin/v1)
5
+ and [Data](https://developers.google.com/analytics/devguides/reporting/data/v1) APIs.
6
+ Empower your AI agent to explore data, run reports, manage configuration and
7
+ control access in Google Analytics. 🚀
8
+
9
+ ## ✨ Highlights
10
+
11
+ - **Full API surface, compact tool set.** 28 tools cover the pinned Admin and Data
12
+ alpha/beta APIs, with 26 enabled by default.
13
+ - **Built for context windows.** Returns Markdown tables by default, with `json`
14
+ and `json_full` available.
15
+ - **Controlled writes.** Writable leaf patches, confirmation for sensitive
16
+ operations and a strict read-only mode.
17
+ - **Runs as you.** Your own OAuth client through Application Default Credentials
18
+ (ADC).
19
+
20
+ Compared with [Google's official MCP](https://github.com/googleanalytics/google-analytics-mcp),
21
+ this server adds configuration and access management, pivot/batch reports and async
22
+ jobs.
23
+
24
+ ## 🧰 Tools
25
+
26
+ | Tier | Tools |
27
+ |---|---|
28
+ | Read (13) | `ga_list`, `ga_get`, `ga_query`, `ga_run_report`, `ga_run_realtime_report`, `ga_run_pivot_report`, `ga_batch_run_reports`, `ga_run_funnel_report`, `ga_check_compatibility`, `ga_get_metadata`, `ga_run_access_report`, `ga_search_change_history`, `ga_describe_schema` |
29
+ | Write (6) | `ga_create`, `ga_update`, `ga_provision_account_ticket`, `ga_create_rollup_property`, `ga_provision_subproperty`, `ga_reorder_event_edit_rules` |
30
+ | Destructive (6), explicit confirm required | `ga_delete`, `ga_update_settings`, `ga_manage_access_bindings`, `ga_submit_user_deletion`, `ga_acknowledge_user_data_collection`, `ga_review_dv360_link_proposal` |
31
+ | Job (1) | `ga_start_async_job` |
32
+ | Optional (2) | `ga_chat` (job/session), `ga_call_api` (mixed effects) |
33
+
34
+ Chat and raw API access are optional. For feature settings and strict read-only
35
+ mode, see [Appendix A: Environment Variables](#appendix-a-environment-variables).
36
+
37
+ Available operations depend on your Google Analytics permissions and property
38
+ eligibility. See [Coverage and known limitations](#-coverage-and-known-limitations)
39
+ for current limitations.
40
+
41
+ ## 🔑 Setup
42
+
43
+ You need a Google Cloud project and the
44
+ [gcloud CLI](https://cloud.google.com/sdk/docs/install).
45
+
46
+ ### 1. Enable the APIs
47
+
48
+ Enable both APIs on the project that will carry the quota:
49
+
50
+ ```bash
51
+ gcloud services enable analyticsadmin.googleapis.com analyticsdata.googleapis.com --project=YOUR_PROJECT
52
+ ```
53
+
54
+ ### 2. Create an OAuth client
55
+
56
+ Create a **Desktop app** OAuth client in your Google Cloud project and download
57
+ its JSON file. See [Manage OAuth Clients](https://support.google.com/cloud/answer/15549257).
58
+
59
+ - If your OAuth app's user type is set to **External**, check its publishing
60
+ status before logging in.
61
+ - With the Analytics scopes used here, refresh tokens issued for an **External**
62
+ app in **Testing** expire after seven days. For ongoing use, switch to
63
+ **In production**. See [Google's OAuth guidance](https://developers.google.com/identity/protocols/oauth2#expiration).
64
+
65
+ ### 3. Authorize access
66
+
67
+ Log in with the scopes needed for your work. Remove the scopes you don't need.
68
+ A limited grant produces an error when a tool requires an additional scope:
69
+
70
+ ```bash
71
+ gcloud auth application-default login \
72
+ --client-id-file=YOUR_DESKTOP_CLIENT.json \
73
+ --scopes=https://www.googleapis.com/auth/analytics.readonly,\
74
+ https://www.googleapis.com/auth/analytics.edit,\
75
+ https://www.googleapis.com/auth/analytics.manage.users,\
76
+ https://www.googleapis.com/auth/analytics.chatbot.read,\
77
+ https://www.googleapis.com/auth/cloud-platform
78
+ ```
79
+
80
+ | Scope | Unlocks |
81
+ |---|---|
82
+ | `analytics.readonly` | Most resource reads and reports |
83
+ | `analytics.edit` | Configuration writes and change-history reads |
84
+ | `analytics.manage.users` | Access-binding reads and writes |
85
+ | `analytics.manage.users.readonly` | Access-binding reads with limited credentials |
86
+ | `analytics.chatbot.read` | Optional [Analytics Chat](https://developers.google.com/analytics/devguides/reporting/data/v1/advisor-basics) |
87
+ | `cloud-platform` | [Cloud quota-project setup](https://docs.cloud.google.com/docs/authentication/troubleshoot-adc) where required; grants no GA access |
88
+
89
+ For limited read credentials, use:
90
+
91
+ - `https://www.googleapis.com/auth/analytics.readonly`
92
+ - `https://www.googleapis.com/auth/analytics.manage.users.readonly`
93
+
94
+ Change-history reads still require `analytics.edit`.
95
+
96
+ Already using [google-tag-manager-mcp](https://github.com/jinchliu/google-tag-manager-mcp)?
97
+ If both servers read the same ADC file, include both sets in one login:
98
+
99
+ ```bash
100
+ gcloud auth application-default login \
101
+ --client-id-file=YOUR_DESKTOP_CLIENT.json \
102
+ --scopes=https://www.googleapis.com/auth/analytics.readonly,\
103
+ https://www.googleapis.com/auth/analytics.edit,\
104
+ https://www.googleapis.com/auth/analytics.manage.users,\
105
+ https://www.googleapis.com/auth/analytics.chatbot.read,\
106
+ https://www.googleapis.com/auth/tagmanager.readonly,\
107
+ https://www.googleapis.com/auth/tagmanager.edit.containers,\
108
+ https://www.googleapis.com/auth/tagmanager.delete.containers,\
109
+ https://www.googleapis.com/auth/tagmanager.edit.containerversions,\
110
+ https://www.googleapis.com/auth/tagmanager.publish,\
111
+ https://www.googleapis.com/auth/tagmanager.manage.users,\
112
+ https://www.googleapis.com/auth/tagmanager.manage.accounts,\
113
+ https://www.googleapis.com/auth/cloud-platform
114
+ ```
115
+
116
+ Enable chat with `GA_MCP_ENABLE_CHAT=1` after authorization.
117
+ See [Appendix A: Environment Variables](#appendix-a-environment-variables) for the full list.
118
+
119
+ To use different identities or grants, set `GOOGLE_APPLICATION_CREDENTIALS` for
120
+ each MCP process to its ADC credentials file.
121
+
122
+ ## 🔌 Connect an MCP client
123
+
124
+ Install from PyPI with [uv](https://docs.astral.sh/uv/guides/tools/) (recommended) or pipx:
125
+
126
+ ```bash
127
+ uv tool install --python 3.14 google-analytics-mcp-server
128
+ ```
129
+
130
+ The client examples below pin an explicit quota project. The identity needs
131
+ permission to consume services on it.
132
+
133
+ The quota project is selected in this order:
134
+
135
+ 1. `GOOGLE_CLOUD_QUOTA_PROJECT` overrides credential configuration.
136
+ 2. Otherwise, a configured ADC `quota_project_id` is used.
137
+ 3. Without an explicit quota project, attribution depends on the credentials and
138
+ API, commonly the OAuth client's project.
139
+
140
+ ### Claude
141
+
142
+ Claude Code:
143
+
144
+ ```bash
145
+ claude mcp add --scope user google-analytics-mcp-server \
146
+ -e GOOGLE_CLOUD_QUOTA_PROJECT=YOUR_PROJECT \
147
+ -- google-analytics-mcp-server
148
+ ```
149
+
150
+ Claude Desktop:
151
+
152
+ Open **Settings > Developer > Edit Config** and add:
153
+
154
+ ```json
155
+ {
156
+ "mcpServers": {
157
+ "google-analytics-mcp-server": {
158
+ "command": "google-analytics-mcp-server",
159
+ "env": { "GOOGLE_CLOUD_QUOTA_PROJECT": "YOUR_PROJECT" }
160
+ }
161
+ }
162
+ }
163
+ ```
164
+
165
+ If Claude Desktop cannot find the command, use its absolute path instead.
166
+
167
+ ### ChatGPT / Codex
168
+
169
+ In the desktop app, go to **Settings > MCP servers > Add server** and choose
170
+ **STDIO**. Use `google-analytics-mcp-server` as the command.
171
+
172
+ Or add the server with the Codex CLI:
173
+
174
+ ```bash
175
+ codex mcp add google-analytics-mcp-server \
176
+ --env GOOGLE_CLOUD_QUOTA_PROJECT=YOUR_PROJECT \
177
+ -- google-analytics-mcp-server
178
+ ```
179
+
180
+ ### Try it out
181
+
182
+ After connecting the server, try asking your AI agent:
183
+
184
+ - “List my Google Analytics accounts and properties.”
185
+ - “Compare purchase revenue by country over the last 28 days.”
186
+ - “Create an event-scoped custom dimension for `membership_level`.”
187
+
188
+ ## 🛡️ Safety model
189
+
190
+ - **Your approval.** Sensitive actions require you to approve what will change
191
+ and where.
192
+ - **Read-only mode.** Limits your agent to viewing data and running reports;
193
+ changes, new background jobs and chat are disabled.
194
+ - **Access management.** Specify every role a user should have when changing
195
+ their access. Removing all roles deletes that direct access assignment.
196
+ - **Sensitive output.** Detailed results may include Measurement Protocol API
197
+ secrets. Summary lists hide those values.
198
+
199
+ ## 🧪 Coverage and known limitations
200
+
201
+ This server is in alpha. It supports the [bundled Admin/Data API versions](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/src/google_analytics_mcp_server/discovery/SOURCES.md).
202
+ Features depend on your Analytics permissions and property eligibility.
203
+
204
+ - **Chat:** Experimental and disabled by default. Successful sessions remain
205
+ unverified.
206
+ - **Account provisioning and Analytics 360:** These workflows
207
+ remain unverified; see [known limitations](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/CHANGELOG.md#known-limitations).
208
+ - **Outside scope:** Universal Analytics, Measurement Protocol event collection
209
+ and BigQuery export queries.
210
+
211
+ ## Development
212
+
213
+ For development from a source checkout:
214
+
215
+ ```bash
216
+ uv sync --locked
217
+ uv run pytest
218
+ ```
219
+
220
+ Tests run offline by default. See the [test guide](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/tests/README.md) for packaging
221
+ checks and opt-in live tests.
222
+
223
+ ## License
224
+
225
+ MIT, see [LICENSE](https://github.com/jinchliu/google-analytics-mcp-server/blob/main/LICENSE).
226
+
227
+ ## Appendix A: Environment Variables
228
+
229
+ | Variable | Default | Effect |
230
+ |---|---|---|
231
+ | `GOOGLE_APPLICATION_CREDENTIALS` | unset | Standard ADC credentials file, before the gcloud ADC file |
232
+ | `GOOGLE_CLOUD_QUOTA_PROJECT` | unset | Quota project override |
233
+ | `GOOGLE_CLOUD_PROJECT` | unset | Optional project ID; avoids gcloud project lookup |
234
+ | `GA_MCP_READ_ONLY` | `0` | Registers the 13 read tools and blocks mutations at execution |
235
+ | `GA_MCP_ENABLE_CHAT` | `0` | Enables experimental chat outside read-only mode; requires its extra scope |
236
+ | `GA_MCP_ENABLE_RAW_API` | `0` | Enables `ga_call_api` outside read-only mode |
237
+ | `GA_MCP_MAX_LIST_ITEMS` | `1000` | Maximum requested list size; upstream limits also apply |
238
+ | `GA_MCP_MAX_ROWS` | `10000` | Aggregate requested report/query rows; pivot limits multiply |
239
+ | `GA_MCP_MAX_OUTPUT_BYTES` | `65536` | Combined text and structured read-output budget |
240
+ | `GA_MCP_HTTP_TIMEOUT` | `60` | Timeout in seconds per HTTP request |
241
+ | `GA_MCP_LOG_LEVEL` | `INFO` | Log level; output goes to stderr |
242
+
243
+ Flags accept `1`, `true` or `yes`. Restart after environment changes.
@@ -0,0 +1,98 @@
1
+ [project]
2
+ name = "google-analytics-mcp-server"
3
+ version = "0.1.0"
4
+ description = "A stdio MCP server for Google Analytics with full coverage of the Admin and Data APIs."
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ keywords = [
10
+ "mcp",
11
+ "google-analytics",
12
+ "ga4",
13
+ "analytics",
14
+ "llm",
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Environment :: Console",
19
+ "Intended Audience :: Developers",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.14",
23
+ ]
24
+ dependencies = [
25
+ "google-api-python-client>=2.200.0",
26
+ "mcp>=2.2,<3",
27
+ ]
28
+
29
+ [[project.authors]]
30
+ name = "Jinchao Liu"
31
+ email = "jinchaoliu09@gmail.com"
32
+
33
+ [project.urls]
34
+ Repository = "https://github.com/jinchliu/google-analytics-mcp-server"
35
+ Issues = "https://github.com/jinchliu/google-analytics-mcp-server/issues"
36
+ Changelog = "https://github.com/jinchliu/google-analytics-mcp-server/blob/main/CHANGELOG.md"
37
+
38
+ [project.scripts]
39
+ google-analytics-mcp-server = "google_analytics_mcp_server:main"
40
+
41
+ [build-system]
42
+ requires = ["uv_build>=0.12.17,<0.13.0"]
43
+ build-backend = "uv_build"
44
+
45
+ [dependency-groups]
46
+ dev = [
47
+ "mypy>=2.3.1",
48
+ "pre-commit>=4.6.2",
49
+ "pytest>=9.1.1",
50
+ "pytest-cov>=7.1.0",
51
+ "ruff>=0.16.8",
52
+ ]
53
+
54
+ [tool.ruff]
55
+ target-version = "py314"
56
+ src = ["src"]
57
+
58
+ [tool.ruff.format]
59
+ quote-style = "single"
60
+
61
+ [tool.ruff.lint]
62
+ select = [
63
+ "E4",
64
+ "E7",
65
+ "E9",
66
+ "F",
67
+ "I",
68
+ "B",
69
+ "UP",
70
+ ]
71
+
72
+ [tool.mypy]
73
+ strict = true
74
+ files = ["src"]
75
+
76
+ [[tool.mypy.overrides]]
77
+ module = [
78
+ "googleapiclient.*",
79
+ "google_auth_httplib2",
80
+ "httplib2",
81
+ ]
82
+ ignore_missing_imports = true
83
+
84
+ [tool.pytest.ini_options]
85
+ testpaths = ["tests"]
86
+ addopts = "-ra --strict-markers --strict-config"
87
+ markers = [
88
+ "live: opt-in Google API tests requiring ADC",
89
+ "live_write: sandbox mutations requiring a dry-run plan and execution journal",
90
+ ]
91
+
92
+ [tool.coverage.run]
93
+ source = ["google_analytics_mcp_server"]
94
+ branch = true
95
+
96
+ [tool.coverage.report]
97
+ show_missing = true
98
+ fail_under = 90