@altipard/sevdesk-mcp 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +612 -2
  3. package/dist/bin/http.js +31 -0
  4. package/dist/bin/stdio.js +201 -0
  5. package/dist/config.js +333 -0
  6. package/dist/http/app.js +267 -0
  7. package/dist/http/jwt-verifier.js +94 -0
  8. package/dist/http/redis.js +112 -0
  9. package/dist/http/scope-challenge.js +43 -0
  10. package/dist/http/start.js +382 -0
  11. package/dist/keychain.js +108 -0
  12. package/dist/logger.js +49 -0
  13. package/dist/policy/audit.js +33 -0
  14. package/dist/policy/classification.js +214 -0
  15. package/dist/policy/confirm.js +127 -0
  16. package/dist/policy/guard.js +319 -0
  17. package/dist/policy/nonce-store.js +42 -0
  18. package/dist/policy/operations.js +1164 -0
  19. package/dist/policy/pins.js +209 -0
  20. package/dist/policy/redis-nonce-store.js +132 -0
  21. package/dist/policy/registry.js +227 -0
  22. package/dist/policy/rights.js +94 -0
  23. package/dist/policy/runtime.js +38 -0
  24. package/dist/policy/scope.js +237 -0
  25. package/dist/redact.js +21 -0
  26. package/dist/server.js +74 -0
  27. package/dist/sevdesk/client.js +426 -0
  28. package/dist/sevdesk/errors.js +98 -0
  29. package/dist/tools/account.js +34 -0
  30. package/dist/tools/banking.js +149 -0
  31. package/dist/tools/contact-writes.js +456 -0
  32. package/dist/tools/contacts.js +514 -0
  33. package/dist/tools/document-actions.js +362 -0
  34. package/dist/tools/document-common.js +138 -0
  35. package/dist/tools/document-drafts.js +335 -0
  36. package/dist/tools/documents.js +116 -0
  37. package/dist/tools/format.js +404 -0
  38. package/dist/tools/generic.js +477 -0
  39. package/dist/tools/guidance.js +94 -0
  40. package/dist/tools/index.js +58 -0
  41. package/dist/tools/invoice-actions.js +465 -0
  42. package/dist/tools/invoices.js +441 -0
  43. package/dist/tools/orders.js +118 -0
  44. package/dist/tools/parts.js +63 -0
  45. package/dist/tools/reports.js +86 -0
  46. package/dist/tools/result.js +186 -0
  47. package/dist/tools/voucher-writes.js +519 -0
  48. package/dist/tools/vouchers.js +184 -0
  49. package/dist/tools/write-common.js +697 -0
  50. package/dist/version.js +9 -0
  51. package/package.json +76 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zilicon IT Services
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,613 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="assets/logo/sevdesk-mcp.svg" alt="sevdesk-mcp logo: an owl bookkeeper with spectacles" width="160">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <h1 align="center">sevdesk-mcp</h1>
6
+
7
+ <p align="center">
8
+ <b>A sevdesk MCP server: ask your AI assistant about invoices, contacts, vouchers and bank transactions in sevdesk.</b><br>
9
+ Unofficial. Curated tools, read-only by default; status changes, bookings and irreversible actions need confirmation.
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://github.com/altipard/sevdesk-mcp/actions/workflows/ci.yml"><img src="https://github.com/altipard/sevdesk-mcp/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
14
+ <a href="https://www.npmjs.com/package/@altipard/sevdesk-mcp"><img src="https://img.shields.io/npm/v/@altipard/sevdesk-mcp" alt="npm version"></a>
15
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
16
+ <img src="https://img.shields.io/badge/node-%3E%3D24-339933?logo=node.js&logoColor=white" alt="Node.js 24 or newer">
17
+ </p>
18
+
19
+ <!-- Demo GIF goes here once a recording exists. -->
20
+
21
+ sevdesk-mcp is a [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server
22
+ for the [sevdesk](https://sevdesk.de) accounting API. It connects sevdesk to AI assistants
23
+ and MCP clients such as Claude Desktop, Claude Code, Cursor and VS Code, so you can ask
24
+ questions like "which invoices are overdue?" or "did the payment from ACME arrive?" in
25
+ plain language. Instead of exposing the whole API it offers a small set of curated tools
26
+ with compact answers, plus a guarded fallback for everything else.
27
+
28
+ > [!IMPORTANT]
29
+ > **Unofficial.** This project is not affiliated with, endorsed by or supported by
30
+ > sevdesk GmbH. "sevdesk" is a trademark of sevdesk GmbH and is used here only to
31
+ > name the API this server talks to.
32
+
33
+ ## Contents
34
+
35
+ - [Install](#install)
36
+ - [Connect your MCP client](#connect-your-mcp-client)
37
+ - [What it can do](#what-it-can-do)
38
+ - [Security model](#security-model)
39
+ - [Remote (HTTP)](#remote-http)
40
+ - [Configuration](#configuration)
41
+ - [Status](#status)
42
+ - [Development](#development)
43
+ - [License](#license)
44
+
45
+ ## Install
46
+
47
+ You need a sevdesk API token (32 hex characters; sevdesk issues one per administrator).
48
+ Pick one of the following.
49
+
50
+ **Installer** (macOS and Linux with glibc, x64 and arm64):
51
+
52
+ ```sh
53
+ curl -fsSL https://raw.githubusercontent.com/altipard/sevdesk-mcp/main/install.sh | sh
54
+ ```
55
+
56
+ It downloads the release binary for your platform, verifies it against the release's
57
+ `SHA256SUMS` (nothing is installed on a mismatch) and installs it to `~/.local/bin`. In a
58
+ terminal it then offers a guided setup, asking before every step:
59
+
60
+ 1. store the API token in the system keychain,
61
+ 2. pick the mode for the client entries (`read`, `write` or `full`, default `read`),
62
+ 3. register the server with Claude Desktop, Claude Code, Cursor and VS Code.
63
+
64
+ The token never goes into a client configuration file. Existing client configs are backed
65
+ up before they are changed and are left alone if they are not valid JSON; changing them
66
+ needs `jq` or `python3`, otherwise the installer prints the snippet to add by hand.
67
+ Without a terminal it installs only and prints the next steps.
68
+
69
+ **npx** (any platform with Node.js 24 or newer), nothing to install up front:
70
+
71
+ ```sh
72
+ npx -y @altipard/sevdesk-mcp
73
+ ```
74
+
75
+ <details>
76
+ <summary>installer options, manual download, from source</summary>
77
+
78
+ <br>
79
+
80
+ **Options**, passed after `sh -s --`:
81
+
82
+ | Option | Meaning |
83
+ | --- | --- |
84
+ | `--dry-run` | Show platform, release and target without downloading or changing anything. |
85
+ | `--no-setup` | Install only, skip the keychain and MCP client setup. |
86
+ | `-h`, `--help` | Show the help. |
87
+
88
+ **Environment variables**, set for `sh`:
89
+
90
+ | Variable | Default | Meaning |
91
+ | --- | --- | --- |
92
+ | `INSTALL_DIR` | `~/.local/bin` | Target directory, absolute path, created if missing, must be writable. |
93
+ | `SEVDESK_MCP_VERSION` | `latest` | Release to install, for example `0.2.0` (tags have no `v` prefix). |
94
+ | `NO_COLOR` | | Set to any value to disable colored output. |
95
+
96
+ ```sh
97
+ curl -fsSL https://raw.githubusercontent.com/altipard/sevdesk-mcp/main/install.sh \
98
+ | INSTALL_DIR="$HOME/bin" SEVDESK_MCP_VERSION=0.2.0 sh -s -- --no-setup
99
+ ```
100
+
101
+ The installer needs `curl` and `sha256sum` or `shasum`. Release binaries exist for
102
+ `darwin-arm64`, `darwin-x64`, `linux-x64` and `linux-arm64`; under Rosetta it picks the
103
+ native arm64 binary. The Linux binaries are built against glibc, so on musl systems such as
104
+ Alpine use npx instead.
105
+
106
+ **Manual download.** Every release carries `sevdesk-mcp-<os>-<arch>` plus `SHA256SUMS`:
107
+
108
+ ```sh
109
+ base=https://github.com/altipard/sevdesk-mcp/releases/latest/download
110
+ asset=sevdesk-mcp-linux-x64
111
+ curl -fsSLO "$base/$asset"
112
+ curl -fsSLO "$base/SHA256SUMS"
113
+ grep " $asset\$" SHA256SUMS | sha256sum -c - # macOS: shasum -a 256 -c -
114
+ mkdir -p ~/.local/bin
115
+ install -m 755 "$asset" ~/.local/bin/sevdesk-mcp
116
+ ```
117
+
118
+ **From source** (Node.js 24 or newer):
119
+
120
+ ```sh
121
+ git clone https://github.com/altipard/sevdesk-mcp.git
122
+ cd sevdesk-mcp
123
+ npm ci
124
+ npm run build
125
+ node dist/bin/stdio.js
126
+ ```
127
+
128
+ </details>
129
+
130
+ ### Keep the token in the keychain
131
+
132
+ If `SEVDESK_API_TOKEN` is unset, the server reads the token from the system keychain at
133
+ start: service `sevdesk-mcp`, account `api-token`. That way no client configuration holds
134
+ the token. The installer's setup stores it there; to do it by hand:
135
+
136
+ macOS (prompts for the token, so it does not land in your shell history):
137
+
138
+ ```sh
139
+ security add-generic-password -U -s sevdesk-mcp -a api-token -w
140
+ ```
141
+
142
+ Linux with a Secret Service keyring (GNOME Keyring, KWallet) and `secret-tool`
143
+ (`libsecret-tools` on Debian and Ubuntu):
144
+
145
+ ```sh
146
+ secret-tool store --label=sevdesk-mcp service sevdesk-mcp account api-token
147
+ ```
148
+
149
+ `SEVDESK_API_TOKEN` always wins over the keychain. On systems without a keychain, set it in
150
+ the client's `env` block.
151
+
152
+ ## Connect your MCP client
153
+
154
+ All clients below start the server as a local process over stdio; to run it as a shared
155
+ service instead, see [Remote (HTTP)](#remote-http). The installer's setup writes
156
+ these entries for you; the snippets below are for doing it by hand. Replace
157
+ `/Users/you/.local/bin/sevdesk-mcp` with the absolute path of your binary (`echo
158
+ ~/.local/bin/sevdesk-mcp`).
159
+
160
+ > [!WARNING]
161
+ > Never put the API token into a project or workspace file that goes into a repository
162
+ > (`.cursor/mcp.json`, `.vscode/mcp.json`, `.mcp.json`). Prefer the keychain. Without one,
163
+ > use user-level configuration only: in Cursor reference an environment variable with
164
+ > `${env:SEVDESK_API_TOKEN}`, in VS Code let it prompt with `${input:…}` (below).
165
+
166
+ **npx instead of the binary.** Set `"command": "npx"` and
167
+ `"args": ["-y", "@altipard/sevdesk-mcp"]`. GUI clients often start without your shell's
168
+ `PATH`, so give the full path to `npx` (`which npx`) or, better, use the binary.
169
+
170
+ **Windows** (untested) has no release binary and no keychain lookup: use npx through
171
+ `cmd`, for example `"command": "cmd", "args": ["/c", "npx", "-y", "@altipard/sevdesk-mcp"]`,
172
+ and supply the token as above. Claude Desktop has no token reference, so on Windows the
173
+ token sits in plain text in its user configuration file. Cursor's `${env:…}` can stay empty
174
+ when Cursor is started from the GUI rather than a shell that has the variable. Claude
175
+ Desktop reads `%APPDATA%\Claude\claude_desktop_config.json`,
176
+ the VS Code user configuration lives in `%APPDATA%\Code\User\mcp.json`, and Cursor uses
177
+ `%USERPROFILE%\.cursor\mcp.json`.
178
+
179
+ <details>
180
+ <summary>Claude Desktop</summary>
181
+
182
+ <br>
183
+
184
+ Settings > Developer > Edit Config opens `claude_desktop_config.json`:
185
+
186
+ ```json
187
+ {
188
+ "mcpServers": {
189
+ "sevdesk": {
190
+ "command": "/Users/you/.local/bin/sevdesk-mcp",
191
+ "env": { "SEVDESK_MODE": "read" }
192
+ }
193
+ }
194
+ }
195
+ ```
196
+
197
+ Restart Claude Desktop afterwards.
198
+
199
+ </details>
200
+
201
+ <details>
202
+ <summary>Claude Code</summary>
203
+
204
+ <br>
205
+
206
+ ```sh
207
+ claude mcp add --scope user sevdesk --env SEVDESK_MODE=read -- ~/.local/bin/sevdesk-mcp
208
+ ```
209
+
210
+ Leave out `--scope user` to register it for the current project only.
211
+
212
+ </details>
213
+
214
+ <details>
215
+ <summary>Cursor</summary>
216
+
217
+ <br>
218
+
219
+ `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project, never with a
220
+ token):
221
+
222
+ ```json
223
+ {
224
+ "mcpServers": {
225
+ "sevdesk": {
226
+ "command": "/Users/you/.local/bin/sevdesk-mcp",
227
+ "env": { "SEVDESK_MODE": "read" }
228
+ }
229
+ }
230
+ }
231
+ ```
232
+
233
+ Without a keychain, in `~/.cursor/mcp.json` only, pass the token from your environment:
234
+ `"env": { "SEVDESK_MODE": "read", "SEVDESK_API_TOKEN": "${env:SEVDESK_API_TOKEN}" }`.
235
+
236
+ </details>
237
+
238
+ <details>
239
+ <summary>VS Code</summary>
240
+
241
+ <br>
242
+
243
+ ```sh
244
+ code --add-mcp '{"name":"sevdesk","type":"stdio","command":"/Users/you/.local/bin/sevdesk-mcp","env":{"SEVDESK_MODE":"read"}}'
245
+ ```
246
+
247
+ Or in `.vscode/mcp.json` in a workspace (no token in this file):
248
+
249
+ ```json
250
+ {
251
+ "servers": {
252
+ "sevdesk": {
253
+ "type": "stdio",
254
+ "command": "/Users/you/.local/bin/sevdesk-mcp",
255
+ "env": { "SEVDESK_MODE": "read" }
256
+ }
257
+ }
258
+ }
259
+ ```
260
+
261
+ Without a keychain, VS Code can prompt for the token once and store it securely; the
262
+ file then holds only the reference, not the token:
263
+
264
+ ```json
265
+ {
266
+ "inputs": [
267
+ { "type": "promptString", "id": "sevdesk-token", "description": "sevdesk API token", "password": true }
268
+ ],
269
+ "servers": {
270
+ "sevdesk": {
271
+ "type": "stdio",
272
+ "command": "/Users/you/.local/bin/sevdesk-mcp",
273
+ "env": { "SEVDESK_MODE": "read", "SEVDESK_API_TOKEN": "${input:sevdesk-token}" }
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+ </details>
280
+
281
+ Other settings from [Configuration](#configuration), for example
282
+ `SEVDESK_DENIED_TOOLS=get_report`, go into the same `env` block.
283
+
284
+ > [!TIP]
285
+ > Ask the assistant to call `get_account_info` first. It checks the connection and tells
286
+ > you which mode the server runs in.
287
+
288
+ ## What it can do
289
+
290
+ Each tool wraps one or a few sevdesk API calls and returns a short text plus compact
291
+ structured JSON. `get_document_pdf` and `get_report` return the file as an embedded
292
+ resource. Which tools are registered depends on the mode (see
293
+ [Security model](#security-model)): `read` offers only the read tools.
294
+
295
+ **Read tools** (available in every mode):
296
+
297
+ | Tool | What it does |
298
+ | --- | --- |
299
+ | `get_account_info` | Checks the connection, returns the bookkeeping system version and the server's mode. |
300
+ | `search_contacts` | Finds contacts by name, customer number or e-mail. Name and e-mail search scan at most 500 contacts or addresses, plus up to 100 organisations from sevdesk's own name filter, and say when they stopped early. |
301
+ | `get_contact` | One contact with master data, addresses and communication ways. |
302
+ | `search_invoices` | Lists invoices by status, date range, contact or invoice number, with open amounts. |
303
+ | `get_invoice` | One invoice with positions, amounts, dates and status. |
304
+ | `list_open_receivables` | Open and partially paid invoices with days overdue, totals per currency and type. Recurring-invoice templates (WKR) are left out by default; the answer can be marked incomplete after a timeout or failed page. |
305
+ | `get_document_pdf` | The rendered PDF of an invoice, credit note or order, without marking it as sent. |
306
+ | `search_orders` | Estimates, order confirmations and delivery notes by status, date, contact or number. |
307
+ | `search_vouchers` | Vouchers (incoming invoices, receipts) by status, date, text, debit/credit or supplier. |
308
+ | `get_voucher` | One voucher with positions, booking accounts and tax rates. |
309
+ | `list_bank_accounts` | Payment accounts (bank, cash, clearing) with balance and IBAN. |
310
+ | `search_transactions` | Bank transactions by account, date, reference, payer/payee, booked or open, direction. |
311
+ | `search_parts` | Parts (products and services) with prices, tax rate and stock. |
312
+ | `get_tax_guidance` | Which booking accounts, tax rules and tax rates sevdesk allows together. |
313
+ | `get_report` | sevdesk's rendered list report (usually a PDF) of invoices, orders, contacts or vouchers. |
314
+ | `sevdesk_api_request` | Guarded fallback: calls one sevdesk operation without a dedicated tool by `operationId`. |
315
+
316
+ **Write tools.** Class `W` runs directly from `SEVDESK_MODE=write` on. Class `W+` also
317
+ needs `write` and runs in two steps with a confirmation token. Class `X` needs `full`, is
318
+ off until the operator lists it in `SEVDESK_ENABLE_TOOLS`, and needs a confirmation token
319
+ plus approval by a human (elicitation) or, on clients without elicitation, the operator
320
+ release that this listing stands for. There is no delete tool.
321
+
322
+ | Tool | Class | What it does |
323
+ | --- | --- | --- |
324
+ | `create_contact` | W | Creates an organisation or person, by default as customer with the next free customer number, optionally with invoice address, e-mail and phone. |
325
+ | `update_contact` | W | Changes master data of a contact and, where unambiguous, its address, e-mail or phone; with several entries it fails and lists their IDs. |
326
+ | `create_invoice_draft` | W | Creates an invoice draft (RE) with free-text or article positions; tax rule and rates are checked first. No invoice number, not sent. |
327
+ | `create_order_draft` | W | Creates an estimate (AN) or order confirmation (AB) as draft, with the same checks. Not sent. |
328
+ | `create_invoice_from_order` | W | Turns an estimate or order confirmation into an invoice draft: whole (RE), partial (TR) or advance (AR). |
329
+ | `create_voucher` | W | Creates a voucher (Beleg) as draft, optionally with the receipt file attached; accounts, tax rule and rates are checked first. |
330
+ | `tag_document` | W | Sets a tag by name on an invoice, voucher, order or credit note; sevdesk creates the tag if it does not exist. |
331
+ | `mark_invoice_sent` | W+ | Marks an invoice as sent (printed, by post, by e-mail outside sevdesk, downloaded) without sending anything; a draft gets its invoice number. |
332
+ | `book_invoice_payment` | W+ | Books a payment on an open or partially paid invoice to a payment account, with an explicit payment type (full, partial, Skonto, bank charges, other, reminder fees). |
333
+ | `book_voucher_payment` | W+ | Books a payment on an unpaid or partially paid voucher, with the same payment types. |
334
+ | `reset_document_status` | W+ | Resets an invoice, credit note or voucher to draft or to open; linked payments are unlinked. Enshrined documents are refused. |
335
+ | `send_invoice_email` | X | Sends an invoice to the customer by e-mail through sevdesk, with explicit recipient, subject and text. |
336
+ | `cancel_invoice` | X | Cancels an invoice by creating a numbered cancellation invoice (Stornorechnung). |
337
+ | `enshrine_document` | X | Enshrines (festschreiben) an invoice, credit note or voucher; afterwards it can never be changed, reset or deleted (GoBD). |
338
+
339
+ `create_voucher` attaches a receipt as PDF, PNG or JPEG up to 10 MiB, passed as base64.
340
+ The draft tools create a new object on every call, and the payment tools book again on
341
+ every confirmed call.
342
+
343
+ > [!CAUTION]
344
+ > **Try write tools on test data first.** They are tested against the sevdesk OpenAPI spec
345
+ > and a mocked API, but the spec is incomplete and some request shapes can only be
346
+ > verified against a live account. Start with a test contact and a test draft, check the
347
+ > result in sevdesk, and only then use them on real bookkeeping data.
348
+
349
+ `sevdesk_api_request` only accepts operations on its allowlist. By default that is a
350
+ curated list of side-effect-free reads; `SEVDESK_API_ALLOW` replaces it. Every listed
351
+ operation still has to fit the mode and goes through the same confirmation rules as the
352
+ tools.
353
+
354
+ > [!NOTE]
355
+ > Everything a tool reads (customer names, IBANs, amounts, PDFs) goes to your MCP client
356
+ > and from there to the client's model provider.
357
+
358
+ ## Security model
359
+
360
+ An accounting system is not a place for an assistant to improvise, so the defaults are
361
+ strict and every relaxation is an explicit setting.
362
+
363
+ - **Mode.** `SEVDESK_MODE` sets the ceiling: `read` (default) allows only reads, `write`
364
+ adds drafts, master data and status changes, `full` adds irreversible actions (sending
365
+ e-mail, cancellation, enshrining). Deleting has no tool; it is only possible through
366
+ `sevdesk_api_request` for delete operations listed in `SEVDESK_API_ALLOW`. Tools above
367
+ the mode are not registered, and no other setting can lift an operation above it.
368
+ - **Risk classes.** Every sevdesk operation is classified: `R` plain read, `R+` bulk
369
+ export, `W` correctable change, `W+` status or booking change, `X` irreversible. An
370
+ operation without a class is refused everywhere. Each tool declares the operations it
371
+ uses; a request outside that list or above the tool's class is refused before it leaves
372
+ the server.
373
+ - **Tool lists.** `SEVDESK_ALLOWED_TOOLS` narrows the tool set to the names listed,
374
+ `SEVDESK_DENIED_TOOLS` removes tools and always wins, `SEVDESK_ENABLE_TOOLS` switches on
375
+ tools that are off by default (bulk exports and every irreversible tool), still capped by
376
+ the mode. Unknown tool names stop the server at startup.
377
+ - **Two-step calls for `W+` and `X`.** `W` changes run directly, within the mode and
378
+ allowlist. For `W+` and `X` the first call only reads: the curated tools return a
379
+ preview with the facts read from sevdesk (number, contact, amount, status before and
380
+ after, warnings) and a confirmation token. `sevdesk_api_request` reads nothing for its
381
+ preview; it shows only the operation, method, path and body. The second call with the
382
+ same arguments and the token executes the action. The token is an HMAC bound to the
383
+ tool, the exact arguments and the caller, is valid exactly once and expires
384
+ (`SEVDESK_CONFIRM_TTL_SECONDS`). Over stdio "exactly once" holds per process: the used
385
+ nonces live in memory, so with a fixed `SEVDESK_CONFIRM_SECRET` a token that one process
386
+ has used is still accepted by a restarted or second process within its lifetime.
387
+ - **Human approval for `X`.** On the second call the server asks the user through the
388
+ client (MCP elicitation). For the curated tools the question shows the facts read for
389
+ the preview, for example invoice number, customer, amount and recipient, so the user
390
+ approves what will actually be acted on, not only the arguments. For
391
+ `sevdesk_api_request` it shows only the operation, method and path. For clients that cannot ask, the
392
+ operator's explicit listing in `SEVDESK_ENABLE_TOOLS` (or of the operation in
393
+ `SEVDESK_API_ALLOW`) counts as the release; then no human sees the action before it runs.
394
+ - **Once per target.** Each irreversible action runs at most once per target within 24
395
+ hours, for example one e-mail per invoice. Over HTTP the lock lives in Redis and is
396
+ shared by all instances. Over stdio it lives only in the running process: a restart or
397
+ a second client with its own server process starts without it. A definite rejection
398
+ from sevdesk (HTTP 4xx) releases the lock so the action can be retried; an unknown
399
+ outcome (timeout, 5xx, lost connection) keeps it, so check in sevdesk before trying
400
+ again.
401
+ - **Audit log.** Every write attempt is logged as a JSON line, whatever `LOG_LEVEL` says:
402
+ who, which tool or operation, which object, and the outcome. Arguments, bodies and
403
+ tokens are never logged; the API token and confirmation secret are redacted from log
404
+ lines, audit entries and error text.
405
+ - **Text from sevdesk.** Names, descriptions and payment references are marked as data,
406
+ not instructions, and hidden characters are stripped. A model can still be misled by
407
+ such text, so review what it proposes.
408
+
409
+ > [!IMPORTANT]
410
+ > **What holds against a manipulated model.** A confirmation token proves that a preview
411
+ > was fetched for exactly these arguments, not that a human read it: a model following
412
+ > injected instructions can make both calls itself. Elicitation only helps where the
413
+ > client actually asks a human; on clients that cannot ask, the operator release in
414
+ > `SEVDESK_ENABLE_TOOLS` stands in and no human sees the action. The hard limits are the
415
+ > mode and, over HTTP, the token's scopes. Give the server no more than the work needs.
416
+
417
+ ## Remote (HTTP)
418
+
419
+ Besides stdio the server can run as a shared service over the MCP Streamable HTTP
420
+ transport, for example for a team or a hosted client. It acts as an OAuth 2.1 resource
421
+ server: it does not log anyone in, it only validates access tokens issued by your
422
+ authorization server (identity provider).
423
+
424
+ - **Endpoint.** The MCP endpoint is the path of `MCP_RESOURCE_URL` (for example `/mcp`).
425
+ `/healthz` answers liveness probes without authentication. Protected Resource Metadata
426
+ ([RFC 9728](https://www.rfc-editor.org/rfc/rfc9728)) is served under
427
+ `/.well-known/oauth-protected-resource/<path>` and names the authorization server and the
428
+ supported scopes, so clients can discover where to get a token.
429
+ - **Tokens.** JWT access tokens (`typ: at+jwt`,
430
+ [RFC 9068](https://www.rfc-editor.org/rfc/rfc9068)) signed with an asymmetric algorithm,
431
+ with `iss` equal to `OAUTH_ISSUER`, `aud` equal to `MCP_RESOURCE_URL`, a `sub` and a
432
+ client ID (`client_id` or `azp`). Keys come from `OAUTH_JWKS_URL`.
433
+ - **Scopes.** `sevdesk:read`, `sevdesk:write`, `sevdesk:irreversible`. They form a ladder
434
+ without implied steps: each level needs its own scope and every scope below it, so issue
435
+ `sevdesk:write` only together with `sevdesk:read`. A token without `sevdesk:read` gets
436
+ no rights at all. Scopes are read only from the `scope` claim, a space-separated string
437
+ as in RFC 9068; an `scp` array is ignored.
438
+ - **Effective rights = min(mode, scopes).** `SEVDESK_MODE` caps the instance, the token's
439
+ scopes cap each caller. A call to a tool above the token's scopes gets HTTP 403
440
+ `insufficient_scope` naming the scopes it needs, so the client can request them.
441
+ Confirmation tokens are bound to the caller (`sub`, else client ID).
442
+ - **sevdesk token.** The server uses one sevdesk API token for all callers, taken from
443
+ `SEVDESK_API_TOKEN` only (no keychain lookup). Everyone with a valid access token acts as
444
+ that sevdesk user, within their scopes.
445
+ - **Host and Origin.** `MCP_ALLOWED_HOSTS` is the allowlist for the `Host` header (DNS
446
+ rebinding protection) and for the `Origin` header of the MCP endpoint; it defaults to the
447
+ host of `MCP_RESOURCE_URL`. Requests without `Origin` (CLI and desktop clients,
448
+ server-side SDKs) are not affected. A request whose `Origin` names another host, or that
449
+ sends `Origin: null`, gets HTTP 403. Add the host of a browser-based client to let it in.
450
+ The `Host` check covers every path except `/healthz`, including the metadata under
451
+ `/.well-known`; only the `Origin` check is limited to the MCP endpoint.
452
+ - **Logs** go to stdout as JSON lines, audit events included.
453
+
454
+ ### Run it
455
+
456
+ The image built from [`Dockerfile`](Dockerfile) runs the HTTP server and holds no
457
+ secrets; configuration comes from the environment at run time.
458
+ [`compose.yaml`](compose.yaml) runs it locally with a Redis set up as described below,
459
+ ports bound to localhost only:
460
+
461
+ ```sh
462
+ # Redis in a container, server from source (variables from .env.example in your shell)
463
+ docker compose up -d redis
464
+ npm run build && npm run start:http
465
+
466
+ # or everything in containers
467
+ docker compose --profile app up --build
468
+ ```
469
+
470
+ `OAUTH_ISSUER` and `OAUTH_JWKS_URL` have no default and must be set, also for compose,
471
+ along with `SEVDESK_API_TOKEN` and `SEVDESK_CONFIRM_SECRET`. Missing or invalid variables
472
+ stop the server at startup with a configuration error that names them. The HTTP server reads the [common variables](#configuration) plus
473
+ [its own](#http-transport-only).
474
+
475
+ ### Redis
476
+
477
+ Redis holds the single-use confirmation nonces and the once-per-target locks of
478
+ irreversible actions. If it forgets them, a used confirmation can become valid again.
479
+ Run it like this:
480
+
481
+ - **Persistence via AOF:** `appendonly yes` with `appendfsync always`, or accept that a
482
+ crash can forget the last second of writes with `everysec`.
483
+ - **`maxmemory-policy noeviction`,** so nonces are never evicted. Under memory pressure
484
+ Redis then refuses writes and the server fails closed.
485
+ - **A Redis of its own,** not a shared cache that others flush or evict.
486
+
487
+ At startup the server warns if `maxmemory-policy` is not `noeviction` (on managed Redis
488
+ without `CONFIG GET` it only logs that it could not check). It also writes a sentinel key;
489
+ if that disappears or changes while the server runs, confirmations (`W+` and `X`) are
490
+ refused until a restart.
491
+
492
+ The sentinel has limits. It only detects a total loss (`FLUSHALL`, Redis restarted empty)
493
+ while the server is running. It does not detect a partial loss (single keys evicted or
494
+ lost in the last fsync window), and it does not detect a loss that happened while the
495
+ server was down: a restart simply writes a new sentinel. Persistence and `noeviction` are
496
+ the actual protection.
497
+
498
+ **Recovery after "redis lost its data":** fix persistence, wait at least
499
+ `SEVDESK_CONFIRM_TTL_SECONDS` + 60 seconds so every confirmation token issued before the
500
+ loss has expired, then restart. Check in sevdesk the irreversible actions (e-mails,
501
+ cancellations, enshrining, and deletes released via `SEVDESK_API_ALLOW`) of the last 24
502
+ hours: their once-per-target lock was lost as well.
503
+
504
+ ### Shutdown
505
+
506
+ On `SIGTERM` the server stops accepting MCP requests (they get HTTP 503, `/healthz`
507
+ reports draining), waits up to 10 seconds for in-flight requests and exits at the latest
508
+ after about 15 seconds. Give it more time than that before `SIGKILL`:
509
+ `stop_grace_period: 20s` in compose (already set) and `terminationGracePeriodSeconds` of
510
+ at least 20 on Kubernetes.
511
+
512
+ ## Configuration
513
+
514
+ All configuration comes from environment variables; see [`.env.example`](.env.example).
515
+ Empty values count as unset. The first table applies to both transports, the second only
516
+ to the [HTTP transport](#remote-http).
517
+
518
+ | Variable | Default | Meaning |
519
+ | --- | --- | --- |
520
+ | `SEVDESK_API_TOKEN` | keychain | sevdesk API token. Unset: read from the keychain (service `sevdesk-mcp`, account `api-token`); required if there is none. HTTP: environment only. |
521
+ | `SEVDESK_MODE` | `read` | `read`, `write` or `full`. |
522
+ | `SEVDESK_ALLOWED_TOOLS` | all tools | Comma-separated whitelist of tool names. Only narrows; never switches on a tool that is off by default. |
523
+ | `SEVDESK_DENIED_TOOLS` | none | Comma-separated tool names that are never registered. Always wins. |
524
+ | `SEVDESK_ENABLE_TOOLS` | none | Comma-separated tools that are off by default to switch on (every `X` tool, bulk exports), still capped by the mode. For `X` it counts as the release for clients without elicitation. |
525
+ | `SEVDESK_API_ALLOW` | curated reads | Comma-separated `operationId`s for `sevdesk_api_request`. Unknown or unclassified IDs stop the server at startup. |
526
+ | `SEVDESK_CONFIRM_SECRET` | random per process | HMAC key for confirmation tokens, at least 32 characters. Required for HTTP. |
527
+ | `SEVDESK_CONFIRM_TTL_SECONDS` | `300` | Lifetime of a confirmation token, 30 to 3600 seconds. |
528
+ | `SEVDESK_BASE_URL` | `https://my.sevdesk.de/api/v1` | API base URL. https only, http only for localhost. |
529
+ | `LOG_LEVEL` | `info` | `debug`, `info`, `warn` or `error`. JSON lines on stderr (stdio) or stdout (HTTP); audit events are written at every level. |
530
+ | `SEVDESK_LIVE_TEST_TOKEN` | unset | Live smoke only: token of a sevdesk test account; unset skips the smoke. |
531
+ | `SEVDESK_LIVE_BASE_URL` | `SEVDESK_BASE_URL` default | Live smoke only: https on sevdesk.de or a subdomain. |
532
+
533
+ ### HTTP transport only
534
+
535
+ Not read by the stdio server. The HTTP server also needs `SEVDESK_API_TOKEN` (from the
536
+ environment, no keychain) and `SEVDESK_CONFIRM_SECRET`.
537
+
538
+ | Variable | Default | Meaning |
539
+ | --- | --- | --- |
540
+ | `PORT` | `3000` | Port to bind. |
541
+ | `MCP_RESOURCE_URL` | required | Public URL of the MCP endpoint as clients reach it, and the audience (`aud`) tokens must carry. https; http only for localhost. No query; the path must not be `/healthz` or under `/.well-known/`. |
542
+ | `MCP_ALLOWED_HOSTS` | host of `MCP_RESOURCE_URL` | Comma-separated host names allowed in `Host` and `Origin`, for example behind a reverse proxy. |
543
+ | `OAUTH_ISSUER` | required | Expected `iss` claim, compared as an exact string. https. |
544
+ | `OAUTH_JWKS_URL` | required | Public keys of the authorization server. https. |
545
+ | `OAUTH_ALGORITHMS` | `RS256` | Comma-separated JWS algorithms, asymmetric only (RS, PS, ES and EdDSA families). |
546
+ | `OAUTH_ALLOW_INSECURE_HTTP` | `false` | `true` accepts plain http for `OAUTH_ISSUER` and `OAUTH_JWKS_URL`. Local development only. |
547
+ | `REDIS_URL` | required | `redis://` or `rediss://` URL of the store for confirmation nonces and once-per-target locks. Can carry a password; treat it as a secret. |
548
+
549
+ ## Status
550
+
551
+ Early release. Read tools, write tools, the policy layer, the fallback and the HTTP
552
+ transport are covered by unit and protocol tests against a mocked sevdesk API; a manual,
553
+ read-only smoke test can run the read tools against a real sevdesk test account. Not
554
+ every write tool has been verified live yet, see the note under
555
+ [What it can do](#what-it-can-do). Issues and feedback are welcome.
556
+
557
+ ## Development
558
+
559
+ ```sh
560
+ npm ci
561
+ npm run gen # apply the spec overlay and generate API types
562
+ npm run check # gen, lint, typecheck, build, tests
563
+ npm run build:bin # standalone binary for this machine in out/bin/ (needs bun)
564
+ npm run smoke:bin # start that binary and check initialize and tools/list, offline
565
+ ```
566
+
567
+ Node.js 24 (see `.nvmrc`) is all `npm run check` needs; `build:bin` compiles with
568
+ [bun](https://bun.sh) and `build:bin:all` builds every release target. CI runs
569
+ `npm run check`, checks the installer under a strict POSIX shell and builds and smoke-tests
570
+ the binary.
571
+
572
+ <details>
573
+ <summary>live smoke test, spec overlay</summary>
574
+
575
+ <br>
576
+
577
+ **Live smoke test.** Calls every read tool once against a real sevdesk account. Use a
578
+ **test account**, never production:
579
+
580
+ ```sh
581
+ read -rs SEVDESK_LIVE_TEST_TOKEN && export SEVDESK_LIVE_TEST_TOKEN # paste, Enter
582
+ npm run test:live
583
+ unset SEVDESK_LIVE_TEST_TOKEN
584
+ ```
585
+
586
+ It always runs in `read` mode, aborts if any non-read tool is registered, and prints only
587
+ tool name, status and a count, never response content. Without the token it is skipped.
588
+ `SEVDESK_LIVE_BASE_URL` overrides the base URL, but only for https hosts on sevdesk.de.
589
+ The smoke is not part of `npm run check` or CI.
590
+
591
+ **Spec overlay.** The vendored sevdesk OpenAPI spec
592
+ ([`openapi/sevdesk.openapi.yaml`](openapi/sevdesk.openapi.yaml)) has gaps: undeclared
593
+ pagination and embed parameters, missing error responses, incomplete status enums. Instead of editing it,
594
+ [`openapi/overlay.yaml`](openapi/overlay.yaml) holds the corrections as an
595
+ [OpenAPI Overlay](https://spec.openapis.org/overlay/latest.html). `npm run gen` applies it
596
+ and generates the TypeScript types the client is built on. It fails if an overlay action
597
+ matches nothing, so an upstream spec change cannot silently drop a correction.
598
+
599
+ </details>
600
+
601
+ **Releases.** Commits follow [Conventional Commits](https://www.conventionalcommits.org).
602
+ Every push to `main` runs the release workflow: commitizen derives the next version from
603
+ the commits since the last tag (`fix` → patch, `feat` → minor, breaking change → major;
604
+ other types release nothing). The version lives only in the tag, without a `v` prefix
605
+ (for example `0.2.0`), and is stamped into the build. A release publishes the four binaries
606
+ with `SHA256SUMS` on GitHub and the npm package with provenance.
607
+
608
+ ## License
609
+
610
+ MIT, see [`LICENSE`](LICENSE). Copyright (c) 2026 Zilicon IT Services.
611
+
612
+ sevdesk is a trademark of sevdesk GmbH. This project is not affiliated with or endorsed by
613
+ sevdesk GmbH.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ import { ConfigError } from "../config.js";
3
+ import { SHUTDOWN_TIMEOUT_MS, StartupError, startHttpServer } from "../http/start.js";
4
+ // Streamable HTTP entrypoint. Logs are JSON lines on stdout, written
5
+ // immediately; the process manager collects them.
6
+ const fail = (msg, fields = {}) => {
7
+ process.stdout.write(`${JSON.stringify({ time: new Date().toISOString(), level: "error", msg, ...fields })}\n`);
8
+ process.exit(1);
9
+ };
10
+ let running;
11
+ try {
12
+ running = await startHttpServer();
13
+ }
14
+ catch (error) {
15
+ if (error instanceof ConfigError)
16
+ fail("invalid configuration", { issues: error.issues });
17
+ if (error instanceof StartupError)
18
+ fail(error.message);
19
+ throw error;
20
+ }
21
+ const stop = (signal) => {
22
+ // Last resort if closing hangs beyond the shutdown timeout.
23
+ setTimeout(() => process.exit(1), SHUTDOWN_TIMEOUT_MS + 5000).unref();
24
+ running.shutdown(signal).then(() => process.exit(0), (error) => {
25
+ running.logger.error("shutdown failed", { error });
26
+ process.exit(1);
27
+ });
28
+ };
29
+ // A second signal does not start a second shutdown; it waits for the first.
30
+ process.on("SIGTERM", stop);
31
+ process.on("SIGINT", stop);