Skip to content

Commit c80f2dd

Browse files
authored
feat!: add 'google-analytics-mcp' command for pipx compatibility (#9)
Simplifies the process of running the server by utilizing `pipx`. - Added pix to commands in README - Added instructions on local testing to the contributing guide BREAKING_CHANGE: `server.py` moved into the `analytics_mcp` package
1 parent de7a28a commit c80f2dd

4 files changed

Lines changed: 38 additions & 40 deletions

File tree

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ Then run the formatter on all Python files:
4343
```
4444
nox -s format
4545
```
46+
47+
## Test changes
48+
49+
To test changes, modify the `command` for the `analytics-mcp` entry in your
50+
`~/.gemini/settings.json` file so Gemini runs the server using your local
51+
source files:
52+
53+
```
54+
"command": "PATH_TO_REPO/.venv/bin/google-analytics-mcp",
55+
```
56+

README.md

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,13 @@ to provide several
5151

5252
Setup involves the following steps:
5353

54-
1. Clone the repo.
55-
1. Configure Python and install dependencies.
54+
1. Configure Python.
5655
1. Configure credentials for Google Analytics.
5756
1. Configure Gemini.
5857

59-
### Clone the repo
60-
61-
```
62-
git clone https://github.com/googleanalytics/google-analytics-mcp.git
63-
```
64-
6558
### Configure Python :snake:
6659

67-
Navigate to the `google-analytics-mcp` directory, then complete the following steps.
68-
69-
1. Create a Python virtual environment in the `env` directory.
70-
71-
```shell
72-
python3 -m venv .venv
73-
```
74-
75-
1. Activate the virtual environment.
76-
77-
```shell
78-
source .venv/bin/activate
79-
```
80-
81-
1. Setup the project and its dependencies.
82-
83-
```shell
84-
pip install .
85-
```
60+
[Install pipx](https://pipx.pypa.io/stable/#install-pipx).
8661

8762
### Configure credentials :key:
8863

@@ -132,20 +107,17 @@ Here are some sample `gcloud` commands you might find useful:
132107
1. Create or edit the file at `~/.gemini/settings.json`, adding your server
133108
to the `mcpServers` list.
134109

135-
Replace `PATH_TO_SERVER` with the complete path to the directory where you
136-
cloned this repo.
137-
138110
```
139111
{
140112
"mcpServers": {
141113
"analytics-mcp": {
142-
"command": "PATH_TO_SERVER/.venv/bin/python",
114+
"command": "pipx",
143115
"args": [
144-
"PATH_TO_SERVER/server.py"
145-
],
146-
"env": {
147-
"MCP_DEBUG": "true"
148-
}
116+
"run",
117+
"--spec",
118+
"git+https://github.com/googleanalytics/google-analytics-mcp.git",
119+
"google-analytics-mcp"
120+
]
149121
}
150122
},
151123
"selectedAuthType": "gemini-api-key",
@@ -169,9 +141,12 @@ Here are some sample `gcloud` commands you might find useful:
169141
{
170142
"mcpServers": {
171143
"analytics-mcp": {
172-
"command": "PATH_TO_SERVER/.venv/bin/python",
144+
"command": "pipx",
173145
"args": [
174-
"PATH_TO_SERVER/server.py"
146+
"run",
147+
"--spec",
148+
"git+https://github.com/googleanalytics/google-analytics-mcp.git",
149+
"google-analytics-mcp"
175150
],
176151
"env": {
177152
"MCP_DEBUG": "true",

server.py renamed to analytics_mcp/server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@
2626
from analytics_mcp.tools.reporting import realtime # noqa: F401
2727
from analytics_mcp.tools.reporting import core # noqa: F401
2828

29-
if __name__ == "__main__":
29+
30+
def run_server() -> None:
31+
"""Runs the server.
32+
33+
Serves as the entrypoint for the 'runmcp' command.
34+
"""
3035
mcp.run()
36+
37+
38+
if __name__ == "__main__":
39+
run_server()

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
name = "analytics-mcp"
2+
name = "google-analytics-mcp"
33
version = "0.1.0"
44
requires-python = ">=3.9, <3.14"
55
license = "Apache-2.0"
@@ -11,6 +11,9 @@ dependencies = [
1111
"httpx>=0.28.1"
1212
]
1313

14+
[project.scripts]
15+
google-analytics-mcp = "analytics_mcp.server:run_server"
16+
1417
[project.optional-dependencies]
1518
dev = [
1619
"black",

0 commit comments

Comments
 (0)