Skip to main content
Glama
stack-system-mcp

stack-system-mcp

by mpvii
README.md
# stack-system-mcp

An MCP server for your [TheStack System](https://www.thestacksystem.com) speed-training
account — the active programme, its stats, your latest session's speeds, the
baseline, checkpoints and the programme catalogue — so an agent can answer
"how is my speed training going?" without opening the web app.

TheStack has no public API. This drives the Chrome/web app's own Firebase
backend with the session you create by signing in once in a real browser. It is
**read-only**: no tool starts, edits or deletes a programme or a session.

> Not affiliated with TheStack. The backend is private and unofficial, so a
> deploy can break it; the tests cover the shapes, not the service's promises.

## Privacy

- **Your password never reaches this process.** `login` opens Chromium; you sign
  in there (email, Google, Apple or phone). We read the Firebase session the app
  itself stored and put it in the macOS Keychain.
- **The repository holds nobody's data.** No account, name, email, speed, club or
  training history. Test fixtures are invented.
- **Raw captures stay local.** `samples/` is git-ignored; `scripts/privacy_scan.py`
  runs in CI to catch an accidental credential or absolute home path.
- **Read-only.** Only `stack_login`/`stack_logout` change local state (the
  Keychain item).

## Install

```bash
uv sync --extra login
uv run playwright install chromium
```

Requires macOS (Keychain) and Python 3.11+.

## Sign in

```bash
uv run stack-system-mcp login
```

A Chromium window opens on TheStack's sign-in page. Sign in, wait for the
dashboard, and the command exits once the Firebase session is captured:

```bash
uv run stack-system-mcp status
uv run stack-system-mcp logout
```

The refresh token is enough for the tools to mint new ID tokens, so the browser
is not needed again until the refresh token is revoked or expires.

## MCP client

```json
{
  "mcp": {
    "stack": {
      "type": "local",
      "command": ["uv", "run", "--directory", "/path/to/stack-system-mcp",
                  "stack-system-mcp", "serve"],
      "enabled": true
    }
  }
}
```

## Tools

| Tool | Returns |
| --- | --- |
| `stack_status` | whether a live session is stored, and when the token expires |
| `stack_login` / `stack_logout` | browser sign-in; remove the stored session |
| `stack_profile` | the account and active golfer: name, handicap, driver |
| `stack_access` | entitlements and membership dates |
| `stack_home` | programme label, speed card and golf headline |
| `stack_program` | the active programme: speeds, distance potential, grit, sessions |
| `stack_last_session` | the latest session's set-by-set peak speeds |
| `stack_lifetime` | all-time speed gained, peak eSpeed, swings, sessions |
| `stack_baseline` | baseline driver eSpeed, distance potential, recommendation |
| `stack_checkpoint` | the recent checkpoint and its grit window |
| `stack_templates` | the programme catalogue: group, sessions, phases |
| `stack_rounds` | Stack Stats: rounds, strokes gained, driving and putting |

**No next-session tool, on purpose.** The app's next-session callable
materialises a session before the user has swung; calling it would be a write.
`stack_home` still tells you which session is next.

## How it works

1. `session.py` captures the Firebase user record (ID token, refresh token and
   the public web API key) from the web app's IndexedDB/localStorage.
2. `auth.py` refreshes the ID token through Google's secure-token endpoint; the
   refreshed blob goes back to the Keychain.
3. `client.py` calls the app's Firebase callable functions (`ts2_*`) and reads
   Firestore documents (`users/{uid}`, `profiles/{activeProfileId}`) as the
   signed-in user. `ALLOWED_CALLS` is the read-only boundary: any callable not on
   that list is refused before a request is made.
4. `parse.py` turns the payloads into the small dictionaries the tools return;
   `service.py` wires one function per tool.

`discover` is a development command that calls the read functions and saves raw
JSON under the git-ignored `samples/` directory, for shaping new tools:

```bash
uv run stack-system-mcp discover
```

## Layout

```
src/stack_system_mcp/config.py    public Firebase project constants
src/stack_system_mcp/keychain.py  macOS Keychain wrapper
src/stack_system_mcp/session.py   Playwright sign-in, status, logout
src/stack_system_mcp/auth.py      refresh token -> ID token
src/stack_system_mcp/client.py    callable functions + Firestore reads
src/stack_system_mcp/parse.py     payload -> small dictionaries
src/stack_system_mcp/service.py   one function per tool, plus discover
src/stack_system_mcp/server.py    MCP tools + argparse CLI
```

## Licence

MIT.