bookstack-mcp 3.4.0 → 4.0.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.
- package/README.md +13 -2
- package/dist/bookstack-client.js +59 -136
- package/dist/index.js +159 -224
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ npx bookstack-mcp
|
|
|
23
23
|
- Type-safe input validation with Zod (auto-coerces string/number params for broad client compatibility)
|
|
24
24
|
- Embedded URLs and content previews in all responses
|
|
25
25
|
- Markdown export fallback for HTML-authored pages, so AI clients always get usable content
|
|
26
|
+
- Token-efficient responses: compact JSON, no redundant fields, no N+1 fetches — ~30–55% smaller payloads than 3.x
|
|
26
27
|
- Write operations disabled by default for safety
|
|
27
28
|
- Works with Claude Desktop, Claude Code, LibreChat, and any MCP-compatible client
|
|
28
29
|
- Stdio and Streamable HTTP transports
|
|
@@ -60,7 +61,15 @@ BOOKSTACK_INSECURE_SKIP_TLS_VERIFY=false # Optional, default false
|
|
|
60
61
|
|
|
61
62
|
### Claude Desktop
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
The easiest install is the prebuilt MCPB bundle attached to each [GitHub release](https://github.com/ttpears/bookstack-mcp/releases/latest):
|
|
65
|
+
|
|
66
|
+
1. Download `bookstack-mcp-<version>.mcpb` from the latest release.
|
|
67
|
+
2. Open Claude Desktop → **Settings → Extensions** and drag the `.mcpb` file in (or click *Install Extension*).
|
|
68
|
+
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.
|
|
69
|
+
|
|
70
|
+
#### Manual install (JSON config)
|
|
71
|
+
|
|
72
|
+
If you'd rather edit the config file directly:
|
|
64
73
|
|
|
65
74
|
```json
|
|
66
75
|
{
|
|
@@ -206,13 +215,14 @@ Books and pages are also exposed as MCP resources, so clients that browse resour
|
|
|
206
215
|
|
|
207
216
|
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.
|
|
208
217
|
|
|
218
|
+
> **4.0.0 breaking changes:** tool responses were trimmed for token efficiency. Removed fields: `direct_link`, `*_friendly` date strings, `content_info`, `contextual_info`, `change_summary`, `pagination_hint`, `location`, `summary`/`tags_summary`/`book_count` on shelves, and the buggy `page_url` on attachments. Use `url`, the ISO date fields, and `download_url` instead. The `get_capabilities` tool was removed — clients should use `tools/list` (built into MCP). Responses are now compact JSON (no pretty-printing) and `get_recent_changes` no longer issues per-result fetches.
|
|
219
|
+
|
|
209
220
|
## Available Tools
|
|
210
221
|
|
|
211
222
|
### Read Operations (always available)
|
|
212
223
|
|
|
213
224
|
| Tool | Description |
|
|
214
225
|
|------|-------------|
|
|
215
|
-
| `get_capabilities` | Server capabilities and configuration |
|
|
216
226
|
| `search_content` | Search across all content with filtering |
|
|
217
227
|
| `search_pages` | Search pages with optional book filtering |
|
|
218
228
|
| `get_books` / `get_book` | List or get details of books |
|
|
@@ -221,6 +231,7 @@ Both templates support `id` autocompletion: as you type, the server searches Boo
|
|
|
221
231
|
| `get_shelves` / `get_shelf` | List or get shelf details |
|
|
222
232
|
| `get_attachments` / `get_attachment` | List or get attachment details |
|
|
223
233
|
| `get_comments` / `get_comment` | List or get page comments (BookStack v25.11+) |
|
|
234
|
+
| `find_users` | Look up BookStack users by name, email, or slug to resolve numeric user IDs for search filters |
|
|
224
235
|
| `get_recycle_bin` | List items in the recycle bin |
|
|
225
236
|
| `export_page` | Export page as HTML, PDF, Markdown, plaintext, or ZIP |
|
|
226
237
|
| `export_book` | Export entire book |
|
package/dist/bookstack-client.js
CHANGED
|
@@ -12,6 +12,19 @@ function parseRetryAfter(value) {
|
|
|
12
12
|
return Math.max(0, dateMs - Date.now());
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
+
// BookStack's advanced search silently ignores {created_by:X}/{updated_by:X}/{owned_by:X}
|
|
16
|
+
// when X isn't a numeric user ID — the query falls back to unfiltered results, which is
|
|
17
|
+
// a confusing footgun. Reject the bad form up front and point the caller at find_users.
|
|
18
|
+
function validateUserIdFilters(query) {
|
|
19
|
+
const re = /\{(created_by|updated_by|owned_by):([^}\s]+)\}/g;
|
|
20
|
+
for (const match of query.matchAll(re)) {
|
|
21
|
+
const [, field, value] = match;
|
|
22
|
+
if (!/^\d+$/.test(value)) {
|
|
23
|
+
throw new Error(`Search filter {${field}:${value}} requires a numeric user ID, not "${value}". ` +
|
|
24
|
+
`Use the find_users tool to look up a user's ID by name, email, or slug.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
export class BookStackClient {
|
|
16
29
|
client;
|
|
17
30
|
enableWrite;
|
|
@@ -89,23 +102,17 @@ export class BookStackClient {
|
|
|
89
102
|
const encodedQuery = encodeURIComponent(query);
|
|
90
103
|
return `${this.baseUrl}/search?term=${encodedQuery}`;
|
|
91
104
|
}
|
|
92
|
-
// Enhanced response helpers
|
|
105
|
+
// Enhanced response helpers. Each one adds only `url` on top of the raw
|
|
106
|
+
// BookStack record — narrated/duplicate fields (direct_link, *_friendly,
|
|
107
|
+
// content_info, summary, location, etc.) were removed to shrink the MCP
|
|
108
|
+
// payload; the LLM can derive them from the raw fields when needed.
|
|
93
109
|
enhanceBookResponse(book) {
|
|
94
|
-
const lastUpdated = this.formatDate(book.updated_at);
|
|
95
|
-
const created = this.formatDate(book.created_at);
|
|
96
110
|
return {
|
|
97
111
|
...book,
|
|
98
|
-
url: this.generateBookUrl(book)
|
|
99
|
-
direct_link: `[${book.name}](${this.generateBookUrl(book)})`,
|
|
100
|
-
last_updated_friendly: lastUpdated,
|
|
101
|
-
created_friendly: created,
|
|
102
|
-
summary: book.description ? `${book.description.substring(0, 100)}${book.description.length > 100 ? '...' : ''}` : 'No description available',
|
|
103
|
-
content_info: `Book created ${created}, last updated ${lastUpdated}`
|
|
112
|
+
url: this.generateBookUrl(book)
|
|
104
113
|
};
|
|
105
114
|
}
|
|
106
115
|
async enhancePageResponse(page, options) {
|
|
107
|
-
const lastUpdated = this.formatDate(page.updated_at);
|
|
108
|
-
const created = this.formatDate(page.created_at);
|
|
109
116
|
const url = await this.generatePageUrl(page);
|
|
110
117
|
// Pick a single content format to return to avoid 3x duplication (html + markdown + text)
|
|
111
118
|
const format = options?.format ?? 'markdown';
|
|
@@ -126,72 +133,41 @@ export class BookStackClient {
|
|
|
126
133
|
return {
|
|
127
134
|
...pageMeta,
|
|
128
135
|
url,
|
|
129
|
-
direct_link: `[${page.name}](${url})`,
|
|
130
|
-
last_updated_friendly: lastUpdated,
|
|
131
|
-
created_friendly: created,
|
|
132
|
-
content_info: `Page created ${created}, last updated ${lastUpdated}`,
|
|
133
136
|
word_count: page.text ? page.text.split(' ').length : 0,
|
|
134
|
-
location: `Book ID ${page.book_id}${page.chapter_id ? `, Chapter ID ${page.chapter_id}` : ''}`,
|
|
135
137
|
content_format: format,
|
|
136
138
|
content_total_chars: totalChars,
|
|
137
139
|
content_offset: offset,
|
|
138
140
|
content_returned_chars: slice.length,
|
|
139
141
|
content_truncated: truncated,
|
|
140
142
|
content_next_offset: truncated ? nextOffset : null,
|
|
141
|
-
pagination_hint: truncated
|
|
142
|
-
? `Only ${nextOffset}/${totalChars} characters returned. Call get_page again with offset=${nextOffset} to continue, or pass a larger limit.`
|
|
143
|
-
: undefined,
|
|
144
143
|
content: slice
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
146
|
async enhanceChapterResponse(chapter) {
|
|
148
|
-
const lastUpdated = this.formatDate(chapter.updated_at);
|
|
149
|
-
const created = this.formatDate(chapter.created_at);
|
|
150
147
|
const url = await this.generateChapterUrl(chapter);
|
|
151
|
-
return {
|
|
152
|
-
...chapter,
|
|
153
|
-
url,
|
|
154
|
-
direct_link: `[${chapter.name}](${url})`,
|
|
155
|
-
last_updated_friendly: lastUpdated,
|
|
156
|
-
created_friendly: created,
|
|
157
|
-
summary: chapter.description ? `${chapter.description.substring(0, 100)}${chapter.description.length > 100 ? '...' : ''}` : 'No description available',
|
|
158
|
-
content_info: `Chapter created ${created}, last updated ${lastUpdated}`,
|
|
159
|
-
location: `In Book ID ${chapter.book_id}`
|
|
160
|
-
};
|
|
148
|
+
return { ...chapter, url };
|
|
161
149
|
}
|
|
162
150
|
enhanceShelfResponse(shelf) {
|
|
163
|
-
const lastUpdated = this.formatDate(shelf.updated_at);
|
|
164
|
-
const created = this.formatDate(shelf.created_at);
|
|
165
|
-
const bookCount = shelf.books?.length || 0;
|
|
166
151
|
return {
|
|
167
152
|
...shelf,
|
|
168
153
|
url: this.generateShelfUrl(shelf),
|
|
169
|
-
|
|
170
|
-
last_updated_friendly: lastUpdated,
|
|
171
|
-
created_friendly: created,
|
|
172
|
-
summary: shelf.description ? `${shelf.description.substring(0, 100)}${shelf.description.length > 100 ? '...' : ''}` : 'No description available',
|
|
173
|
-
content_info: `Shelf with ${bookCount} book${bookCount !== 1 ? 's' : ''}, created ${created}, last updated ${lastUpdated}`,
|
|
174
|
-
book_count: bookCount,
|
|
175
|
-
books: shelf.books?.map(book => this.enhanceBookResponse(book)),
|
|
176
|
-
tags_summary: shelf.tags?.length ? `Tagged with: ${shelf.tags.map(t => `${t.name}${t.value ? `=${t.value}` : ''}`).join(', ')}` : 'No tags'
|
|
154
|
+
books: shelf.books?.map(book => this.enhanceBookResponse(book))
|
|
177
155
|
};
|
|
178
156
|
}
|
|
179
157
|
async enhanceSearchResults(results, originalQuery) {
|
|
180
158
|
const enhancedResults = await Promise.all(results.map(async (result) => {
|
|
181
159
|
const url = await this.generateContentUrl(result);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
location_info: result.book_id ? `In book ID ${result.book_id}${result.chapter_id ? `, chapter ID ${result.chapter_id}` : ''}` : 'Location unknown'
|
|
189
|
-
};
|
|
160
|
+
const preview = result.preview_content?.content;
|
|
161
|
+
const out = { ...result, url };
|
|
162
|
+
if (preview) {
|
|
163
|
+
out.content_preview = preview.length > 150 ? `${preview.substring(0, 150)}...` : preview;
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
190
166
|
}));
|
|
191
167
|
return {
|
|
192
168
|
search_query: originalQuery,
|
|
193
169
|
search_url: this.generateSearchUrl(originalQuery),
|
|
194
|
-
|
|
170
|
+
total: results.length,
|
|
195
171
|
results: enhancedResults
|
|
196
172
|
};
|
|
197
173
|
}
|
|
@@ -219,6 +195,7 @@ export class BookStackClient {
|
|
|
219
195
|
}
|
|
220
196
|
}
|
|
221
197
|
async searchContent(query, options) {
|
|
198
|
+
validateUserIdFilters(query);
|
|
222
199
|
let searchQuery = query;
|
|
223
200
|
// Use advanced search syntax for type filtering
|
|
224
201
|
if (options?.type) {
|
|
@@ -234,6 +211,7 @@ export class BookStackClient {
|
|
|
234
211
|
return await this.enhanceSearchResults(results, query);
|
|
235
212
|
}
|
|
236
213
|
async searchPages(query, options) {
|
|
214
|
+
validateUserIdFilters(query);
|
|
237
215
|
let searchQuery = `{type:page} ${query}`.trim();
|
|
238
216
|
// Add book filtering if specified
|
|
239
217
|
if (options?.bookId) {
|
|
@@ -288,25 +266,15 @@ export class BookStackClient {
|
|
|
288
266
|
};
|
|
289
267
|
}
|
|
290
268
|
async enhancePageListItem(page) {
|
|
291
|
-
const lastUpdated = this.formatDate(page.updated_at);
|
|
292
|
-
const created = this.formatDate(page.created_at);
|
|
293
269
|
const url = await this.generatePageUrl(page);
|
|
294
|
-
const preview = page.text
|
|
295
|
-
? `${page.text.substring(0, 200)}${page.text.length > 200 ? '...' : ''}`
|
|
296
|
-
: 'No content preview available';
|
|
297
270
|
// List responses from BookStack don't include html/markdown/text/raw_html, but strip
|
|
298
271
|
// defensively and never embed full content here — use get_page for that.
|
|
299
272
|
const { html: _h, markdown: _m, text: _t, raw_html: _r, ...pageMeta } = page;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
created_friendly: created,
|
|
306
|
-
content_preview: preview,
|
|
307
|
-
content_info: `Page created ${created}, last updated ${lastUpdated}`,
|
|
308
|
-
location: `Book ID ${page.book_id}${page.chapter_id ? `, Chapter ID ${page.chapter_id}` : ''}`
|
|
309
|
-
};
|
|
273
|
+
const out = { ...pageMeta, url };
|
|
274
|
+
if (page.text) {
|
|
275
|
+
out.content_preview = page.text.length > 200 ? `${page.text.substring(0, 200)}...` : page.text;
|
|
276
|
+
}
|
|
277
|
+
return out;
|
|
310
278
|
}
|
|
311
279
|
async getPage(id, options) {
|
|
312
280
|
const response = await this.client.get(`/pages/${id}`);
|
|
@@ -507,76 +475,24 @@ export class BookStackClient {
|
|
|
507
475
|
};
|
|
508
476
|
const response = await this.client.get('/search', { params });
|
|
509
477
|
const results = response.data.data || response.data;
|
|
510
|
-
//
|
|
478
|
+
// Use the search response data as-is — no per-item BookStack fetch (was N+1).
|
|
479
|
+
// Callers can fetch full details via get_page/get_book/get_chapter if needed.
|
|
511
480
|
const enhancedResults = await Promise.all(results.map(async (result) => {
|
|
512
|
-
let contextualInfo = '';
|
|
513
|
-
let contentPreview = result.preview_content?.content || '';
|
|
514
|
-
try {
|
|
515
|
-
// Get additional context based on content type
|
|
516
|
-
if (result.type === 'page' && result.id) {
|
|
517
|
-
const fullPage = await this.client.get(`/pages/${result.id}`);
|
|
518
|
-
const pageData = fullPage.data;
|
|
519
|
-
contentPreview = pageData.text?.substring(0, 200) || contentPreview;
|
|
520
|
-
contextualInfo = `Updated in book: ${pageData.book?.name || 'Unknown Book'}`;
|
|
521
|
-
if (pageData.chapter) {
|
|
522
|
-
contextualInfo += `, chapter: ${pageData.chapter.name}`;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
else if (result.type === 'book' && result.id) {
|
|
526
|
-
const fullBook = await this.client.get(`/books/${result.id}`);
|
|
527
|
-
const bookData = fullBook.data;
|
|
528
|
-
contentPreview = bookData.description?.substring(0, 200) || 'No description available';
|
|
529
|
-
contextualInfo = `Book with ${bookData.page_count || 0} pages`;
|
|
530
|
-
}
|
|
531
|
-
else if (result.type === 'chapter' && result.id) {
|
|
532
|
-
const fullChapter = await this.client.get(`/chapters/${result.id}`);
|
|
533
|
-
const chapterData = fullChapter.data;
|
|
534
|
-
contentPreview = chapterData.description?.substring(0, 200) || 'No description available';
|
|
535
|
-
contextualInfo = `Chapter in book: ${chapterData.book?.name || 'Unknown Book'}`;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
catch (error) {
|
|
539
|
-
// If we can't get additional context, use what we have
|
|
540
|
-
contextualInfo = `${result.type.charAt(0).toUpperCase() + result.type.slice(1)} content`;
|
|
541
|
-
}
|
|
542
481
|
const url = await this.generateContentUrl(result);
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
last_updated: this.formatDate(result.updated_at || result.created_at || ''),
|
|
550
|
-
change_summary: `${result.type === 'page' ? 'Page' : result.type === 'book' ? 'Book' : 'Chapter'} "${result.name}" was updated`
|
|
551
|
-
};
|
|
482
|
+
const preview = result.preview_content?.content;
|
|
483
|
+
const out = { ...result, url };
|
|
484
|
+
if (preview) {
|
|
485
|
+
out.content_preview = preview.length > 200 ? `${preview.substring(0, 200)}...` : preview;
|
|
486
|
+
}
|
|
487
|
+
return out;
|
|
552
488
|
}));
|
|
553
489
|
return {
|
|
554
|
-
search_query: `Recent changes in the last ${days} days (${type})`,
|
|
555
490
|
date_threshold: dateFilter,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
summary: `Found ${results.length} items updated in the last ${days} days${type !== 'all' ? ` (${type}s only)` : ''}`,
|
|
491
|
+
type,
|
|
492
|
+
total: results.length,
|
|
559
493
|
results: enhancedResults
|
|
560
494
|
};
|
|
561
495
|
}
|
|
562
|
-
formatDate(dateString) {
|
|
563
|
-
if (!dateString)
|
|
564
|
-
return 'Unknown date';
|
|
565
|
-
const date = new Date(dateString);
|
|
566
|
-
const now = new Date();
|
|
567
|
-
const diffInHours = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60));
|
|
568
|
-
if (diffInHours < 1)
|
|
569
|
-
return 'Less than an hour ago';
|
|
570
|
-
if (diffInHours < 24)
|
|
571
|
-
return `${diffInHours} hours ago`;
|
|
572
|
-
const diffInDays = Math.floor(diffInHours / 24);
|
|
573
|
-
if (diffInDays < 7)
|
|
574
|
-
return `${diffInDays} days ago`;
|
|
575
|
-
const diffInWeeks = Math.floor(diffInDays / 7);
|
|
576
|
-
if (diffInWeeks < 4)
|
|
577
|
-
return `${diffInWeeks} weeks ago`;
|
|
578
|
-
return date.toLocaleDateString();
|
|
579
|
-
}
|
|
580
496
|
// Shelves (Book Collections) Management
|
|
581
497
|
async getShelves(options) {
|
|
582
498
|
const params = {
|
|
@@ -633,8 +549,7 @@ export class BookStackClient {
|
|
|
633
549
|
...data,
|
|
634
550
|
data: data.data.map((attachment) => ({
|
|
635
551
|
...attachment,
|
|
636
|
-
|
|
637
|
-
direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`
|
|
552
|
+
download_url: `${this.baseUrl}/attachments/${attachment.id}`
|
|
638
553
|
}))
|
|
639
554
|
};
|
|
640
555
|
}
|
|
@@ -643,8 +558,6 @@ export class BookStackClient {
|
|
|
643
558
|
const attachment = response.data;
|
|
644
559
|
return {
|
|
645
560
|
...attachment,
|
|
646
|
-
page_url: `${this.baseUrl}/books/${Math.floor(attachment.uploaded_to / 1000)}/page/${attachment.uploaded_to}`,
|
|
647
|
-
direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`,
|
|
648
561
|
download_url: `${this.baseUrl}/attachments/${attachment.id}`
|
|
649
562
|
};
|
|
650
563
|
}
|
|
@@ -656,8 +569,7 @@ export class BookStackClient {
|
|
|
656
569
|
const attachment = response.data;
|
|
657
570
|
return {
|
|
658
571
|
...attachment,
|
|
659
|
-
|
|
660
|
-
direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`
|
|
572
|
+
download_url: `${this.baseUrl}/attachments/${attachment.id}`
|
|
661
573
|
};
|
|
662
574
|
}
|
|
663
575
|
async updateAttachment(id, data) {
|
|
@@ -668,8 +580,7 @@ export class BookStackClient {
|
|
|
668
580
|
const attachment = response.data;
|
|
669
581
|
return {
|
|
670
582
|
...attachment,
|
|
671
|
-
|
|
672
|
-
direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`
|
|
583
|
+
download_url: `${this.baseUrl}/attachments/${attachment.id}`
|
|
673
584
|
};
|
|
674
585
|
}
|
|
675
586
|
async deleteAttachment(id) {
|
|
@@ -742,4 +653,16 @@ export class BookStackClient {
|
|
|
742
653
|
const response = await this.client.delete(`/recycle-bin/${deletionId}`);
|
|
743
654
|
return response.data;
|
|
744
655
|
}
|
|
656
|
+
// Users
|
|
657
|
+
async getUsers(options) {
|
|
658
|
+
const params = {
|
|
659
|
+
offset: options?.offset || 0,
|
|
660
|
+
count: Math.min(options?.count || 50, 500)
|
|
661
|
+
};
|
|
662
|
+
if (options?.sort)
|
|
663
|
+
params.sort = options.sort;
|
|
664
|
+
this.applyFilters(params, options?.filter);
|
|
665
|
+
const response = await this.client.get('/users', { params });
|
|
666
|
+
return response.data;
|
|
667
|
+
}
|
|
745
668
|
}
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ function registerResources(server, client) {
|
|
|
56
56
|
resources: (books.data ?? []).map((b) => ({
|
|
57
57
|
uri: `bookstack://book/${b.id}`,
|
|
58
58
|
name: b.name,
|
|
59
|
-
description: b.
|
|
59
|
+
description: b.description ?? undefined,
|
|
60
60
|
mimeType: "application/json"
|
|
61
61
|
}))
|
|
62
62
|
};
|
|
@@ -70,7 +70,6 @@ function registerResources(server, client) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}), {
|
|
73
|
-
title: "BookStack Book",
|
|
74
73
|
description: "A BookStack book exposed as an MCP resource",
|
|
75
74
|
mimeType: "application/json"
|
|
76
75
|
}, async (uri, variables) => {
|
|
@@ -83,7 +82,7 @@ function registerResources(server, client) {
|
|
|
83
82
|
contents: [{
|
|
84
83
|
uri: uri.href,
|
|
85
84
|
mimeType: "application/json",
|
|
86
|
-
text: JSON.stringify(book
|
|
85
|
+
text: JSON.stringify(book)
|
|
87
86
|
}]
|
|
88
87
|
};
|
|
89
88
|
});
|
|
@@ -95,7 +94,7 @@ function registerResources(server, client) {
|
|
|
95
94
|
resources: (pages.data ?? []).map((p) => ({
|
|
96
95
|
uri: `bookstack://page/${p.id}`,
|
|
97
96
|
name: p.name,
|
|
98
|
-
description: p.content_preview ??
|
|
97
|
+
description: p.content_preview ?? undefined,
|
|
99
98
|
mimeType: "text/markdown"
|
|
100
99
|
}))
|
|
101
100
|
};
|
|
@@ -109,7 +108,6 @@ function registerResources(server, client) {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
}), {
|
|
112
|
-
title: "BookStack Page",
|
|
113
111
|
description: "A BookStack page exposed as an MCP resource (markdown content)",
|
|
114
112
|
mimeType: "text/markdown"
|
|
115
113
|
}, async (uri, variables) => {
|
|
@@ -133,10 +131,10 @@ function registerResources(server, client) {
|
|
|
133
131
|
chapter_id: page.chapter_id,
|
|
134
132
|
url: page.url,
|
|
135
133
|
word_count: page.word_count,
|
|
136
|
-
|
|
134
|
+
updated_at: page.updated_at,
|
|
137
135
|
content_truncated: page.content_truncated,
|
|
138
136
|
content_total_chars: page.content_total_chars
|
|
139
|
-
}
|
|
137
|
+
})
|
|
140
138
|
}]
|
|
141
139
|
};
|
|
142
140
|
});
|
|
@@ -147,33 +145,16 @@ function registerTools(server, client, config) {
|
|
|
147
145
|
// to the SDK's generic overloads at the call sites.
|
|
148
146
|
const readTool = ((name, cfg, handler) => server.registerTool(name, { ...cfg, annotations: { ...READ_ONLY_ANNOTATIONS, ...(cfg.annotations ?? {}) } }, handler));
|
|
149
147
|
const writeTool = ((name, cfg, handler) => server.registerTool(name, { ...cfg, annotations: { ...WRITE_ANNOTATIONS, ...(cfg.annotations ?? {}) } }, handler));
|
|
150
|
-
// Register read-only tools
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
description: "Get information about available BookStack MCP capabilities and current configuration",
|
|
154
|
-
inputSchema: {}
|
|
155
|
-
}, async () => {
|
|
156
|
-
const capabilities = {
|
|
157
|
-
server_name: "BookStack MCP Server",
|
|
158
|
-
version: PKG_VERSION,
|
|
159
|
-
write_operations_enabled: config.enableWrite,
|
|
160
|
-
available_tools: config.enableWrite ? "All tools enabled" : "Read-only tools only",
|
|
161
|
-
security_note: config.enableWrite
|
|
162
|
-
? "⚠️ Write operations are ENABLED - AI can create and modify BookStack content"
|
|
163
|
-
: "🛡️ Read-only mode - Safe for production use"
|
|
164
|
-
};
|
|
165
|
-
return {
|
|
166
|
-
content: [{ type: "text", text: JSON.stringify(capabilities, null, 2) }]
|
|
167
|
-
};
|
|
168
|
-
});
|
|
148
|
+
// Register read-only tools.
|
|
149
|
+
// Common params (offset/count/sort/filter/id) are self-describing and intentionally
|
|
150
|
+
// bare so tool definitions stay compact in the MCP tools/list payload.
|
|
169
151
|
readTool("search_content", {
|
|
170
|
-
|
|
171
|
-
description: "Search across BookStack content with contextual previews and location info",
|
|
152
|
+
description: "Search BookStack content. Supports advanced syntax like {type:page} or {book_id:5}. {created_by:X}/{updated_by:X}/{owned_by:X} need a numeric user ID — use find_users to resolve names.",
|
|
172
153
|
inputSchema: {
|
|
173
|
-
query: z.string()
|
|
174
|
-
type: z.enum(["book", "page", "chapter", "bookshelf"]).optional()
|
|
175
|
-
count: z.coerce.number().max(500).optional()
|
|
176
|
-
offset: z.coerce.number().optional()
|
|
154
|
+
query: z.string(),
|
|
155
|
+
type: z.enum(["book", "page", "chapter", "bookshelf"]).optional(),
|
|
156
|
+
count: z.coerce.number().max(500).optional(),
|
|
157
|
+
offset: z.coerce.number().optional()
|
|
177
158
|
}
|
|
178
159
|
}, async (args) => {
|
|
179
160
|
const results = await client.searchContent(args.query, {
|
|
@@ -181,18 +162,15 @@ function registerTools(server, client, config) {
|
|
|
181
162
|
count: args.count,
|
|
182
163
|
offset: args.offset
|
|
183
164
|
});
|
|
184
|
-
return {
|
|
185
|
-
content: [{ type: "text", text: JSON.stringify(results, null, 2) }]
|
|
186
|
-
};
|
|
165
|
+
return { content: [{ type: "text", text: JSON.stringify(results) }] };
|
|
187
166
|
});
|
|
188
167
|
readTool("search_pages", {
|
|
189
|
-
|
|
190
|
-
description: "Search specifically for pages with optional book filtering",
|
|
168
|
+
description: "Search BookStack pages, optionally within a book. Same user-ID caveat as search_content.",
|
|
191
169
|
inputSchema: {
|
|
192
|
-
query: z.string()
|
|
193
|
-
book_id: z.coerce.number().optional()
|
|
194
|
-
count: z.coerce.number().max(500).optional()
|
|
195
|
-
offset: z.coerce.number().optional()
|
|
170
|
+
query: z.string(),
|
|
171
|
+
book_id: z.coerce.number().optional(),
|
|
172
|
+
count: z.coerce.number().max(500).optional(),
|
|
173
|
+
offset: z.coerce.number().optional()
|
|
196
174
|
}
|
|
197
175
|
}, async (args) => {
|
|
198
176
|
const results = await client.searchPages(args.query, {
|
|
@@ -200,18 +178,15 @@ function registerTools(server, client, config) {
|
|
|
200
178
|
count: args.count,
|
|
201
179
|
offset: args.offset
|
|
202
180
|
});
|
|
203
|
-
return {
|
|
204
|
-
content: [{ type: "text", text: JSON.stringify(results, null, 2) }]
|
|
205
|
-
};
|
|
181
|
+
return { content: [{ type: "text", text: JSON.stringify(results) }] };
|
|
206
182
|
});
|
|
207
183
|
readTool("get_books", {
|
|
208
|
-
|
|
209
|
-
description: "List available books with advanced filtering and sorting",
|
|
184
|
+
description: "List books with optional filter/sort.",
|
|
210
185
|
inputSchema: {
|
|
211
|
-
offset: z.coerce.number().default(0)
|
|
212
|
-
count: z.coerce.number().max(500).default(50)
|
|
213
|
-
sort: z.string().optional()
|
|
214
|
-
filter: z.record(z.any()).optional()
|
|
186
|
+
offset: z.coerce.number().default(0),
|
|
187
|
+
count: z.coerce.number().max(500).default(50),
|
|
188
|
+
sort: z.string().optional(),
|
|
189
|
+
filter: z.record(z.any()).optional()
|
|
215
190
|
}
|
|
216
191
|
}, async (args) => {
|
|
217
192
|
const books = await client.getBooks({
|
|
@@ -221,31 +196,29 @@ function registerTools(server, client, config) {
|
|
|
221
196
|
filter: args.filter
|
|
222
197
|
});
|
|
223
198
|
return {
|
|
224
|
-
content: [{ type: "text", text: JSON.stringify(books
|
|
199
|
+
content: [{ type: "text", text: JSON.stringify(books) }]
|
|
225
200
|
};
|
|
226
201
|
});
|
|
227
202
|
readTool("get_book", {
|
|
228
|
-
|
|
229
|
-
description: "Get detailed information about a specific book",
|
|
203
|
+
description: "Get a book.",
|
|
230
204
|
inputSchema: {
|
|
231
|
-
id: z.coerce.number().min(1)
|
|
205
|
+
id: z.coerce.number().min(1)
|
|
232
206
|
}
|
|
233
207
|
}, async (args) => {
|
|
234
208
|
const book = await client.getBook(args.id);
|
|
235
209
|
return {
|
|
236
|
-
content: [{ type: "text", text: JSON.stringify(book
|
|
210
|
+
content: [{ type: "text", text: JSON.stringify(book) }]
|
|
237
211
|
};
|
|
238
212
|
});
|
|
239
213
|
readTool("get_pages", {
|
|
240
|
-
|
|
241
|
-
description: "List pages with content previews, word counts, and contextual information",
|
|
214
|
+
description: "List pages with previews.",
|
|
242
215
|
inputSchema: {
|
|
243
|
-
book_id: z.coerce.number().optional()
|
|
244
|
-
chapter_id: z.coerce.number().optional()
|
|
245
|
-
offset: z.coerce.number().default(0)
|
|
246
|
-
count: z.coerce.number().max(500).default(50)
|
|
247
|
-
sort: z.string().optional()
|
|
248
|
-
filter: z.record(z.any()).optional()
|
|
216
|
+
book_id: z.coerce.number().optional(),
|
|
217
|
+
chapter_id: z.coerce.number().optional(),
|
|
218
|
+
offset: z.coerce.number().default(0),
|
|
219
|
+
count: z.coerce.number().max(500).default(50),
|
|
220
|
+
sort: z.string().optional(),
|
|
221
|
+
filter: z.record(z.any()).optional()
|
|
249
222
|
}
|
|
250
223
|
}, async (args) => {
|
|
251
224
|
const pages = await client.getPages({
|
|
@@ -257,14 +230,13 @@ function registerTools(server, client, config) {
|
|
|
257
230
|
filter: args.filter
|
|
258
231
|
});
|
|
259
232
|
return {
|
|
260
|
-
content: [{ type: "text", text: JSON.stringify(pages
|
|
233
|
+
content: [{ type: "text", text: JSON.stringify(pages) }]
|
|
261
234
|
};
|
|
262
235
|
});
|
|
263
236
|
readTool("get_page", {
|
|
264
|
-
|
|
265
|
-
description: "Get content of a specific page. Returns one content format (default markdown) and supports character-range pagination so large pages don't blow the context window. Use offset/limit or the returned content_next_offset to page through long content.",
|
|
237
|
+
description: "Get a page. Returns one format (default markdown); use offset/limit + content_next_offset to paginate large pages.",
|
|
266
238
|
inputSchema: {
|
|
267
|
-
id: z.coerce.number().min(1)
|
|
239
|
+
id: z.coerce.number().min(1),
|
|
268
240
|
format: z.enum(["markdown", "html", "text"]).optional().describe("Which content format to return. Defaults to markdown."),
|
|
269
241
|
offset: z.coerce.number().min(0).optional().describe("Character offset into the content to start from (default 0)"),
|
|
270
242
|
limit: z.coerce.number().min(1).max(200000).optional().describe("Max characters of content to return (default 50000)")
|
|
@@ -276,127 +248,87 @@ function registerTools(server, client, config) {
|
|
|
276
248
|
limit: args.limit
|
|
277
249
|
});
|
|
278
250
|
return {
|
|
279
|
-
content: [{ type: "text", text: JSON.stringify(page
|
|
251
|
+
content: [{ type: "text", text: JSON.stringify(page) }]
|
|
280
252
|
};
|
|
281
253
|
});
|
|
282
254
|
readTool("get_chapters", {
|
|
283
|
-
|
|
284
|
-
description: "List chapters, optionally filtered by book",
|
|
255
|
+
description: "List chapters; optional book_id.",
|
|
285
256
|
inputSchema: {
|
|
286
|
-
book_id: z.coerce.number().optional()
|
|
287
|
-
offset: z.coerce.number().default(0)
|
|
288
|
-
count: z.coerce.number().default(50)
|
|
257
|
+
book_id: z.coerce.number().optional(),
|
|
258
|
+
offset: z.coerce.number().default(0),
|
|
259
|
+
count: z.coerce.number().default(50)
|
|
289
260
|
}
|
|
290
261
|
}, async (args) => {
|
|
291
262
|
const chapters = await client.getChapters(args.book_id, args.offset, args.count);
|
|
292
263
|
return {
|
|
293
|
-
content: [{ type: "text", text: JSON.stringify(chapters
|
|
264
|
+
content: [{ type: "text", text: JSON.stringify(chapters) }]
|
|
294
265
|
};
|
|
295
266
|
});
|
|
296
267
|
readTool("get_chapter", {
|
|
297
|
-
|
|
298
|
-
description: "Get details of a specific chapter",
|
|
268
|
+
description: "Get a chapter.",
|
|
299
269
|
inputSchema: {
|
|
300
|
-
id: z.coerce.number().min(1)
|
|
270
|
+
id: z.coerce.number().min(1)
|
|
301
271
|
}
|
|
302
272
|
}, async (args) => {
|
|
303
273
|
const chapter = await client.getChapter(args.id);
|
|
304
274
|
return {
|
|
305
|
-
content: [{ type: "text", text: JSON.stringify(chapter
|
|
275
|
+
content: [{ type: "text", text: JSON.stringify(chapter) }]
|
|
306
276
|
};
|
|
307
277
|
});
|
|
308
278
|
readTool("export_page", {
|
|
309
|
-
|
|
310
|
-
description: "Export a page in various formats (PDF/ZIP provide direct BookStack download URLs)",
|
|
279
|
+
description: "Export a page (PDF/ZIP return download URL).",
|
|
311
280
|
inputSchema: {
|
|
312
|
-
id: z.coerce.number().min(1)
|
|
313
|
-
format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"])
|
|
281
|
+
id: z.coerce.number().min(1),
|
|
282
|
+
format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"])
|
|
314
283
|
}
|
|
315
284
|
}, async (args) => {
|
|
316
285
|
const content = await client.exportPage(args.id, args.format);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const format = args.format.toUpperCase();
|
|
320
|
-
return {
|
|
321
|
-
content: [{
|
|
322
|
-
type: "text",
|
|
323
|
-
text: `✅ **${format} Export Ready**\n\n` +
|
|
324
|
-
`📄 **Page:** ${content.page_name}\n` +
|
|
325
|
-
`📚 **Book:** ${content.book_name}\n` +
|
|
326
|
-
`📁 **File:** ${content.filename}\n\n` +
|
|
327
|
-
`🚀 **Direct Download Link:**\n${content.download_url}\n\n` +
|
|
328
|
-
`ℹ️ **Note:** ${content.note}`
|
|
329
|
-
}]
|
|
330
|
-
};
|
|
286
|
+
if (typeof content === 'object' && content.download_url) {
|
|
287
|
+
return { content: [{ type: "text", text: JSON.stringify(content) }] };
|
|
331
288
|
}
|
|
332
|
-
|
|
333
|
-
const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
|
289
|
+
const text = typeof content === 'string' ? content : JSON.stringify(content);
|
|
334
290
|
return {
|
|
335
291
|
content: [{ type: "text", text }]
|
|
336
292
|
};
|
|
337
293
|
});
|
|
338
294
|
readTool("export_book", {
|
|
339
|
-
|
|
340
|
-
description: "Export an entire book in various formats",
|
|
295
|
+
description: "Export a book.",
|
|
341
296
|
inputSchema: {
|
|
342
|
-
id: z.coerce.number().min(1)
|
|
343
|
-
format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"])
|
|
297
|
+
id: z.coerce.number().min(1),
|
|
298
|
+
format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"])
|
|
344
299
|
}
|
|
345
300
|
}, async (args) => {
|
|
346
301
|
const content = await client.exportBook(args.id, args.format);
|
|
347
302
|
if (typeof content === 'object' && content.download_url) {
|
|
348
|
-
|
|
349
|
-
return {
|
|
350
|
-
content: [{
|
|
351
|
-
type: "text",
|
|
352
|
-
text: `✅ **${format} Book Export Ready**\n\n` +
|
|
353
|
-
`📚 **Book:** ${content.book_name}\n` +
|
|
354
|
-
`📁 **File:** ${content.filename}\n\n` +
|
|
355
|
-
`🚀 **Direct Download Link:**\n${content.download_url}\n\n` +
|
|
356
|
-
`ℹ️ **Note:** ${content.note}`
|
|
357
|
-
}]
|
|
358
|
-
};
|
|
303
|
+
return { content: [{ type: "text", text: JSON.stringify(content) }] };
|
|
359
304
|
}
|
|
360
|
-
const text = typeof content === 'string' ? content : JSON.stringify(content
|
|
305
|
+
const text = typeof content === 'string' ? content : JSON.stringify(content);
|
|
361
306
|
return {
|
|
362
307
|
content: [{ type: "text", text }]
|
|
363
308
|
};
|
|
364
309
|
});
|
|
365
310
|
readTool("export_chapter", {
|
|
366
|
-
|
|
367
|
-
description: "Export a chapter in various formats",
|
|
311
|
+
description: "Export a chapter.",
|
|
368
312
|
inputSchema: {
|
|
369
|
-
id: z.coerce.number().min(1)
|
|
370
|
-
format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"])
|
|
313
|
+
id: z.coerce.number().min(1),
|
|
314
|
+
format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"])
|
|
371
315
|
}
|
|
372
316
|
}, async (args) => {
|
|
373
317
|
const content = await client.exportChapter(args.id, args.format);
|
|
374
318
|
if (typeof content === 'object' && content.download_url) {
|
|
375
|
-
|
|
376
|
-
return {
|
|
377
|
-
content: [{
|
|
378
|
-
type: "text",
|
|
379
|
-
text: `✅ **${format} Chapter Export Ready**\n\n` +
|
|
380
|
-
`📖 **Chapter:** ${content.chapter_name}\n` +
|
|
381
|
-
`📚 **Book:** ${content.book_name}\n` +
|
|
382
|
-
`📁 **File:** ${content.filename}\n\n` +
|
|
383
|
-
`🚀 **Direct Download Link:**\n${content.download_url}\n\n` +
|
|
384
|
-
`ℹ️ **Note:** ${content.note}`
|
|
385
|
-
}]
|
|
386
|
-
};
|
|
319
|
+
return { content: [{ type: "text", text: JSON.stringify(content) }] };
|
|
387
320
|
}
|
|
388
|
-
const text = typeof content === 'string' ? content : JSON.stringify(content
|
|
321
|
+
const text = typeof content === 'string' ? content : JSON.stringify(content);
|
|
389
322
|
return {
|
|
390
323
|
content: [{ type: "text", text }]
|
|
391
324
|
};
|
|
392
325
|
});
|
|
393
326
|
readTool("get_recent_changes", {
|
|
394
|
-
|
|
395
|
-
description: "Get recently updated content with contextual previews and change descriptions",
|
|
327
|
+
description: "List content updated in the last N days.",
|
|
396
328
|
inputSchema: {
|
|
397
|
-
type: z.enum(["all", "page", "book", "chapter"]).default("all")
|
|
398
|
-
limit: z.coerce.number().max(100).default(20)
|
|
399
|
-
days: z.coerce.number().default(30)
|
|
329
|
+
type: z.enum(["all", "page", "book", "chapter"]).default("all"),
|
|
330
|
+
limit: z.coerce.number().max(100).default(20),
|
|
331
|
+
days: z.coerce.number().default(30)
|
|
400
332
|
}
|
|
401
333
|
}, async (args) => {
|
|
402
334
|
const changes = await client.getRecentChanges({
|
|
@@ -405,17 +337,16 @@ function registerTools(server, client, config) {
|
|
|
405
337
|
days: args.days
|
|
406
338
|
});
|
|
407
339
|
return {
|
|
408
|
-
content: [{ type: "text", text: JSON.stringify(changes
|
|
340
|
+
content: [{ type: "text", text: JSON.stringify(changes) }]
|
|
409
341
|
};
|
|
410
342
|
});
|
|
411
343
|
readTool("get_shelves", {
|
|
412
|
-
|
|
413
|
-
description: "List available book shelves (collections) with filtering and sorting",
|
|
344
|
+
description: "List shelves (book collections).",
|
|
414
345
|
inputSchema: {
|
|
415
|
-
offset: z.coerce.number().default(0)
|
|
416
|
-
count: z.coerce.number().max(500).default(50)
|
|
417
|
-
sort: z.string().optional()
|
|
418
|
-
filter: z.record(z.any()).optional()
|
|
346
|
+
offset: z.coerce.number().default(0),
|
|
347
|
+
count: z.coerce.number().max(500).default(50),
|
|
348
|
+
sort: z.string().optional(),
|
|
349
|
+
filter: z.record(z.any()).optional()
|
|
419
350
|
}
|
|
420
351
|
}, async (args) => {
|
|
421
352
|
const shelves = await client.getShelves({
|
|
@@ -425,29 +356,27 @@ function registerTools(server, client, config) {
|
|
|
425
356
|
filter: args.filter
|
|
426
357
|
});
|
|
427
358
|
return {
|
|
428
|
-
content: [{ type: "text", text: JSON.stringify(shelves
|
|
359
|
+
content: [{ type: "text", text: JSON.stringify(shelves) }]
|
|
429
360
|
};
|
|
430
361
|
});
|
|
431
362
|
readTool("get_shelf", {
|
|
432
|
-
|
|
433
|
-
description: "Get details of a specific book shelf including all books",
|
|
363
|
+
description: "Get a shelf including its books.",
|
|
434
364
|
inputSchema: {
|
|
435
|
-
id: z.coerce.number().min(1)
|
|
365
|
+
id: z.coerce.number().min(1)
|
|
436
366
|
}
|
|
437
367
|
}, async (args) => {
|
|
438
368
|
const shelf = await client.getShelf(args.id);
|
|
439
369
|
return {
|
|
440
|
-
content: [{ type: "text", text: JSON.stringify(shelf
|
|
370
|
+
content: [{ type: "text", text: JSON.stringify(shelf) }]
|
|
441
371
|
};
|
|
442
372
|
});
|
|
443
373
|
readTool("get_attachments", {
|
|
444
|
-
|
|
445
|
-
description: "List attachments (files and links) with filtering and sorting",
|
|
374
|
+
description: "List attachments (files and links).",
|
|
446
375
|
inputSchema: {
|
|
447
|
-
offset: z.coerce.number().default(0)
|
|
448
|
-
count: z.coerce.number().max(500).default(50)
|
|
449
|
-
sort: z.string().optional()
|
|
450
|
-
filter: z.record(z.any()).optional()
|
|
376
|
+
offset: z.coerce.number().default(0),
|
|
377
|
+
count: z.coerce.number().max(500).default(50),
|
|
378
|
+
sort: z.string().optional(),
|
|
379
|
+
filter: z.record(z.any()).optional()
|
|
451
380
|
}
|
|
452
381
|
}, async (args) => {
|
|
453
382
|
const attachments = await client.getAttachments({
|
|
@@ -457,29 +386,27 @@ function registerTools(server, client, config) {
|
|
|
457
386
|
filter: args.filter
|
|
458
387
|
});
|
|
459
388
|
return {
|
|
460
|
-
content: [{ type: "text", text: JSON.stringify(attachments
|
|
389
|
+
content: [{ type: "text", text: JSON.stringify(attachments) }]
|
|
461
390
|
};
|
|
462
391
|
});
|
|
463
392
|
readTool("get_attachment", {
|
|
464
|
-
|
|
465
|
-
description: "Get details of a specific attachment including download links",
|
|
393
|
+
description: "Get an attachment with download_url.",
|
|
466
394
|
inputSchema: {
|
|
467
|
-
id: z.coerce.number().min(1)
|
|
395
|
+
id: z.coerce.number().min(1)
|
|
468
396
|
}
|
|
469
397
|
}, async (args) => {
|
|
470
398
|
const attachment = await client.getAttachment(args.id);
|
|
471
399
|
return {
|
|
472
|
-
content: [{ type: "text", text: JSON.stringify(attachment
|
|
400
|
+
content: [{ type: "text", text: JSON.stringify(attachment) }]
|
|
473
401
|
};
|
|
474
402
|
});
|
|
475
403
|
readTool("get_comments", {
|
|
476
|
-
|
|
477
|
-
description: "List comments, optionally filtered to a single page. Requires BookStack v25.11+.",
|
|
404
|
+
description: "List comments (optional page_id). BookStack v25.11+.",
|
|
478
405
|
inputSchema: {
|
|
479
|
-
page_id: z.coerce.number().optional()
|
|
480
|
-
offset: z.coerce.number().default(0)
|
|
481
|
-
count: z.coerce.number().max(500).default(50)
|
|
482
|
-
sort: z.string().optional()
|
|
406
|
+
page_id: z.coerce.number().optional(),
|
|
407
|
+
offset: z.coerce.number().default(0),
|
|
408
|
+
count: z.coerce.number().max(500).default(50),
|
|
409
|
+
sort: z.string().optional()
|
|
483
410
|
}
|
|
484
411
|
}, async (args) => {
|
|
485
412
|
const comments = await client.getComments({
|
|
@@ -489,28 +416,54 @@ function registerTools(server, client, config) {
|
|
|
489
416
|
sort: args.sort
|
|
490
417
|
});
|
|
491
418
|
return {
|
|
492
|
-
content: [{ type: "text", text: JSON.stringify(comments
|
|
419
|
+
content: [{ type: "text", text: JSON.stringify(comments) }]
|
|
493
420
|
};
|
|
494
421
|
});
|
|
495
422
|
readTool("get_comment", {
|
|
496
|
-
|
|
497
|
-
description: "Get a single comment by ID. Requires BookStack v25.11+.",
|
|
423
|
+
description: "Get a comment. BookStack v25.11+.",
|
|
498
424
|
inputSchema: {
|
|
499
|
-
id: z.coerce.number().min(1)
|
|
425
|
+
id: z.coerce.number().min(1)
|
|
500
426
|
}
|
|
501
427
|
}, async (args) => {
|
|
502
428
|
const comment = await client.getComment(args.id);
|
|
503
429
|
return {
|
|
504
|
-
content: [{ type: "text", text: JSON.stringify(comment
|
|
430
|
+
content: [{ type: "text", text: JSON.stringify(comment) }]
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
readTool("find_users", {
|
|
434
|
+
description: "List users; filter by name/email/slug (partial match). Resolves names to numeric user IDs for {created_by:X}/{updated_by:X}/{owned_by:X} search filters. Requires admin token.",
|
|
435
|
+
inputSchema: {
|
|
436
|
+
name: z.string().optional(),
|
|
437
|
+
email: z.string().optional(),
|
|
438
|
+
slug: z.string().optional(),
|
|
439
|
+
offset: z.coerce.number().default(0),
|
|
440
|
+
count: z.coerce.number().max(500).default(50),
|
|
441
|
+
sort: z.string().optional()
|
|
442
|
+
}
|
|
443
|
+
}, async (args) => {
|
|
444
|
+
const filter = {};
|
|
445
|
+
if (args.name)
|
|
446
|
+
filter.name = args.name;
|
|
447
|
+
if (args.email)
|
|
448
|
+
filter.email = args.email;
|
|
449
|
+
if (args.slug)
|
|
450
|
+
filter.slug = args.slug;
|
|
451
|
+
const users = await client.getUsers({
|
|
452
|
+
offset: args.offset,
|
|
453
|
+
count: args.count,
|
|
454
|
+
sort: args.sort,
|
|
455
|
+
filter: Object.keys(filter).length ? filter : undefined
|
|
456
|
+
});
|
|
457
|
+
return {
|
|
458
|
+
content: [{ type: "text", text: JSON.stringify(users) }]
|
|
505
459
|
};
|
|
506
460
|
});
|
|
507
461
|
readTool("get_recycle_bin", {
|
|
508
|
-
|
|
509
|
-
description: "List items in the recycle bin (deleted books, chapters, pages, shelves). Requires admin permissions on the API token.",
|
|
462
|
+
description: "List recycle-bin items. Admin token required.",
|
|
510
463
|
inputSchema: {
|
|
511
|
-
offset: z.coerce.number().default(0)
|
|
512
|
-
count: z.coerce.number().max(500).default(50)
|
|
513
|
-
sort: z.string().optional()
|
|
464
|
+
offset: z.coerce.number().default(0),
|
|
465
|
+
count: z.coerce.number().max(500).default(50),
|
|
466
|
+
sort: z.string().optional()
|
|
514
467
|
}
|
|
515
468
|
}, async (args) => {
|
|
516
469
|
const items = await client.getRecycleBin({
|
|
@@ -519,13 +472,12 @@ function registerTools(server, client, config) {
|
|
|
519
472
|
sort: args.sort
|
|
520
473
|
});
|
|
521
474
|
return {
|
|
522
|
-
content: [{ type: "text", text: JSON.stringify(items
|
|
475
|
+
content: [{ type: "text", text: JSON.stringify(items) }]
|
|
523
476
|
};
|
|
524
477
|
});
|
|
525
478
|
// Register write tools if enabled
|
|
526
479
|
if (config.enableWrite) {
|
|
527
480
|
writeTool("create_book", {
|
|
528
|
-
title: "Create Book",
|
|
529
481
|
description: "Create a new book in BookStack",
|
|
530
482
|
inputSchema: {
|
|
531
483
|
name: z.string().describe("Book name"),
|
|
@@ -542,11 +494,10 @@ function registerTools(server, client, config) {
|
|
|
542
494
|
tags: args.tags
|
|
543
495
|
});
|
|
544
496
|
return {
|
|
545
|
-
content: [{ type: "text", text: JSON.stringify(book
|
|
497
|
+
content: [{ type: "text", text: JSON.stringify(book) }]
|
|
546
498
|
};
|
|
547
499
|
});
|
|
548
500
|
writeTool("create_chapter", {
|
|
549
|
-
title: "Create Chapter",
|
|
550
501
|
description: "Create a new chapter within a book",
|
|
551
502
|
inputSchema: {
|
|
552
503
|
book_id: z.coerce.number().min(1).describe("Book ID where the chapter will be created"),
|
|
@@ -565,11 +516,10 @@ function registerTools(server, client, config) {
|
|
|
565
516
|
tags: args.tags
|
|
566
517
|
});
|
|
567
518
|
return {
|
|
568
|
-
content: [{ type: "text", text: JSON.stringify(chapter
|
|
519
|
+
content: [{ type: "text", text: JSON.stringify(chapter) }]
|
|
569
520
|
};
|
|
570
521
|
});
|
|
571
522
|
writeTool("create_page", {
|
|
572
|
-
title: "Create Page",
|
|
573
523
|
description: "Create a new page in BookStack",
|
|
574
524
|
inputSchema: {
|
|
575
525
|
name: z.string().describe("Page name"),
|
|
@@ -587,14 +537,13 @@ function registerTools(server, client, config) {
|
|
|
587
537
|
markdown: args.markdown
|
|
588
538
|
});
|
|
589
539
|
return {
|
|
590
|
-
content: [{ type: "text", text: JSON.stringify(page
|
|
540
|
+
content: [{ type: "text", text: JSON.stringify(page) }]
|
|
591
541
|
};
|
|
592
542
|
});
|
|
593
543
|
writeTool("update_page", {
|
|
594
|
-
title: "Update Page",
|
|
595
544
|
description: "Update an existing page. Pass book_id (and optionally chapter_id) to move the page to a different location.",
|
|
596
545
|
inputSchema: {
|
|
597
|
-
id: z.coerce.number().min(1)
|
|
546
|
+
id: z.coerce.number().min(1),
|
|
598
547
|
name: z.string().optional().describe("Optional: New page name"),
|
|
599
548
|
html: z.string().optional().describe("Optional: New HTML content"),
|
|
600
549
|
markdown: z.string().optional().describe("Optional: New Markdown content"),
|
|
@@ -610,11 +559,10 @@ function registerTools(server, client, config) {
|
|
|
610
559
|
chapter_id: args.chapter_id
|
|
611
560
|
});
|
|
612
561
|
return {
|
|
613
|
-
content: [{ type: "text", text: JSON.stringify(page
|
|
562
|
+
content: [{ type: "text", text: JSON.stringify(page) }]
|
|
614
563
|
};
|
|
615
564
|
});
|
|
616
565
|
writeTool("create_shelf", {
|
|
617
|
-
title: "Create Shelf",
|
|
618
566
|
description: "Create a new book shelf (collection)",
|
|
619
567
|
inputSchema: {
|
|
620
568
|
name: z.string().describe("Shelf name"),
|
|
@@ -633,14 +581,13 @@ function registerTools(server, client, config) {
|
|
|
633
581
|
tags: args.tags
|
|
634
582
|
});
|
|
635
583
|
return {
|
|
636
|
-
content: [{ type: "text", text: JSON.stringify(shelf
|
|
584
|
+
content: [{ type: "text", text: JSON.stringify(shelf) }]
|
|
637
585
|
};
|
|
638
586
|
});
|
|
639
587
|
writeTool("update_shelf", {
|
|
640
|
-
title: "Update Shelf",
|
|
641
588
|
description: "Update an existing book shelf",
|
|
642
589
|
inputSchema: {
|
|
643
|
-
id: z.coerce.number().min(1)
|
|
590
|
+
id: z.coerce.number().min(1),
|
|
644
591
|
name: z.string().optional().describe("New shelf name"),
|
|
645
592
|
description: z.string().optional().describe("New shelf description"),
|
|
646
593
|
books: z.array(z.coerce.number()).optional().describe("Array of book IDs"),
|
|
@@ -657,23 +604,21 @@ function registerTools(server, client, config) {
|
|
|
657
604
|
tags: args.tags
|
|
658
605
|
});
|
|
659
606
|
return {
|
|
660
|
-
content: [{ type: "text", text: JSON.stringify(shelf
|
|
607
|
+
content: [{ type: "text", text: JSON.stringify(shelf) }]
|
|
661
608
|
};
|
|
662
609
|
});
|
|
663
610
|
writeTool("delete_shelf", {
|
|
664
|
-
title: "Delete Shelf",
|
|
665
611
|
description: "Delete a book shelf (collection)",
|
|
666
612
|
inputSchema: {
|
|
667
|
-
id: z.coerce.number().min(1)
|
|
613
|
+
id: z.coerce.number().min(1)
|
|
668
614
|
}
|
|
669
615
|
}, async (args) => {
|
|
670
616
|
const result = await client.deleteShelf(args.id);
|
|
671
617
|
return {
|
|
672
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
618
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
673
619
|
};
|
|
674
620
|
});
|
|
675
621
|
writeTool("create_attachment", {
|
|
676
|
-
title: "Create Attachment",
|
|
677
622
|
description: "Create a new link attachment to a page",
|
|
678
623
|
inputSchema: {
|
|
679
624
|
name: z.string().describe("Attachment name"),
|
|
@@ -687,14 +632,13 @@ function registerTools(server, client, config) {
|
|
|
687
632
|
link: args.link
|
|
688
633
|
});
|
|
689
634
|
return {
|
|
690
|
-
content: [{ type: "text", text: JSON.stringify(attachment
|
|
635
|
+
content: [{ type: "text", text: JSON.stringify(attachment) }]
|
|
691
636
|
};
|
|
692
637
|
});
|
|
693
638
|
writeTool("update_attachment", {
|
|
694
|
-
title: "Update Attachment",
|
|
695
639
|
description: "Update an existing attachment",
|
|
696
640
|
inputSchema: {
|
|
697
|
-
id: z.coerce.number().min(1)
|
|
641
|
+
id: z.coerce.number().min(1),
|
|
698
642
|
name: z.string().optional().describe("New attachment name"),
|
|
699
643
|
link: z.string().optional().describe("New URL for link attachment"),
|
|
700
644
|
uploaded_to: z.coerce.number().optional().describe("Move attachment to different page")
|
|
@@ -706,59 +650,54 @@ function registerTools(server, client, config) {
|
|
|
706
650
|
uploaded_to: args.uploaded_to
|
|
707
651
|
});
|
|
708
652
|
return {
|
|
709
|
-
content: [{ type: "text", text: JSON.stringify(attachment
|
|
653
|
+
content: [{ type: "text", text: JSON.stringify(attachment) }]
|
|
710
654
|
};
|
|
711
655
|
});
|
|
712
656
|
writeTool("delete_attachment", {
|
|
713
|
-
title: "Delete Attachment",
|
|
714
657
|
description: "Delete an attachment",
|
|
715
658
|
inputSchema: {
|
|
716
|
-
id: z.coerce.number().min(1)
|
|
659
|
+
id: z.coerce.number().min(1)
|
|
717
660
|
}
|
|
718
661
|
}, async (args) => {
|
|
719
662
|
const result = await client.deleteAttachment(args.id);
|
|
720
663
|
return {
|
|
721
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
664
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
722
665
|
};
|
|
723
666
|
});
|
|
724
667
|
writeTool("delete_book", {
|
|
725
|
-
title: "Delete Book",
|
|
726
668
|
description: "Delete a book. Goes to the recycle bin and can be restored from there.",
|
|
727
669
|
inputSchema: {
|
|
728
|
-
id: z.coerce.number().min(1)
|
|
670
|
+
id: z.coerce.number().min(1)
|
|
729
671
|
}
|
|
730
672
|
}, async (args) => {
|
|
731
673
|
const result = await client.deleteBook(args.id);
|
|
732
674
|
return {
|
|
733
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
675
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
734
676
|
};
|
|
735
677
|
});
|
|
736
678
|
writeTool("delete_chapter", {
|
|
737
|
-
title: "Delete Chapter",
|
|
738
679
|
description: "Delete a chapter. Goes to the recycle bin and can be restored from there.",
|
|
739
680
|
inputSchema: {
|
|
740
|
-
id: z.coerce.number().min(1)
|
|
681
|
+
id: z.coerce.number().min(1)
|
|
741
682
|
}
|
|
742
683
|
}, async (args) => {
|
|
743
684
|
const result = await client.deleteChapter(args.id);
|
|
744
685
|
return {
|
|
745
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
686
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
746
687
|
};
|
|
747
688
|
});
|
|
748
689
|
writeTool("delete_page", {
|
|
749
|
-
title: "Delete Page",
|
|
750
690
|
description: "Delete a page. Goes to the recycle bin and can be restored from there.",
|
|
751
691
|
inputSchema: {
|
|
752
|
-
id: z.coerce.number().min(1)
|
|
692
|
+
id: z.coerce.number().min(1)
|
|
753
693
|
}
|
|
754
694
|
}, async (args) => {
|
|
755
695
|
const result = await client.deletePage(args.id);
|
|
756
696
|
return {
|
|
757
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
697
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
758
698
|
};
|
|
759
699
|
});
|
|
760
700
|
writeTool("create_comment", {
|
|
761
|
-
title: "Create Comment",
|
|
762
701
|
description: "Add a comment to a page. Pass parent_id to reply to an existing comment. Requires BookStack v25.11+.",
|
|
763
702
|
inputSchema: {
|
|
764
703
|
page_id: z.coerce.number().min(1).describe("Page ID to comment on"),
|
|
@@ -774,14 +713,13 @@ function registerTools(server, client, config) {
|
|
|
774
713
|
content_ref: args.content_ref
|
|
775
714
|
});
|
|
776
715
|
return {
|
|
777
|
-
content: [{ type: "text", text: JSON.stringify(comment
|
|
716
|
+
content: [{ type: "text", text: JSON.stringify(comment) }]
|
|
778
717
|
};
|
|
779
718
|
});
|
|
780
719
|
writeTool("update_comment", {
|
|
781
|
-
title: "Update Comment",
|
|
782
720
|
description: "Edit a comment's body or archive/unarchive it. Requires BookStack v25.11+.",
|
|
783
721
|
inputSchema: {
|
|
784
|
-
id: z.coerce.number().min(1)
|
|
722
|
+
id: z.coerce.number().min(1),
|
|
785
723
|
html: z.string().optional().describe("Optional: new HTML body"),
|
|
786
724
|
archived: z.boolean().optional().describe("Optional: archive (true) or unarchive (false) the comment")
|
|
787
725
|
}
|
|
@@ -791,43 +729,40 @@ function registerTools(server, client, config) {
|
|
|
791
729
|
archived: args.archived
|
|
792
730
|
});
|
|
793
731
|
return {
|
|
794
|
-
content: [{ type: "text", text: JSON.stringify(comment
|
|
732
|
+
content: [{ type: "text", text: JSON.stringify(comment) }]
|
|
795
733
|
};
|
|
796
734
|
});
|
|
797
735
|
writeTool("delete_comment", {
|
|
798
|
-
title: "Delete Comment",
|
|
799
736
|
description: "Delete a comment. Requires BookStack v25.11+.",
|
|
800
737
|
inputSchema: {
|
|
801
|
-
id: z.coerce.number().min(1)
|
|
738
|
+
id: z.coerce.number().min(1)
|
|
802
739
|
}
|
|
803
740
|
}, async (args) => {
|
|
804
741
|
const result = await client.deleteComment(args.id);
|
|
805
742
|
return {
|
|
806
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
743
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
807
744
|
};
|
|
808
745
|
});
|
|
809
746
|
writeTool("restore_deleted", {
|
|
810
|
-
title: "Restore from Recycle Bin",
|
|
811
747
|
description: "Restore a deleted item from the recycle bin. Use the deletion ID from get_recycle_bin (not the original entity ID). Requires admin permissions.",
|
|
812
748
|
inputSchema: {
|
|
813
|
-
deletion_id: z.coerce.number().min(1)
|
|
749
|
+
deletion_id: z.coerce.number().min(1)
|
|
814
750
|
}
|
|
815
751
|
}, async (args) => {
|
|
816
752
|
const result = await client.restoreFromRecycleBin(args.deletion_id);
|
|
817
753
|
return {
|
|
818
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
754
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
819
755
|
};
|
|
820
756
|
});
|
|
821
757
|
writeTool("permanently_delete", {
|
|
822
|
-
title: "Permanently Delete from Recycle Bin",
|
|
823
758
|
description: "PERMANENTLY destroys a deleted item — this cannot be undone. Use the deletion ID from get_recycle_bin. Requires admin permissions.",
|
|
824
759
|
inputSchema: {
|
|
825
|
-
deletion_id: z.coerce.number().min(1)
|
|
760
|
+
deletion_id: z.coerce.number().min(1)
|
|
826
761
|
}
|
|
827
762
|
}, async (args) => {
|
|
828
763
|
const result = await client.destroyFromRecycleBin(args.deletion_id);
|
|
829
764
|
return {
|
|
830
|
-
content: [{ type: "text", text: JSON.stringify(result
|
|
765
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
831
766
|
};
|
|
832
767
|
});
|
|
833
768
|
}
|