From 1153efcc33fd05f6eb6b96cacce26458adab740a Mon Sep 17 00:00:00 2001 From: Dasemu Date: Sun, 18 Oct 2026 15:08:50 +0200 Subject: [PATCH] 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 --- .claude/bootstrap-version | 1 + .claude/settings.json | 25 ++++++++++++++ .env.example | 10 ++++++ .github/workflows/ci.yml | 26 +++++++++++++++ .github/workflows/version.yml | 63 +++++++++++++++++++++++++++++++++++ CLAUDE.md | 34 +++++++++++++++++++ LESSONS.md | 8 +++++ README.md | 14 ++++++++ VERSION | 1 + docs/architecture.md | 40 ++++++++++++++++++++++ 10 files changed, 222 insertions(+) create mode 100644 .claude/bootstrap-version create mode 100644 .claude/settings.json create mode 100644 .env.example create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/version.yml create mode 100644 CLAUDE.md create mode 100644 LESSONS.md create mode 100644 README.md create mode 100644 VERSION create mode 100644 docs/architecture.md diff --git a/.claude/bootstrap-version b/.claude/bootstrap-version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.claude/bootstrap-version @@ -0,0 +1 @@ +2 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..23b65e7 --- /dev/null +++ b/.claude/settings.json @@ -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" + } + ] + } + ] + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..625135f --- /dev/null +++ b/.env.example @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bbeb013 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..87524a4 --- /dev/null +++ b/.github/workflows/version.yml @@ -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 diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..7d7b577 --- /dev/null +++ b/CLAUDE.md @@ -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). diff --git a/LESSONS.md b/LESSONS.md new file mode 100644 index 0000000..be24a47 --- /dev/null +++ b/LESSONS.md @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d0f25f0 --- /dev/null +++ b/README.md @@ -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. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..074d7c7 --- /dev/null +++ b/docs/architecture.md @@ -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.