Skip to content

feat: add session tools (get_sessions, get_session_stats, get_session_activity) - #26

Merged
Macawls merged 1 commit into
Macawls:mainfrom
simonjaneck:feat/session-tools
Jun 20, 2026
Merged

feat: add session tools (get_sessions, get_session_stats, get_session_activity)#26
Macawls merged 1 commit into
Macawls:mainfrom
simonjaneck:feat/session-tools

Conversation

@simonjaneck

Copy link
Copy Markdown
Contributor

What

Adds three tools that surface Umami's per-session data — the sessions that Session Replay records — which the server didn't expose before:

Tool Endpoint Returns
get_sessions GET /websites/{id}/sessions Paginated session list + total count; each row has browser, os, device, country/region/city, language, screen, visits, views, firstAt/lastAt
get_session_stats GET /websites/{id}/sessions/stats Flattened totals: pageviews, visitors, visits, countries, events
get_session_activity GET /websites/{id}/sessions/{sessionId}/activity Ordered pageview/event timeline for one session

Why

People with Session Replay enabled can see recorded sessions in the dashboard but can't reach them through the MCP. get_sessions gives the count + metadata, and get_session_activity reconstructs the page/event sequence of a visit — the closest data-level view of what a replay shows.

Notes

  • Activity date params: the /activity endpoint returns 400 "expected number, received NaN" when startAt/endAt are omitted on current Umami, despite the docs marking them optional. The client defaults them (0 .. now) so the tool works out of the box; callers can still pass a session's firstAt/lastAt to scope.
  • Refactored the shared validate website_id → normalize dates → run query → render flow into dateRangeQuery / textContent helpers; get_stats and get_session_stats now share it.
  • validateWebsiteID generalized to validateID, plus validateSessionID.
  • Added a session-insights prompt and README / tool-table entries.
  • .gitignore: also ignore the default umami-mcp-server build artifact (the existing entries only covered umami-mcp).

Testing

  • go test ./... — pass (added client tests for all three endpoints + validateSessionID).
  • golangci-lint v1.64.8 run ./... — clean.
  • Verified against a live self-hosted Umami: real session count, stats, and a full page/event timeline came back correctly.

🤖 Generated with Claude Code

…_activity)

The server exposed aggregate analytics but no way to reach Umami's
per-session data — the sessions that session replay records. Add three
tools wrapping the documented /sessions endpoints:

- get_sessions        — GET /websites/{id}/sessions: paginated session list
                        plus total `count`. Each row carries browser, os,
                        device, country/region/city, language, screen,
                        visits, views, firstAt/lastAt.
- get_session_stats   — GET /websites/{id}/sessions/stats: flattened totals
                        (pageviews, visitors, visits, countries, events).
- get_session_activity— GET /websites/{id}/sessions/{sessionId}/activity:
                        ordered pageview/event timeline for one session.

Notes:
- The activity endpoint rejects missing startAt/endAt on current Umami
  (400 "expected number, received NaN") despite the docs marking them
  optional, so the client defaults them (0 .. now) when the caller omits
  them; callers can still scope with the session's firstAt/lastAt.
- Refactored the shared "validate website_id + normalize dates + run query
  + render" flow into dateRangeQuery/textContent helpers; get_stats and
  get_session_stats now share it (removes a dupl-lint hit).
- validateWebsiteID generalized to validateID, plus validateSessionID.
- Added a session-insights prompt and README/tool-table entries.
- .gitignore: also ignore the default `umami-mcp-server` build artifact.

Tested against a live self-hosted Umami: all three tools return real data
(session count, stats, and a full page/event timeline). go test ./... and
golangci-lint v1.64.8 pass.
@Macawls
Macawls merged commit 141a451 into Macawls:main Jun 20, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants