Skip to main content
Glama
README.md
# bookamate

Python client (`bookamate`) and local MCP server (`bookamate-mcp`) for the [bookamat API](https://www.bookamat.com/dokumentation/api/v1/index.html), in one uv workspace. Unofficial; not affiliated with or endorsed by bookamat.

> **Status:** early development, not yet released.

## Packages

| Package | What it is |
| --- | --- |
| `bookamate` | Typed client for the bookamat API, async with a generated sync variant |
| `bookamate-mcp` | Local MCP server for AI agents such as Claude Code and Mistral Vibe, built on `bookamate` |
| `bookamate-mock` | Local mock of the bookamat API for tests and for trying things out; not published |

The MCP server runs only locally, over stdio, with your own bookamat username and personal API key. It talks to bookamat directly; there is no hosted version. Note that your agent's MCP client passes tool results, including booking data, to the AI provider behind it.

## Settings

The client and the MCP server take their settings from environment variables. With the client, an argument to `Client(...)` or `AsyncClient(...)` wins over its variable.

| Variable | Argument | Default | What it is |
| --- | --- | --- | --- |
| `BOOKAMATE_USERNAME` | `username` | required | Your bookamat username |
| `BOOKAMATE_API_KEY` | `api_key` | required | Your personal API key, under "Mein Account" in bookamat |
| `BOOKAMATE_BASE_URL` | `base_url` | `https://www.bookamat.com/api/v1/` | The API root; point it at `bookamate-mock` for tests |
| `BOOKAMATE_SUBDOMAIN` | `subdomain` | none | Your Subdomain, as in `https://<subdomain>.bookamat.com/`, for links into the web UI |
| `BOOKAMATE_RETRY_ATTEMPTS` | `retry_attempts` | `3` | Attempts per request, the first included |
| `BOOKAMATE_RETRY_TIMEOUT` | `retry_timeout` | `30` | Seconds all attempts of one request may take |
| `BOOKAMATE_CONNECT_TIMEOUT` | `connect_timeout` | `5` | Seconds to wait for a connection |
| `BOOKAMATE_READ_TIMEOUT` | `read_timeout` | `30` | Seconds to wait for an answer |

A client sends one request at a time, since bookamat rejects parallel requests of one user. It retries connection errors, and for reading requests also timeouts and `502`, `503` and `504`; it never resends a `POST` or `PATCH` that reached bookamat. A `429` is retried after its `Retry-After` when that fits the time left; a longer wait, e.g. a reached hourly limit, is raised at once as `api:429`, with the wait at the end of its message. A `429` without `Retry-After` is retried like a `503`.

Neither reads a `.env` file itself. To keep the values in one, let the tool that starts the program load it, e.g. `uv run --env-file` or `uvx --env-file`.

### Registering the MCP server from PyPI

Point your agent at `uvx` with the absolute path of your `.env` file, e.g. in Claude Code:

```sh
claude mcp add bookamate -- uvx --env-file /absolute/path/to/.env bookamate-mcp
```

The path must be absolute: the agent starts the server from a working directory of its own.

## Development

### Commands

Run from the repo root. Where a command needs an absolute path, replace `/path/to/bookamate` with your checkout. The sections below explain them and link back here.

| Task | Command | Note |
| --- | --- | --- |
| Set up | `uv sync --all-packages` | |
| Install the hooks | `uv run pre-commit install` | Once; the hooks then run on every commit |
| Tests | `uv run pytest` | One package: `uv run pytest packages/bookamate` |
| Lint and types | `uv run ruff check --fix && uv run ruff format && uv run pyright` | |
| All hooks | `uv run pre-commit run --all-files` | ruff, pyright, markdownlint, gitleaks, zizmor, sync-client check. Tracked files only: `git add` new files first |
| Regenerate the sync client | `uv run python scripts/generate_sync.py` | After changing `_async/`; commit both together |
| SonarQube analysis | `uv run pytest --cov --cov-report=xml && uv run --env-file .env pysonar` | Needs `SONAR_HOST_URL` and `SONAR_TOKEN` in `.env` |
| Check the upstream docs for changes | `uv run python scripts/fetch_api_docs.py --dry-run` | Downloads and reports, writes nothing |
| Refresh the upstream docs mirror | `uv run python scripts/fetch_api_docs.py` | Maintainer only; then update the impact table |
| Probe the live API, report only | `uv run --env-file .env python scripts/probe_api.py --dry-run` | Maintainer only, real account: GET, HEAD and OPTIONS on every documented path (about 130 requests), one at a time. Keeps status, headers, OPTIONS and error bodies, and only the shape of GET bodies. `--page bookings` for one upstream page, `--package at/2025` for another year |
| Record the live probe | `uv run --env-file .env python scripts/probe_api.py` | Maintainer only; writes `docs/bookamat-api/live/<time>/`, one folder per upstream page with `reads.json` (GET), `writes.json` (write schemas from OPTIONS) and `http.json` (statuses, headers), and points `latest` at it when something changed |
| Compare the models with the live probe | `uv run python scripts/check_models.py` | Local files only: reads `docs/bookamat-api/live/latest/`; lists each difference: fields, types and required from GET bodies; fields, types, read-only and max. length from OPTIONS where the resource takes writes; names write-only fields (writable, sent by no GET answer) without counting them |
| Start the mock server | `uv run bookamate-mock` | Prints its base URL; `--host` and `--port` change it (default `127.0.0.1:8000`) |
| MCP Inspector against the mock | `npx @modelcontextprotocol/inspector -e BOOKAMATE_BASE_URL=http://127.0.0.1:8000/api/v1/ -e BOOKAMATE_USERNAME=dev -e BOOKAMATE_API_KEY=dummy -- uv run --directory /path/to/bookamate bookamate-mcp` | Mock running. `-e` variables go before `--`. Optional: `--protocol-era auto` before `--` (web UI only; the Inspector defaults to `legacy`) |
| MCP Inspector against your account | `npx @modelcontextprotocol/inspector -- uv run --env-file /path/to/bookamate/.env --directory /path/to/bookamate bookamate-mcp` | Real account: read only. Optional: `--protocol-era auto` before `--` (web UI only) |
| One MCP call without a browser | `npx @modelcontextprotocol/inspector --cli -e BOOKAMATE_BASE_URL=http://127.0.0.1:8000/api/v1/ -e BOOKAMATE_USERNAME=dev -e BOOKAMATE_API_KEY=dummy --method tools/list -- uv run --directory /path/to/bookamate bookamate-mcp` | Mock running. `--cli` comes first; call a tool with `--method tools/call --tool-name list_user_accounts` |
| Register in Claude Code against the mock | `claude mcp add bookamate-mock-dev -e BOOKAMATE_BASE_URL=http://127.0.0.1:8000/api/v1/ -e BOOKAMATE_USERNAME=dev -e BOOKAMATE_API_KEY=dummy -- uv run --directory /path/to/bookamate bookamate-mcp` | Mock running |
| Register in Claude Code against your account | `claude mcp add bookamate-dev -- uv run --env-file /path/to/bookamate/.env --directory /path/to/bookamate bookamate-mcp` | Real account: read only |
| Remove a Claude Code registration | `claude mcp remove bookamate-dev` | Or `bookamate-mock-dev` |

### Checks, upstream docs and SonarQube

CI runs the tests and all hooks on every pull request and on every push to `main`. Tests run against `bookamate-mock`, a local mock of the bookamat API, and never call a real account.

The [upstream docs commands](#commands) mirror the upstream docs into `docs/bookamat-api/upstream/` (gitignored, German, one `.txt` per page). Each version the script finds goes into a new folder named after the fetch time (`2026-11-30T160515Z`), `upstream/latest` points at the newest, and older folders stay untouched, so `diff -r` shows what changed between any two. A fetch without changes writes nothing. For each new version it finds compared with the previous one, the script adds an entry to the tracked [`docs/bookamat-api/upstream-changes.md`](docs/bookamat-api/upstream-changes.md): the new upstream changelog entries and the pages added, removed and changed; before committing, update the [impact table](docs/bookamat-api/impact.md) and the entry's `Affects:` line as the table describes. Rerun it before working on a resource and after a new upstream changelog entry; it lists the changed pages and prints the newest changelog date. `--base-url` mirrors from another docs root. The first run after updating moves an older flat mirror into a dated folder.

SonarQube analysis runs locally against your own server, with the [command above](#commands). The settings (project key, sources, exclusions) are in `[tool.sonar]` in `pyproject.toml`.

### Keeping secrets and real data out of the repo

The repo is public and must never contain credentials or data from a real bookamat account. [gitleaks](https://github.com/gitleaks/gitleaks) checks this in the pre-commit hook and again in CI, since a local hook can be skipped. Besides secrets, it rejects a real Subdomain, in a web UI address or in `BOOKAMATE_SUBDOMAIN`: docs and examples use `example`, `your-subdomain` or `<subdomain>` (`.gitleaks.toml`). GitHub push protection is enabled as a further check.

### Credentials during development

Credentials live in one `.env` file in the repo root, which is gitignored; start it from the committed template with `cp .env.example .env`. It holds one set of variables per environment: the plain names for your real account, the same names with `MOCK` for the mock server, which accepts any value.

```dotenv
BOOKAMATE_USERNAME=your-username
BOOKAMATE_API_KEY=your-api-key
# Optional: your Subdomain, as in https://your-subdomain.bookamat.com/, for links
# into the web UI. The API doesn't expose it.
BOOKAMATE_SUBDOMAIN=your-subdomain

# Optional; defaults to https://www.bookamat.com/api/v1/
# BOOKAMATE_BASE_URL=

BOOKAMATE_MOCK_USERNAME=dev
BOOKAMATE_MOCK_API_KEY=dummy
```

Tools load the file; the code only reads environment variables and never opens `.env` itself:

- `uv run --env-file /path/to/bookamate/.env …` for the client and the MCP server (used in the agent setups below). Variables already set in the environment win over the file.
- `{{$dotenv %keyVar}}` in the `.http` files. VS Code's [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) finds the root `.env` by searching upwards from the `.http` file, and the selected REST Client environment names which set to read.
- `"envFile": "${workspaceFolder}/.env"` in a `launch.json` debug configuration.

Define the REST Client environments in your VS Code user settings (or `.vscode/settings.json`, which is gitignored). They hold no secrets, only the base URL and the names of the variables to read:

```jsonc
"rest-client.environmentVariables": {
  "$shared": {
    "country": "at",
    "year": "2026"
  },
  "live": {
    "base_url": "https://www.bookamat.com/api/v1",
    "username_key": "BOOKAMATE_USERNAME",
    "api_key_key": "BOOKAMATE_API_KEY",
    "subdomain_key": "BOOKAMATE_SUBDOMAIN"
  },
  "mock": {
    "base_url": "http://127.0.0.1:8000/api/v1",
    "username_key": "BOOKAMATE_MOCK_USERNAME",
    "api_key_key": "BOOKAMATE_MOCK_API_KEY"
  }
}
```

`country` and `year` choose the annual package the requests read. Keep `base_url` in each environment, not in `$shared`, so that `mock` never reaches the real API. Select an environment with Ctrl+Alt+E; with none selected, every `{{$dotenv %…_key}}` stays empty.

Keep credentials out of every other file, including `.vscode/`, `launch.json`, `*.code-workspace` files and `.http` files.

### Trying your working copy in an agent

To try local changes in a real client, point it at `uv run` in your checkout. `uv run` runs the source as it is on disk, so every server restart picks up your edits.

The server then talks to your real bookamat account. bookamat has no test environment and the account is audited, so try only reading this way. To try writing, use the mock server instead (see below).

Use a name of its own (here `bookamate-dev`) so it can sit next to an installed version.

#### Claude Code

Register it with the [Claude Code command for your account](#commands). Check that it is connected with `/mcp`. After changing code, reconnect it in `/mcp` (or restart Claude Code).

#### Mistral Vibe

Add to `~/.vibe/config.toml`, then restart Vibe:

```toml
[[mcp_servers]]
name = "bookamate-dev"
transport = "stdio"
command = "uv"
args = ["run", "--env-file", "/path/to/bookamate/.env", "--directory", "/path/to/bookamate", "bookamate-mcp"]
```

#### Without an agent

The MCP Inspector lists the tools and shows their raw results, in a web UI or, with `--cli`, for one call in the terminal. See the [Inspector commands](#commands).

### Trying writes against the mock server

Start the mock and register a second server that points at the base URL it prints, with dummy credentials instead of the `.env` file; both commands are in the [table](#commands). The mock accepts any credentials, and its data is synthetic. Only the resources and methods it mocks are available; everything else answers `501 Not Implemented`.

## License

[Apache License 2.0](LICENSE)