mirror of
https://github.com/Dasemu/umami-analytics-mcp.git
synced 2026-11-26 07:16:08 +00:00
chore: bootstrap Claude setup
Add root CLAUDE.md, docs/, LESSONS.md, .env.example, project hooks (.claude/settings.json) and CI workflows (lint/test + versioning), per the standard repo bootstrap. No lint/test tooling exists yet, so hooks and CI only run a py_compile sanity check; CI/versioning target the development/main branch convention even though development does not exist yet. Deployment stays on Nixpacks for now (flagged in LESSONS.md pending a decision on migrating to the standard LXC/VPS+systemd setup). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b131f78870
commit
1153efcc33
10 files changed
+222
No files matched your search
@@ -0,0 +1 @@
|
||||
2
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Edit|Write",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "f=$(cat | python3 -c 'import json,sys;print(json.load(sys.stdin).get(\"tool_input\",{}).get(\"file_path\",\"\"))'); case \"$f\" in *.py) python3 -m py_compile \"$f\" ;; esac"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Stop": [
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "python3 -m py_compile server.py"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Umami instance base URL (no trailing slash), e.g. https://analytics.example.com
|
||||
UMAMI_HOST=
|
||||
|
||||
# Umami account used to authenticate against the API
|
||||
UMAMI_USERNAME=
|
||||
UMAMI_PASSWORD=
|
||||
|
||||
# Host/port the MCP server binds to (optional, defaults shown)
|
||||
BIND_HOST=127.0.0.1
|
||||
BIND_PORT=8083
|
||||
@@ -0,0 +1,26 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [development]
|
||||
push:
|
||||
branches: [development, main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
cache: "pip"
|
||||
|
||||
- name: Install dependencies
|
||||
run: pip install -r requirements.txt
|
||||
|
||||
# No linter or test suite is configured yet; this is a basic sanity check
|
||||
# that the source at least compiles.
|
||||
- name: Compile check
|
||||
run: python -m py_compile server.py
|
||||
@@ -0,0 +1,63 @@
|
||||
name: Version
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [development, main]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
bump:
|
||||
if: github.actor != 'github-actions[bot]'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Bump version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
current=$(cat VERSION)
|
||||
IFS=. read -r major minor patch <<< "$current"
|
||||
|
||||
if [ "${{ github.ref_name }}" = "development" ]; then
|
||||
patch=$((patch + 1))
|
||||
else
|
||||
# main: PATCH+1 for a direct hotfix push, MINOR+1/PATCH=0 when every
|
||||
# commit in this push came from development (an approved PR merge).
|
||||
merge_base=$(git merge-base origin/development HEAD 2>/dev/null || echo "")
|
||||
before="${{ github.event.before }}"
|
||||
if [ -n "$merge_base" ] && [ -n "$before" ] && [ "$before" != "0000000000000000000000000000000000000000" ] \
|
||||
&& git merge-base --is-ancestor "$before" origin/development 2>/dev/null; then
|
||||
minor=$((minor + 1))
|
||||
patch=0
|
||||
else
|
||||
patch=$((patch + 1))
|
||||
fi
|
||||
fi
|
||||
|
||||
new_version="$major.$minor.$patch"
|
||||
echo "$new_version" > VERSION
|
||||
git add VERSION
|
||||
git commit -m "chore(release): v$new_version [skip ci]"
|
||||
git tag "v$new_version"
|
||||
|
||||
- name: Push changes
|
||||
run: git push origin HEAD:${{ github.ref_name }} --follow-tags
|
||||
|
||||
- name: Merge main back into development
|
||||
if: github.ref_name == 'main'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git fetch origin development
|
||||
git checkout development
|
||||
git merge --no-edit origin/main
|
||||
git push origin development
|
||||
@@ -0,0 +1,34 @@
|
||||
# CLAUDE.md
|
||||
|
||||
## Overview
|
||||
MCP server exposing Umami analytics (pageviews, metrics, active visitors) as tools over
|
||||
streamable-HTTP, for use by MCP clients (e.g. Claude).
|
||||
|
||||
## Commands
|
||||
- Dev: `python server.py` (reads `UMAMI_HOST`, `UMAMI_USERNAME`, `UMAMI_PASSWORD` from env; see `.env.example`)
|
||||
- Install: `pip install -r requirements.txt`
|
||||
- Test: no test suite yet
|
||||
- Lint: no linter configured yet
|
||||
- Build: none (plain Python, run directly; `nixpacks.toml` defines the start command for Nixpacks-based hosting)
|
||||
|
||||
## Architecture
|
||||
Single-file server (`server.py`) built on `mcp.server.mcpserver.MCPServer`. Logs into the
|
||||
Umami API on first request, caches the bearer token in memory, and re-authenticates once on
|
||||
a 401. Each `@mcp.tool()` function wraps one Umami REST endpoint. See `docs/` for more.
|
||||
|
||||
## Conventions
|
||||
- Keep all tools as thin wrappers around the Umami API; push validation (e.g. `metric_type`)
|
||||
into the tool function, not into `_request`.
|
||||
- Dates/times accepted from callers are ISO strings or raw millisecond epochs (`_to_ms`).
|
||||
|
||||
## Workflow quirks
|
||||
- No tests or linter are set up; CI only compiles the source as a sanity check.
|
||||
|
||||
## Deployment
|
||||
Currently started via Nixpacks (`nixpacks.toml` → `python server.py`). This does not yet
|
||||
follow the standard LXC/VPS + systemd + authenticated update-endpoint setup described in the
|
||||
`web-deploy` skill; see `LESSONS.md`.
|
||||
|
||||
## Gotchas
|
||||
- `UMAMI_HOST`, `UMAMI_USERNAME`, `UMAMI_PASSWORD` are required; the process raises on import
|
||||
if any is missing (no defaults).
|
||||
@@ -0,0 +1,8 @@
|
||||
# LESSONS.md
|
||||
|
||||
Recurring mistakes in this repo and how to avoid them.
|
||||
|
||||
- Deployment is currently Nixpacks-based (`nixpacks.toml`), not the standard LXC/VPS +
|
||||
systemd + authenticated update-endpoint setup described by the `web-deploy` skill. Before
|
||||
changing deployment, confirm with the user whether to migrate it or leave Nixpacks as-is;
|
||||
don't silently add a systemd unit/update script without asking.
|
||||
@@ -0,0 +1,14 @@
|
||||
# ZenvairoAnalytics-MCP
|
||||
|
||||
MCP server that exposes Umami analytics data (websites, pageviews, metrics, active
|
||||
visitors) as tools, over streamable-HTTP.
|
||||
|
||||
## Quick start
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
cp .env.example .env # fill in your Umami credentials
|
||||
python server.py
|
||||
```
|
||||
|
||||
See `docs/` for architecture notes and `CLAUDE.md` for conventions and commands.
|
||||
@@ -0,0 +1,40 @@
|
||||
# Architecture
|
||||
|
||||
## Overview
|
||||
|
||||
`server.py` is a single-file MCP server built with `mcp.server.mcpserver.MCPServer`. It
|
||||
exposes the Umami analytics REST API as MCP tools so an MCP client can query website stats
|
||||
without talking to Umami directly.
|
||||
|
||||
## Auth flow
|
||||
|
||||
- On first request, `_login()` POSTs credentials to `UMAMI_HOST/api/auth/login` and caches
|
||||
the returned bearer token in the module-level `_token` variable, guarded by `_token_lock`.
|
||||
- `_request()` attaches the cached token to every call. On a `401`, it re-logs in once and
|
||||
retries the request before giving up.
|
||||
|
||||
## Tools
|
||||
|
||||
| Tool | Umami endpoint | Notes |
|
||||
|---|---|---|
|
||||
| `list_websites` | `GET /websites` | Includes websites from owned teams. |
|
||||
| `list_teams` | `GET /teams` | Teams/organizations the account belongs to. |
|
||||
| `list_team_websites` | `GET /teams/{id}/websites` | Websites in a team the account is a member (not owner) of. |
|
||||
| `get_website_stats` | `GET /websites/{id}/stats` | Pageviews, visitors, visits, bounces, time. |
|
||||
| `get_pageviews` | `GET /websites/{id}/pageviews` | Timeseries; `unit` is `hour`/`day`/`month`. |
|
||||
| `get_metrics` | `GET /websites/{id}/metrics` | `metric_type` restricted to `METRIC_TYPES`. |
|
||||
| `get_active_visitors` | `GET /websites/{id}/active` | Real-time visitor count. |
|
||||
|
||||
Dates are accepted as ISO date/datetime strings or raw millisecond epochs, normalized by
|
||||
`_to_ms`.
|
||||
|
||||
## Transport
|
||||
|
||||
Runs as `streamable-http` via `mcp.run(...)`, bound to `BIND_HOST`/`BIND_PORT`
|
||||
(defaults `127.0.0.1:8083`).
|
||||
|
||||
## Deployment
|
||||
|
||||
Currently started via Nixpacks (`nixpacks.toml`: `python server.py`). This has not yet been
|
||||
brought in line with the standard LXC/VPS + systemd + authenticated update-endpoint setup
|
||||
(see root `LESSONS.md`); no systemd unit, update script, or update endpoint exist yet.
|
||||
Reference in new issue
Block a user