Skip to main content
Glama
split-pro-mcp

split-pro-mcp

by GuiHue
README.md
# split-pro-mcp

An [MCP](https://modelcontextprotocol.io) server for [SplitPro](https://github.com/oss-apps/split-pro), the self-hosted expense-splitting app. It lets AI assistants (Claude, chat bots, agent frameworks) read balances and expenses, and add or change expenses. Every write needs an explicit preview and confirm step.

It is meant to run on your own network next to SplitPro, behind a TLS reverse proxy. It is not meant to be exposed to the internet.

Requires **SplitPro v2.2.0 or newer**. That is the first release with the public REST API (`/api/v1`) and API keys.

> [!WARNING]
> **Built entirely with AI. Use at your own risk.**
> The code, tests and docs in this repository were written by an AI coding assistant, with a human reviewing the results and making the decisions. It has an automated test suite and runs in one household, but it has not had an independent security review.
>
> This server can **create and change real financial records**. SplitPro API keys have no scopes, so a key used here can do everything its user can do through the API. Before you point it at the SplitPro instance you actually rely on, try it against a test instance or a copy of your data, keep backups of your SplitPro database, and read the code. The MIT license's "as is, without warranty" clause applies in full.

## Tools

| Tool | What it does |
| --- | --- |
| `whoami` | Which SplitPro user this connection acts as, plus friends, groups, and whether it may write |
| `list_categories` | Valid categories: a section such as `food`, or a sub-category such as `groceries` |
| `get_balances` | Who owes whom, per group or overall. A positive amount means the other person owes me |
| `list_expenses` | Newest first, with optional group, text search and date window |
| `get_expense` | One expense with each participant's share |
| `preview_expense` | Prepares a new expense from plain inputs ("42.80", "me", a name, equal or exact split). **Nothing is saved yet.** By default the key owner paid, and the cost is split equally between the members of the default group. |
| `preview_edit` | Prepares a change to an existing expense (description, amount, category, date, payer, split) and shows before and after. An equal split is recalculated when the amount changes |
| `preview_revert` | Prepares restoring an expense to its state before the last change made through this server, taken from the audit log |
| `confirm_expense` | Saves a preview. One-shot, expires after 15 minutes, and only the client that created it can confirm it |
| `new_expenses_digest` | Expenses *entered* in the last N hours, grouped by category area, with totals per area and per payer and my balance change. Includes a ready-to-send `text` (English or German) |

There is no delete tool, because SplitPro's API cannot delete. Delete in the app. Settlements, currency conversions, recurring expenses, and percentage or share splits can only be edited in the app.

The model never handles cents or SplitPro's signed participant balances. The server converts amounts, distributes odd cents, checks group membership and category, and builds the API payload. That removes a whole class of wrong-sign and off-by-100 mistakes.

## Security model

- **Every request needs a bearer token.** Each client (for example a desktop assistant and a chat bot) has its own token and its own SplitPro API key. The key decides which SplitPro user the client acts as, so expenses show the right person, and each client can be revoked on its own. Requests without a valid token get `401` before any tool runs. Only `GET /healthz` is open, and it returns no data.
- **Writes are opt-in per client** (`MCP_CLIENT_<NAME>_WRITE=true`), and always need preview + confirm. A preview can only be confirmed by the client that created it.
- **SplitPro API keys have no scopes.** A key can do everything its user can do through the API, including editing. This server is where access is narrowed, so don't reuse the keys elsewhere.
- **Audit log:** every write is appended to `/data/audit.jsonl` (client, action, full state before and after). It is the undo path for edits.
- **Host header check** (DNS-rebinding protection) via `MCP_ALLOWED_HOSTS`.
- Bind the port to a private address and put a reverse proxy with TLS and a source-IP allowlist in front. See `examples/Caddyfile`.

## Configuration

All configuration is via environment variables. See [`.env.example`](.env.example) for the full list. Generate client tokens with `openssl rand -base64 36`, and create SplitPro keys under **Account → API keys** in the account each client should act as.

| Variable | Default | Meaning |
| --- | --- | --- |
| `SPLITPRO_URL` | (required) | SplitPro base URL as reachable from the server |
| `MCP_CLIENTS` | (required) | Comma-separated client names |
| `MCP_CLIENT_<NAME>_TOKEN` | (required) | Bearer token for that client, at least 32 characters |
| `MCP_CLIENT_<NAME>_SPLITPRO_KEY` | (required) | SplitPro API key (`spro_…`) |
| `MCP_CLIENT_<NAME>_WRITE` | `false` | Allow preview/confirm of adds and edits |
| `MCP_DEFAULT_GROUP` | none | Group used when a call names none |
| `MCP_ALLOWED_HOSTS` | none (check off) | Accepted Host header values |
| `MCP_TIME_ZONE` | `UTC` | Time zone for "today" and expense dates |
| `MCP_DIGEST_LANGUAGE` | `en` | `en` or `de` for the digest text |
| `MCP_AUDIT_LOG` | `/data/audit.jsonl` | Audit log path; empty disables it |

## Run

With Docker, next to a Docker-based SplitPro:

```bash
cp .env.example .env && chmod 600 .env   # fill in
mkdir -p data && sudo chown 10001:10001 data
docker compose up -d --build
curl -fsS http://127.0.0.1:3002/healthz
```

The compose file joins SplitPro's Docker network (`splitpro_default` by default), so the server reaches SplitPro at `http://splitpro:3000` without going through the proxy.

For development:

```bash
python -m venv .venv && .venv/bin/pip install -e '.[test]'
.venv/bin/pytest -q
```

The MCP endpoint is `/mcp` (streamable HTTP, stateless, JSON responses).

## Connect clients

**Claude Code:**

```bash
claude mcp add --scope user --transport http splitpro https://splitpro-mcp.example.lan/mcp \
  --header "Authorization: Bearer <client token>"
```

**Other MCP clients:** configure an HTTP (streamable) MCP server with the URL above and an `Authorization: Bearer <token>` header.

Cloud-hosted assistants (for example web chat apps with remote connectors) can only use this server if it is reachable from the internet. That is not recommended for a write-capable finance tool.

## Daily digest

`examples/digest.py` calls `new_expenses_digest` and prints the ready-made text, or nothing if no expenses were entered. Run it from cron or an agent's scheduler and forward the output to a chat. No language model is involved, so the numbers are exactly what SplitPro has.

```bash
SPLITPRO_MCP_URL=https://splitpro-mcp.example.lan/mcp SPLITPRO_MCP_TOKEN=… examples/digest.py --hours 24
```

## After SplitPro updates

SplitPro's API is versioned `0.1.0` and is still being rolled out. After updating SplitPro, run `whoami` and a `preview_expense` once to check that the response shapes still match.

## License

MIT