bookstack-mcp 5.7.1 → 5.7.3
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.
- package/README.md +50 -368
- package/dist/oauth/entra-proxy.js +30 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,155 +1,50 @@
|
|
|
1
1
|
# BookStack MCP Server
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/bookstack-mcp)
|
|
4
|
-
[](https://www.npmjs.com/package/bookstack-mcp)
|
|
5
4
|
[](https://github.com/ttpears/bookstack-mcp/actions/workflows/ci.yml)
|
|
6
5
|
[](https://hol.org/registry/plugins/ttpears%2Fbookstack-mcp)
|
|
7
|
-
[](https://modelcontextprotocol.io)
|
|
9
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](LICENSE)
|
|
10
7
|
|
|
11
|
-
<img src="assets/logo.svg" width="96" align="right" alt="
|
|
8
|
+
<img src="assets/logo.svg" width="96" align="right" alt="BookStack MCP"/>
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
Connect an AI assistant to your [BookStack](https://www.bookstackapp.com) wiki through the [Model Context Protocol](https://modelcontextprotocol.io). Search documentation, answer questions with source links, summarize books, and optionally maintain pages and other content.
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
npx bookstack-mcp
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Read the [privacy policy](./PRIVACY.md) for data flows, credentials, optional
|
|
20
|
-
OAuth/Redis state, and logging. Your MCP client and deployment operator may have
|
|
21
|
-
additional policies. The [terms of use](./TERMS.md) explain the scope of the
|
|
22
|
-
software under its [MIT license](./LICENSE).
|
|
23
|
-
|
|
24
|
-
Field notes: [Why my BookStack MCP server starts read-only](https://hackyourworld.com/bookstack-mcp-server-read-only-by-default/) covers the shared-token rate-limit failure, process-wide cache, response-size measurements, and permission boundaries that shaped the current design.
|
|
25
|
-
|
|
26
|
-
## Features
|
|
27
|
-
|
|
28
|
-
- 21 read-only tools + 22 write tools for BookStack API access
|
|
29
|
-
- Books, chapters, pages, shelves, attachments, and comments — full CRUD
|
|
30
|
-
- Recycle bin support — restore or permanently delete soft-deleted content
|
|
31
|
-
- Type-safe input validation with Zod (auto-coerces string/number params for broad client compatibility)
|
|
32
|
-
- Embedded URLs and content previews in all responses
|
|
33
|
-
- Markdown export fallback for HTML-authored pages, so AI clients always get usable content
|
|
34
|
-
- Token-efficient responses: compact JSON, no redundant fields, no N+1 fetches — ~30–55% smaller payloads than 3.x
|
|
35
|
-
- Write operations disabled by default for safety
|
|
36
|
-
- Works with Claude Desktop, Claude Code, LibreChat, and any MCP-compatible client
|
|
37
|
-
- Stdio and Streamable HTTP transports
|
|
12
|
+
**Read-only by default.** The server exposes 21 read tools and, when enabled, 22 write tools. BookStack permissions still apply to every API request. Use a dedicated account with access to only the content the assistant should see.
|
|
38
13
|
|
|
39
14
|
## Quick Start
|
|
40
15
|
|
|
41
|
-
###
|
|
16
|
+
### 1. Create a BookStack API token
|
|
42
17
|
|
|
43
|
-
|
|
44
|
-
npx bookstack-mcp
|
|
45
|
-
```
|
|
18
|
+
In BookStack, open your profile's **API Tokens** section and create a token for a dedicated user. Its role needs **Access System API** and permission to view the relevant books/pages. Copy both the **Token ID** and **Token Secret**; they are separate values.
|
|
46
19
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
git clone https://github.com/ttpears/bookstack-mcp.git
|
|
51
|
-
cd bookstack-mcp
|
|
52
|
-
npm install && npm run build
|
|
53
|
-
npm start
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Environment Variables
|
|
57
|
-
|
|
58
|
-
```env
|
|
59
|
-
BOOKSTACK_BASE_URL=https://your-bookstack.com # Required
|
|
60
|
-
BOOKSTACK_TOKEN_ID=your-token-id # Required
|
|
61
|
-
BOOKSTACK_TOKEN_SECRET=your-token-secret # Required
|
|
62
|
-
BOOKSTACK_ENABLE_WRITE=false # Optional, default false
|
|
63
|
-
BOOKSTACK_INSECURE_SKIP_TLS_VERIFY=false # Optional, default false
|
|
64
|
-
BOOKSTACK_TIMEOUT_MS=30000 # Optional, timeout per HTTP attempt
|
|
65
|
-
BOOKSTACK_RETRY_TIMEOUT_MS=60000 # Optional, total budget per API request
|
|
66
|
-
```
|
|
20
|
+
Also grant **Export Content** to read WYSIWYG pages as Markdown: BookStack stores no Markdown source for those pages, so the server uses its export endpoint as a fallback. User lookup and recycle-bin tools require additional administrative permissions; ordinary reading does not.
|
|
67
21
|
|
|
68
|
-
|
|
69
|
-
and rate-limit backoff. HTTP 429 responses are retried up to five times, with each
|
|
70
|
-
delay capped at 30 seconds. If a delay cannot fit in the remaining budget or retries
|
|
71
|
-
are exhausted, the tool returns an explicit BookStack rate-limit error. The budget
|
|
72
|
-
applies to each API request; tools that fetch multiple endpoints can take longer.
|
|
22
|
+
### 2. Choose an installation
|
|
73
23
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
24
|
+
| Your setup | Start here |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Claude Desktop | Install the `.mcpb` bundle from the [latest release](https://github.com/ttpears/bookstack-mcp/releases/latest) under **Settings → Extensions**, then enter the three BookStack settings |
|
|
27
|
+
| Claude Code | [Marketplace or direct CLI setup](docs/CLIENTS.md#claude-code) |
|
|
28
|
+
| Codex or Gemini CLI | [Native plugin and extension setup](docs/CLIENTS.md#codex) |
|
|
29
|
+
| Cursor | [Native plugin or manual MCP setup](docs/CLIENTS.md#cursor) |
|
|
30
|
+
| Any local MCP client | Use the stdio configuration below |
|
|
31
|
+
| LibreChat / shared Docker service | [Internal HTTP deployment](docs/SETUP.md#internal-http-service) |
|
|
32
|
+
| Remote connector with Microsoft sign-in | [HTTPS and Entra OAuth deployment](docs/SETUP.md#public-connector-with-entra-oauth) |
|
|
77
33
|
|
|
78
|
-
|
|
79
|
-
(1–180 characters), saved as the revision summary in the page's history. It
|
|
80
|
-
needs BookStack v26.09 or newer; older versions silently ignore it.
|
|
34
|
+
For npm-based installations, use a supported Node.js LTS release (Node 24 recommended; CI also uses Node 22). The published package declares `node >=18`; that minimum is not a recommendation to run an unsupported Node release. Docker includes its own Node runtime.
|
|
81
35
|
|
|
82
|
-
|
|
83
|
-
as an array of `{ "name": "Environment", "value": "Production" }` objects.
|
|
84
|
-
Use `"value": ""` for a tag with no value. Chapter and shelf create/update
|
|
85
|
-
tools also support tags.
|
|
36
|
+
### 3. Configure a local MCP client
|
|
86
37
|
|
|
87
|
-
|
|
88
|
-
or pass `[]` to remove all tags. To add, edit, or remove individual tags, first
|
|
89
|
-
read the entity with `get_page` or `get_book`, then send the revised list,
|
|
90
|
-
including every tag you want to keep. For example:
|
|
91
|
-
|
|
92
|
-
```json
|
|
93
|
-
{"id": 42, "tags": [{"name": "Environment", "value": "Production"}, {"name": "Reviewed", "value": ""}]}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Pass this to `update_page` or `update_book`. A tag-only update needs no page
|
|
97
|
-
content and preserves the editor source. Tag writes require
|
|
98
|
-
`BOOKSTACK_ENABLE_WRITE=true` and the corresponding BookStack edit permission.
|
|
99
|
-
|
|
100
|
-
`get_page` accepts `format: "raw"` to return the page's stored editor HTML
|
|
101
|
-
(BookStack's `raw_html`). The `html` format is the rendered view readers see:
|
|
102
|
-
page includes are resolved and the content filter has run, so attributes such as
|
|
103
|
-
`rel`, `data-*` or legacy `width`/`align` may be gone.
|
|
104
|
-
|
|
105
|
-
When you edit a page, match the format to the page's `editor` field:
|
|
106
|
-
|
|
107
|
-
- **HTML (WYSIWYG) pages:** read `format: "raw"` and send the result back as
|
|
108
|
-
`update_page.html`. Starting from `html` saves the rendered output and drops
|
|
109
|
-
whatever rendering removed.
|
|
110
|
-
- **Markdown pages:** read `format: "markdown"` and send the result back as
|
|
111
|
-
`update_page.markdown`. For these pages `raw_html` is HTML generated from the
|
|
112
|
-
Markdown, and saving any `html` clears the stored Markdown source.
|
|
113
|
-
|
|
114
|
-
> **Security warning:** `BOOKSTACK_INSECURE_SKIP_TLS_VERIFY=true` disables TLS certificate verification for outgoing requests to BookStack. Use only for self-signed certs on a trusted LAN — connections become vulnerable to MITM attacks. The server logs a `WARNING` line at startup whenever this is enabled.
|
|
115
|
-
|
|
116
|
-
## Client Configuration
|
|
117
|
-
|
|
118
|
-
### Codex plugin
|
|
119
|
-
|
|
120
|
-
This repository includes a native Codex manifest at
|
|
121
|
-
`.codex-plugin/plugin.json`, which references the stdio server in `.mcp.json`.
|
|
122
|
-
Set `BOOKSTACK_BASE_URL`, `BOOKSTACK_TOKEN_ID`, and `BOOKSTACK_TOKEN_SECRET` in
|
|
123
|
-
the environment that launches Codex before enabling the plugin. Write operations
|
|
124
|
-
remain disabled unless `BOOKSTACK_ENABLE_WRITE=true` is set.
|
|
125
|
-
|
|
126
|
-
The manifest supplies the project website, privacy policy, and terms of use for
|
|
127
|
-
plugin directories, including HOL. The HOL Guard CI workflow scans this manifest
|
|
128
|
-
alongside the Claude and Gemini manifests. After a passing scan on `main`, a
|
|
129
|
-
separate job sends an authenticated score summary to HOL so the registry can
|
|
130
|
-
show the result checked in CI. PR scans remain read-only. See
|
|
131
|
-
[HOL registry setup](docs/HOL.md) for ownership verification and reporting details.
|
|
132
|
-
|
|
133
|
-
### Claude Desktop
|
|
134
|
-
|
|
135
|
-
The easiest install is the prebuilt MCPB bundle attached to each [GitHub release](https://github.com/ttpears/bookstack-mcp/releases/latest):
|
|
136
|
-
|
|
137
|
-
1. Download `bookstack-mcp-<version>.mcpb` from the latest release.
|
|
138
|
-
2. Open Claude Desktop → **Settings → Extensions** and drag the `.mcpb` file in (or click *Install Extension*).
|
|
139
|
-
3. Fill in **BookStack URL**, **API Token ID**, and **API Token Secret**. Tokens are stored in your OS keychain. Leave **Enable Write Operations** as `false` for read-only access; set to `true` to enable create/update/delete tools.
|
|
140
|
-
|
|
141
|
-
#### Manual install (JSON config)
|
|
142
|
-
|
|
143
|
-
If you'd rather edit the config file directly:
|
|
38
|
+
Add this entry to your client's MCP configuration, replacing the example values:
|
|
144
39
|
|
|
145
40
|
```json
|
|
146
41
|
{
|
|
147
42
|
"mcpServers": {
|
|
148
43
|
"bookstack": {
|
|
149
44
|
"command": "npx",
|
|
150
|
-
"args": ["-y", "bookstack-mcp"],
|
|
45
|
+
"args": ["-y", "bookstack-mcp@5.7.3"],
|
|
151
46
|
"env": {
|
|
152
|
-
"BOOKSTACK_BASE_URL": "https://
|
|
47
|
+
"BOOKSTACK_BASE_URL": "https://wiki.example.com",
|
|
153
48
|
"BOOKSTACK_TOKEN_ID": "your-token-id",
|
|
154
49
|
"BOOKSTACK_TOKEN_SECRET": "your-token-secret"
|
|
155
50
|
}
|
|
@@ -158,265 +53,52 @@ If you'd rather edit the config file directly:
|
|
|
158
53
|
}
|
|
159
54
|
```
|
|
160
55
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
Add to your `librechat.yaml`:
|
|
164
|
-
|
|
165
|
-
```yaml
|
|
166
|
-
mcpServers:
|
|
167
|
-
bookstack:
|
|
168
|
-
command: npx
|
|
169
|
-
args:
|
|
170
|
-
- -y
|
|
171
|
-
- bookstack-mcp
|
|
172
|
-
env:
|
|
173
|
-
BOOKSTACK_BASE_URL: "https://your-bookstack.com"
|
|
174
|
-
BOOKSTACK_TOKEN_ID: "your-token-id"
|
|
175
|
-
BOOKSTACK_TOKEN_SECRET: "your-token-secret"
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### LibreChat (Streamable HTTP, recommended for production / Docker)
|
|
179
|
-
|
|
180
|
-
Run the server as a long-lived HTTP service and point LibreChat at the URL. This is the right setup for multi-user or containerized deployments.
|
|
181
|
-
|
|
182
|
-
Start the server in HTTP mode:
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
MCP_TRANSPORT=http \
|
|
186
|
-
MCP_HTTP_PORT=8080 \
|
|
187
|
-
BOOKSTACK_BASE_URL=https://your-bookstack.com \
|
|
188
|
-
BOOKSTACK_TOKEN_ID=your-token-id \
|
|
189
|
-
BOOKSTACK_TOKEN_SECRET=your-token-secret \
|
|
190
|
-
npx bookstack-mcp
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Then configure LibreChat:
|
|
194
|
-
|
|
195
|
-
```yaml
|
|
196
|
-
mcpServers:
|
|
197
|
-
bookstack:
|
|
198
|
-
type: streamable-http
|
|
199
|
-
url: http://bookstack-mcp:8080/mcp
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
#### Per-user BookStack credentials
|
|
203
|
-
|
|
204
|
-
Set `BOOKSTACK_ALLOW_REQUEST_CREDENTIALS=true` on the HTTP server to accept
|
|
205
|
-
`X-Bookstack-Token-Id` and `X-Bookstack-Token-Secret` on each request. Both headers
|
|
206
|
-
must be supplied together; when both are absent, the server uses its environment
|
|
207
|
-
credentials. This is opt-in and does not change the write-tool or OAuth role gates.
|
|
208
|
-
Use a read-only environment token with limited visibility for the fallback.
|
|
209
|
-
Credential overrides apply to each request, including reused MCP sessions, and
|
|
210
|
-
their slug caches are private to that request. Send credentials over HTTPS or a
|
|
211
|
-
trusted internal connection and configure proxies to redact these headers.
|
|
212
|
-
|
|
213
|
-
```yaml
|
|
214
|
-
mcpServers:
|
|
215
|
-
bookstack:
|
|
216
|
-
type: streamable-http
|
|
217
|
-
url: http://bookstack-mcp:8080/mcp
|
|
218
|
-
headers:
|
|
219
|
-
X-Bookstack-Token-Id: "{{BOOKSTACK_TOKEN_ID}}"
|
|
220
|
-
X-Bookstack-Token-Secret: "{{BOOKSTACK_TOKEN_SECRET}}"
|
|
221
|
-
customUserVars:
|
|
222
|
-
BOOKSTACK_TOKEN_ID: { title: "BookStack token ID" }
|
|
223
|
-
BOOKSTACK_TOKEN_SECRET: { title: "BookStack token secret" }
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
#### Gallery images
|
|
56
|
+
This configuration contains credentials: keep it private and outside version control. It pins the reviewed release `5.7.3`; update the exact version deliberately when upgrading. The repository's native plugin/extension launchers also pin a matching npm version.
|
|
227
57
|
|
|
228
|
-
`
|
|
229
|
-
`sort` parameters. With write mode enabled, `create_image` accepts exactly one
|
|
230
|
-
absolute `file_path` or HTTP(S) `url`, a required existing page ID `uploaded_to`,
|
|
231
|
-
and an optional `name`. It uploads the binary data directly and returns BookStack's
|
|
232
|
-
hosted URL, thumbnails, and `content.html` / `content.markdown` snippets. PNG,
|
|
233
|
-
JPEG, GIF, WebP, and SVG sources up to 50 MB are supported; BookStack may impose
|
|
234
|
-
smaller limits. `delete_image` deletes an image and its thumbnails by `id`.
|
|
58
|
+
Restart the client, check that BookStack tools appear, and ask: **“List the books I can access, then find our onboarding guide and link to it.”** This verifies MCP connectivity and BookStack access. Starting `npx` without the required settings fails; starting it in a terminal with settings waits for MCP input rather than opening a web interface.
|
|
235
59
|
|
|
236
|
-
|
|
237
|
-
In HTTP mode, local files are disabled unless
|
|
238
|
-
`BOOKSTACK_ALLOW_LOCAL_IMAGE_FILES=true`. URL sources require a comma-separated
|
|
239
|
-
`BOOKSTACK_IMAGE_ALLOWED_HOSTS` hostname allowlist, which also applies to every
|
|
240
|
-
redirect. For example, allow your image service with
|
|
241
|
-
`BOOKSTACK_IMAGE_ALLOWED_HOSTS=images.example.com`. Source downloads never use
|
|
242
|
-
the BookStack authorization token. Deleting an image can break existing page references.
|
|
243
|
-
|
|
244
|
-
> **3.0.0 breaking change:** the deprecated HTTP+SSE transport (`GET /sse` + `POST /messages`) has been removed. Streamable HTTP at `/mcp` already speaks SSE for streaming responses, and is the only HTTP transport in current MCP clients. If you're on an older client that needs the legacy endpoints, pin to `bookstack-mcp@2.x`.
|
|
245
|
-
|
|
246
|
-
#### HTTP transport environment variables
|
|
247
|
-
|
|
248
|
-
| Variable | Default | Description |
|
|
249
|
-
|----------|---------|-------------|
|
|
250
|
-
| `MCP_TRANSPORT` | `stdio` | Set to `http` to enable the HTTP server |
|
|
251
|
-
| `MCP_HTTP_PORT` | `8080` | Port to listen on |
|
|
252
|
-
| `MCP_HTTP_HOST` | `127.0.0.1` | Bind address. Loopback by default for safety |
|
|
253
|
-
| `MCP_HTTP_ALLOWED_HOSTS` | *(loopback only)* | Comma-separated allowlist of `Host` header hostnames for DNS rebinding protection. Required when binding to a non-loopback address |
|
|
254
|
-
| `MCP_HTTP_PATH` | `/mcp` | Streamable HTTP endpoint |
|
|
255
|
-
| `MCP_HTTP_MAX_BODY_BYTES` | `10485760` (10 MiB) | Maximum MCP JSON request size in bytes; positive integer |
|
|
256
|
-
|
|
257
|
-
OAuth registration and token request bodies are limited to 64 KiB. Body reads
|
|
258
|
-
must complete within 30 seconds. Oversized bodies return HTTP 413, slow bodies
|
|
259
|
-
return 408, and malformed MCP JSON returns 400 without echoing its contents.
|
|
260
|
-
|
|
261
|
-
OAuth sessions are bound to both the user's identity and current write role.
|
|
262
|
-
If that role changes, the server closes the old session and returns 404 so the
|
|
263
|
-
client reinitializes with the appropriate credential and tool set. OAuth pending
|
|
264
|
-
states and authorization codes are consumed atomically, including with Redis.
|
|
265
|
-
|
|
266
|
-
When binding to `0.0.0.0` (e.g. inside a container reachable from other services), set `MCP_HTTP_ALLOWED_HOSTS` to the hostnames LibreChat will use to reach this server, e.g. `MCP_HTTP_ALLOWED_HOSTS=bookstack-mcp,bookstack-mcp.internal`.
|
|
267
|
-
|
|
268
|
-
Restart LibreChat after config changes.
|
|
269
|
-
|
|
270
|
-
### Remote hosting & Claude Connector (Docker + Entra OAuth)
|
|
271
|
-
|
|
272
|
-
A container image is published to `ghcr.io/ttpears/bookstack-mcp` (released `:X.Y.Z`/`:latest`,
|
|
273
|
-
plus per-PR preview tags `:branch-<slug>`). The server can run as a public **Claude Connector**
|
|
274
|
-
gated by Microsoft 365 / Entra ID login — users sign in, no API key or client credential to
|
|
275
|
-
paste; write tools are unlocked per session by an Entra app role.
|
|
276
|
-
|
|
277
|
-
See **[docs/SETUP.md](docs/SETUP.md)** for the full runbook: Entra app registration steps,
|
|
278
|
-
the environment-variable reference, internal LibreChat deployment, and the public OAuth
|
|
279
|
-
connector setup.
|
|
280
|
-
|
|
281
|
-
### Claude Code (CLI)
|
|
282
|
-
|
|
283
|
-
The recommended path is the `ttpears/claude-plugins` marketplace, which ships this repo's plugin manifest (`.claude-plugin/plugin.json`):
|
|
284
|
-
|
|
285
|
-
```
|
|
286
|
-
/plugin marketplace add ttpears/claude-plugins
|
|
287
|
-
/plugin install bookstack-mcp@ttpears-plugins
|
|
288
|
-
```
|
|
60
|
+
## Client Configuration
|
|
289
61
|
|
|
290
|
-
|
|
62
|
+
The [client guide](docs/CLIENTS.md) covers Claude Desktop, Claude Code, Codex, Cursor, Gemini CLI, and LibreChat, including per-user HTTP credential headers. The [configuration reference](docs/CONFIGURATION.md) documents all server settings and the different npm and Docker defaults.
|
|
291
63
|
|
|
292
|
-
|
|
293
|
-
export BOOKSTACK_BASE_URL=https://your-bookstack.com
|
|
294
|
-
export BOOKSTACK_TOKEN_ID=your-token-id
|
|
295
|
-
export BOOKSTACK_TOKEN_SECRET=your-token-secret
|
|
296
|
-
```
|
|
64
|
+
For development from a checkout, see [CONTRIBUTING.md](CONTRIBUTING.md). The server does not automatically read `.env`; use the client's `env` settings, export variables, or explicitly pass Node's `--env-file` option.
|
|
297
65
|
|
|
298
|
-
|
|
66
|
+
## Available Tools
|
|
299
67
|
|
|
300
|
-
|
|
68
|
+
| Task | Tools and behavior |
|
|
69
|
+
|---|---|
|
|
70
|
+
| Find information | `search_content`, `search_pages`, `find_users`, `get_recent_changes` |
|
|
71
|
+
| Read the wiki | List/detail tools for books, chapters, pages, shelves, attachments, and comments; `list_images` |
|
|
72
|
+
| Export | `export_page`, `export_book`, `export_chapter` as HTML, Markdown, plaintext, PDF, or ZIP |
|
|
73
|
+
| Maintain content | Optional create/update/delete tools, gallery image uploads, and recycle-bin operations |
|
|
301
74
|
|
|
302
|
-
|
|
303
|
-
claude mcp add bookstack \
|
|
304
|
-
--transport stdio \
|
|
305
|
-
--scope user \
|
|
306
|
-
--env BOOKSTACK_BASE_URL=https://your-bookstack.com \
|
|
307
|
-
--env BOOKSTACK_TOKEN_ID=your-token-id \
|
|
308
|
-
--env BOOKSTACK_TOKEN_SECRET=your-token-secret \
|
|
309
|
-
-- npx -y bookstack-mcp
|
|
310
|
-
```
|
|
75
|
+
See the [complete tool reference and recipes](docs/TOOLS.md) for all 43 tool names, pagination, tags, image policies, and version requirements. MCP `tools/list` on your connected server is authoritative for argument schemas and enabled tools.
|
|
311
76
|
|
|
312
|
-
|
|
77
|
+
To enable writes in **non-OAuth** mode, set `BOOKSTACK_ENABLE_WRITE=true` and use a BookStack token with the corresponding permissions. In OAuth mode, writes instead require the configured Entra role and a separate write-token pair. Entra users normally share those BookStack service accounts; sign-in does not automatically give each user their own BookStack identity or private content boundary.
|
|
313
78
|
|
|
314
|
-
|
|
315
|
-
|-------|----------------|----------------|-------------|
|
|
316
|
-
| `local` (default) | `~/.claude.json`, scoped to the current project | No | Trying it out in one repo |
|
|
317
|
-
| `user` | `~/.claude.json`, available in every project | No | You want bookstack everywhere |
|
|
318
|
-
| `project` | `.mcp.json` at the repo root | Yes | The whole team should get it |
|
|
79
|
+
### Editing pages safely
|
|
319
80
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
"mcpServers": {
|
|
325
|
-
"bookstack": {
|
|
326
|
-
"type": "stdio",
|
|
327
|
-
"command": "npx",
|
|
328
|
-
"args": ["-y", "bookstack-mcp"],
|
|
329
|
-
"env": {
|
|
330
|
-
"BOOKSTACK_BASE_URL": "https://your-bookstack.com",
|
|
331
|
-
"BOOKSTACK_TOKEN_ID": "your-token-id",
|
|
332
|
-
"BOOKSTACK_TOKEN_SECRET": "your-token-secret"
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
> **Tip for committed `.mcp.json`:** Claude Code expands `${VAR}` and `${VAR:-default}` references in `.mcp.json` from the surrounding shell. Use that to keep secrets out of git: set `"BOOKSTACK_TOKEN_SECRET": "${BOOKSTACK_TOKEN_SECRET}"` in the file and have each developer export the variable in their shell.
|
|
81
|
+
- For HTML/WYSIWYG pages, read `get_page` with `format: "raw"` and update using `html`. The rendered `html` view can remove editor attributes and resolve includes.
|
|
82
|
+
- For Markdown pages, read `format: "markdown"` and update using `markdown`. Saving `html` clears the stored Markdown source.
|
|
83
|
+
- Tags replace the entire tag list. Omit `tags` to preserve it, or send `[]` to clear it. Read the current list before changing individual tags.
|
|
84
|
+
- Read all content chunks before replacing a large page. [Worked examples](docs/TOOLS.md#edit-without-losing-source-or-tags) show the workflow.
|
|
340
85
|
|
|
341
86
|
## MCP Resources
|
|
342
87
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
| URI template | Description |
|
|
346
|
-
|--------------|-------------|
|
|
347
|
-
| `bookstack://book/{id}` | A book, returned as JSON metadata |
|
|
348
|
-
| `bookstack://page/{id}` | A page, returned as markdown plus a JSON metadata blob |
|
|
349
|
-
|
|
350
|
-
Both templates support `id` autocompletion: as you type, the server searches BookStack and returns matching IDs so you don't have to remember numeric IDs by hand.
|
|
88
|
+
Clients with resource support can browse `bookstack://book/{id}` for book metadata and `bookstack://page/{id}` for Markdown and page metadata. Both templates provide ID completion through BookStack search.
|
|
351
89
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
## Available Tools
|
|
355
|
-
|
|
356
|
-
### Read Operations (always available)
|
|
357
|
-
|
|
358
|
-
| Tool | Description |
|
|
359
|
-
|------|-------------|
|
|
360
|
-
| `search_content` | Search across all content with filtering |
|
|
361
|
-
| `search_pages` | Search pages with optional book filtering |
|
|
362
|
-
| `get_books` / `get_book` | List or get details of books |
|
|
363
|
-
| `get_pages` / `get_page` | List or get full page content |
|
|
364
|
-
| `get_chapters` / `get_chapter` | List or get chapter details |
|
|
365
|
-
| `get_shelves` / `get_shelf` | List or get shelf details |
|
|
366
|
-
| `get_attachments` / `get_attachment` | List or get attachment details |
|
|
367
|
-
| `list_images` | List gallery images, optionally filtered by page |
|
|
368
|
-
| `get_comments` / `get_comment` | List or get page comments (BookStack v25.11+) |
|
|
369
|
-
| `find_users` | Look up BookStack users by name, email, or slug to resolve user slugs for `{created_by:X}`-style search filters |
|
|
370
|
-
| `get_recycle_bin` | List items in the recycle bin |
|
|
371
|
-
| `export_page` | Export page as HTML, PDF, Markdown, plaintext, or ZIP |
|
|
372
|
-
| `export_book` | Export entire book |
|
|
373
|
-
| `export_chapter` | Export chapter |
|
|
374
|
-
| `get_recent_changes` | Recently updated content |
|
|
375
|
-
|
|
376
|
-
### Write Operations (requires `BOOKSTACK_ENABLE_WRITE=true`)
|
|
377
|
-
|
|
378
|
-
| Tool | Description |
|
|
379
|
-
|------|-------------|
|
|
380
|
-
| `create_book` / `update_book` / `delete_book` | Create, update, or delete a book |
|
|
381
|
-
| `create_chapter` / `update_chapter` / `delete_chapter` | Create, update (including moving to a different book or reordering), or delete a chapter |
|
|
382
|
-
| `create_page` | Create a new page (HTML or Markdown) |
|
|
383
|
-
| `update_page` | Update content, rename, or move to a different book/chapter |
|
|
384
|
-
| `delete_page` | Delete a page (recoverable from recycle bin) |
|
|
385
|
-
| `create_shelf` / `update_shelf` / `delete_shelf` | Manage shelves |
|
|
386
|
-
| `create_attachment` / `update_attachment` / `delete_attachment` | Manage attachments |
|
|
387
|
-
| `create_image` / `delete_image` | Upload gallery images from files or URLs, or delete images |
|
|
388
|
-
| `create_comment` / `update_comment` / `delete_comment` | Manage page comments (v25.11+) |
|
|
389
|
-
| `restore_deleted` / `permanently_delete` | Restore or permanently destroy items in the recycle bin |
|
|
390
|
-
|
|
391
|
-
## BookStack API Setup
|
|
392
|
-
|
|
393
|
-
1. Log into BookStack as an admin
|
|
394
|
-
2. Go to **Settings > Users > Edit your user**
|
|
395
|
-
3. Ensure the user has **Access System API** permission
|
|
396
|
-
4. In the **API Tokens** section, create a new token
|
|
397
|
-
5. Copy the Token ID and Token Secret
|
|
398
|
-
|
|
399
|
-
> **Also grant the role “Export Content”** if you read pages written in the
|
|
400
|
-
> WYSIWYG editor. BookStack returns an empty `markdown` body for those pages, and
|
|
401
|
-
> `get_page` recovers it from the server-side HTML→markdown export endpoint. Without
|
|
402
|
-
> the permission that fallback fails and the page reads as empty. The default Viewer
|
|
403
|
-
> role does not include it.
|
|
90
|
+
Four MCP prompts guide read workflows: `answer_from_wiki`, `find_pages`, `summarize_book`, and `recent_changes`. [Prompt arguments](docs/TOOLS.md#resources-and-prompts) are documented alongside the tools. Client support for resources and prompts varies.
|
|
404
91
|
|
|
405
92
|
## Security
|
|
406
93
|
|
|
407
|
-
-
|
|
408
|
-
- Use HTTPS for production instances
|
|
409
|
-
- Store API tokens securely (never commit to git)
|
|
410
|
-
- Consider a dedicated BookStack user with limited permissions
|
|
94
|
+
Use HTTPS, keep TLS verification enabled, and protect HTTP services with OAuth or a trusted internal network. HTTP without OAuth has no built-in caller authentication. Set an explicit allowed-host list when exposing a container; a host allowlist is not authentication.
|
|
411
95
|
|
|
412
|
-
|
|
96
|
+
HTTP image downloads require an allowed hostname, and local file uploads are disabled by default. Request bodies, request duration, and session counts are bounded. See [deployment boundaries](docs/CONFIGURATION.md#credentials-and-permissions) and the [security policy](SECURITY.md), including private vulnerability reporting.
|
|
413
97
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
npm run build # Production build
|
|
418
|
-
```
|
|
98
|
+
The [privacy policy](PRIVACY.md) explains data flows, credentials, OAuth/Redis state, and logging. Your AI client and deployment operator may have additional policies. Use is governed by the [terms](TERMS.md) and [MIT license](LICENSE).
|
|
99
|
+
|
|
100
|
+
## Documentation
|
|
419
101
|
|
|
420
|
-
|
|
102
|
+
Browse the [documentation index](docs/README.md) for installation, deployment, configuration, tool recipes, troubleshooting, contributions, releases, and [HOL Guard](docs/HOL.md). For a connection problem, start with the [troubleshooting guide](docs/TROUBLESHOOTING.md).
|
|
421
103
|
|
|
422
|
-
|
|
104
|
+
Design background: [Why my BookStack MCP server starts read-only](https://hackyourworld.com/bookstack-mcp-server-read-only-by-default/) describes permission boundaries, shared-token rate limiting, and response-size decisions.
|
|
@@ -36,6 +36,9 @@ export function loadOAuthConfig(env) {
|
|
|
36
36
|
const audience = env.OAUTH_AUDIENCE || `api://${clientId}`;
|
|
37
37
|
const scopes = env.OAUTH_SCOPES || `openid profile offline_access ${audience}/.default`;
|
|
38
38
|
const writeRole = env.OAUTH_WRITE_ROLE || "Writer";
|
|
39
|
+
const serviceRole = env.OAUTH_SERVICE_ROLE || "";
|
|
40
|
+
const serviceAppIds = (env.OAUTH_SERVICE_APP_IDS || "")
|
|
41
|
+
.split(",").map((s) => s.trim()).filter(Boolean);
|
|
39
42
|
const trustProxy = env.MCP_TRUST_PROXY?.toLowerCase() === "true";
|
|
40
43
|
const base = `https://login.microsoftonline.com/${tenantId}`;
|
|
41
44
|
return {
|
|
@@ -46,6 +49,8 @@ export function loadOAuthConfig(env) {
|
|
|
46
49
|
audience,
|
|
47
50
|
scopes,
|
|
48
51
|
writeRole,
|
|
52
|
+
serviceRole,
|
|
53
|
+
serviceAppIds,
|
|
49
54
|
trustProxy,
|
|
50
55
|
authorizeEndpoint: `${base}/oauth2/v2.0/authorize`,
|
|
51
56
|
tokenEndpoint: `${base}/oauth2/v2.0/token`,
|
|
@@ -125,14 +130,23 @@ function audienceMatches(cfg, aud) {
|
|
|
125
130
|
return aud.some((a) => accepted.has(a));
|
|
126
131
|
return false;
|
|
127
132
|
}
|
|
128
|
-
|
|
133
|
+
// A token with no delegated scope is app-only (client credentials): Entra
|
|
134
|
+
// issues one to any app in the tenant that asks for this audience, with no
|
|
135
|
+
// user, no MFA and no role unless one was assigned. v2 app tokens omit idtyp
|
|
136
|
+
// unless that optional claim is configured, so the missing scp decides.
|
|
137
|
+
function isAppOnly(payload) {
|
|
138
|
+
if (payload.idtyp === "app")
|
|
139
|
+
return true;
|
|
140
|
+
return typeof payload.scp !== "string" || payload.scp.trim() === "";
|
|
141
|
+
}
|
|
142
|
+
export async function validateBearer(req, cfg, keys = getJwks(cfg)) {
|
|
129
143
|
const header = req.headers["authorization"];
|
|
130
144
|
if (!header || Array.isArray(header) || !header.startsWith("Bearer ")) {
|
|
131
145
|
return { ok: false, error: "missing bearer token" };
|
|
132
146
|
}
|
|
133
147
|
const token = header.slice("Bearer ".length).trim();
|
|
134
148
|
try {
|
|
135
|
-
const { payload } = await jwtVerify(token,
|
|
149
|
+
const { payload } = await jwtVerify(token, keys, {
|
|
136
150
|
issuer: cfg.issuers,
|
|
137
151
|
});
|
|
138
152
|
if (!audienceMatches(cfg, payload.aud)) {
|
|
@@ -141,9 +155,22 @@ export async function validateBearer(req, cfg) {
|
|
|
141
155
|
const roles = Array.isArray(payload.roles)
|
|
142
156
|
? payload.roles
|
|
143
157
|
: [];
|
|
158
|
+
const sub = typeof payload.sub === "string" ? payload.sub : undefined;
|
|
159
|
+
if (isAppOnly(payload)) {
|
|
160
|
+
const appId = typeof payload.azp === "string" ? payload.azp
|
|
161
|
+
: typeof payload.appid === "string" ? payload.appid : "";
|
|
162
|
+
if (!cfg.serviceRole || !roles.includes(cfg.serviceRole)) {
|
|
163
|
+
return { ok: false, error: "app-only token without the service role" };
|
|
164
|
+
}
|
|
165
|
+
if (!appId || !cfg.serviceAppIds.includes(appId)) {
|
|
166
|
+
return { ok: false, error: "app-only token from an app that is not allowed" };
|
|
167
|
+
}
|
|
168
|
+
// A service caller reads only: write mode stays a user decision.
|
|
169
|
+
return { ok: true, sub, roles, isWriter: false, service: true };
|
|
170
|
+
}
|
|
144
171
|
return {
|
|
145
172
|
ok: true,
|
|
146
|
-
sub
|
|
173
|
+
sub,
|
|
147
174
|
roles,
|
|
148
175
|
isWriter: roles.includes(cfg.writeRole),
|
|
149
176
|
};
|