bookstack-mcp 3.5.0 → 5.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.
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
@@ -143,6 +144,17 @@ When binding to `0.0.0.0` (e.g. inside a container reachable from other services
143
144
 
144
145
  Restart LibreChat after config changes.
145
146
 
147
+ ### Remote hosting & Claude Connector (Docker + Entra OAuth)
148
+
149
+ A container image is published to `ghcr.io/ttpears/bookstack-mcp` (released `:X.Y.Z`/`:latest`,
150
+ plus per-PR preview tags `:branch-<slug>`). The server can run as a public **Claude Connector**
151
+ gated by Microsoft 365 / Entra ID login — users sign in, no API key or client credential to
152
+ paste; write tools are unlocked per session by an Entra app role.
153
+
154
+ See **[docs/SETUP.md](docs/SETUP.md)** for the full runbook: Entra app registration steps,
155
+ the environment-variable reference, internal LibreChat deployment, and the public OAuth
156
+ connector setup.
157
+
146
158
  ### Claude Code (CLI)
147
159
 
148
160
  The recommended path is the `ttpears/claude-plugins` marketplace, which ships this repo's plugin manifest (`.claude-plugin/plugin.json`):
@@ -214,13 +226,14 @@ Books and pages are also exposed as MCP resources, so clients that browse resour
214
226
 
215
227
  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.
216
228
 
229
+ > **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.
230
+
217
231
  ## Available Tools
218
232
 
219
233
  ### Read Operations (always available)
220
234
 
221
235
  | Tool | Description |
222
236
  |------|-------------|
223
- | `get_capabilities` | Server capabilities and configuration |
224
237
  | `search_content` | Search across all content with filtering |
225
238
  | `search_pages` | Search pages with optional book filtering |
226
239
  | `get_books` / `get_book` | List or get details of books |
@@ -102,23 +102,17 @@ export class BookStackClient {
102
102
  const encodedQuery = encodeURIComponent(query);
103
103
  return `${this.baseUrl}/search?term=${encodedQuery}`;
104
104
  }
105
- // 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.
106
109
  enhanceBookResponse(book) {
107
- const lastUpdated = this.formatDate(book.updated_at);
108
- const created = this.formatDate(book.created_at);
109
110
  return {
110
111
  ...book,
111
- url: this.generateBookUrl(book),
112
- direct_link: `[${book.name}](${this.generateBookUrl(book)})`,
113
- last_updated_friendly: lastUpdated,
114
- created_friendly: created,
115
- summary: book.description ? `${book.description.substring(0, 100)}${book.description.length > 100 ? '...' : ''}` : 'No description available',
116
- content_info: `Book created ${created}, last updated ${lastUpdated}`
112
+ url: this.generateBookUrl(book)
117
113
  };
118
114
  }
119
115
  async enhancePageResponse(page, options) {
120
- const lastUpdated = this.formatDate(page.updated_at);
121
- const created = this.formatDate(page.created_at);
122
116
  const url = await this.generatePageUrl(page);
123
117
  // Pick a single content format to return to avoid 3x duplication (html + markdown + text)
124
118
  const format = options?.format ?? 'markdown';
@@ -139,72 +133,41 @@ export class BookStackClient {
139
133
  return {
140
134
  ...pageMeta,
141
135
  url,
142
- direct_link: `[${page.name}](${url})`,
143
- last_updated_friendly: lastUpdated,
144
- created_friendly: created,
145
- content_info: `Page created ${created}, last updated ${lastUpdated}`,
146
136
  word_count: page.text ? page.text.split(' ').length : 0,
147
- location: `Book ID ${page.book_id}${page.chapter_id ? `, Chapter ID ${page.chapter_id}` : ''}`,
148
137
  content_format: format,
149
138
  content_total_chars: totalChars,
150
139
  content_offset: offset,
151
140
  content_returned_chars: slice.length,
152
141
  content_truncated: truncated,
153
142
  content_next_offset: truncated ? nextOffset : null,
154
- pagination_hint: truncated
155
- ? `Only ${nextOffset}/${totalChars} characters returned. Call get_page again with offset=${nextOffset} to continue, or pass a larger limit.`
156
- : undefined,
157
143
  content: slice
158
144
  };
159
145
  }
160
146
  async enhanceChapterResponse(chapter) {
161
- const lastUpdated = this.formatDate(chapter.updated_at);
162
- const created = this.formatDate(chapter.created_at);
163
147
  const url = await this.generateChapterUrl(chapter);
164
- return {
165
- ...chapter,
166
- url,
167
- direct_link: `[${chapter.name}](${url})`,
168
- last_updated_friendly: lastUpdated,
169
- created_friendly: created,
170
- summary: chapter.description ? `${chapter.description.substring(0, 100)}${chapter.description.length > 100 ? '...' : ''}` : 'No description available',
171
- content_info: `Chapter created ${created}, last updated ${lastUpdated}`,
172
- location: `In Book ID ${chapter.book_id}`
173
- };
148
+ return { ...chapter, url };
174
149
  }
175
150
  enhanceShelfResponse(shelf) {
176
- const lastUpdated = this.formatDate(shelf.updated_at);
177
- const created = this.formatDate(shelf.created_at);
178
- const bookCount = shelf.books?.length || 0;
179
151
  return {
180
152
  ...shelf,
181
153
  url: this.generateShelfUrl(shelf),
182
- direct_link: `[${shelf.name}](${this.generateShelfUrl(shelf)})`,
183
- last_updated_friendly: lastUpdated,
184
- created_friendly: created,
185
- summary: shelf.description ? `${shelf.description.substring(0, 100)}${shelf.description.length > 100 ? '...' : ''}` : 'No description available',
186
- content_info: `Shelf with ${bookCount} book${bookCount !== 1 ? 's' : ''}, created ${created}, last updated ${lastUpdated}`,
187
- book_count: bookCount,
188
- books: shelf.books?.map(book => this.enhanceBookResponse(book)),
189
- 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))
190
155
  };
191
156
  }
192
157
  async enhanceSearchResults(results, originalQuery) {
193
158
  const enhancedResults = await Promise.all(results.map(async (result) => {
194
159
  const url = await this.generateContentUrl(result);
195
- return {
196
- ...result,
197
- url,
198
- direct_link: `[${result.name}](${url})`,
199
- content_preview: result.preview_content?.content ? `${result.preview_content.content.substring(0, 150)}${result.preview_content.content.length > 150 ? '...' : ''}` : 'No preview available',
200
- content_type: result.type.charAt(0).toUpperCase() + result.type.slice(1),
201
- location_info: result.book_id ? `In book ID ${result.book_id}${result.chapter_id ? `, chapter ID ${result.chapter_id}` : ''}` : 'Location unknown'
202
- };
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;
203
166
  }));
204
167
  return {
205
168
  search_query: originalQuery,
206
169
  search_url: this.generateSearchUrl(originalQuery),
207
- summary: `Found ${results.length} results for "${originalQuery}"`,
170
+ total: results.length,
208
171
  results: enhancedResults
209
172
  };
210
173
  }
@@ -303,25 +266,15 @@ export class BookStackClient {
303
266
  };
304
267
  }
305
268
  async enhancePageListItem(page) {
306
- const lastUpdated = this.formatDate(page.updated_at);
307
- const created = this.formatDate(page.created_at);
308
269
  const url = await this.generatePageUrl(page);
309
- const preview = page.text
310
- ? `${page.text.substring(0, 200)}${page.text.length > 200 ? '...' : ''}`
311
- : 'No content preview available';
312
270
  // List responses from BookStack don't include html/markdown/text/raw_html, but strip
313
271
  // defensively and never embed full content here — use get_page for that.
314
272
  const { html: _h, markdown: _m, text: _t, raw_html: _r, ...pageMeta } = page;
315
- return {
316
- ...pageMeta,
317
- url,
318
- direct_link: `[${page.name}](${url})`,
319
- last_updated_friendly: lastUpdated,
320
- created_friendly: created,
321
- content_preview: preview,
322
- content_info: `Page created ${created}, last updated ${lastUpdated}`,
323
- location: `Book ID ${page.book_id}${page.chapter_id ? `, Chapter ID ${page.chapter_id}` : ''}`
324
- };
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;
325
278
  }
326
279
  async getPage(id, options) {
327
280
  const response = await this.client.get(`/pages/${id}`);
@@ -522,76 +475,24 @@ export class BookStackClient {
522
475
  };
523
476
  const response = await this.client.get('/search', { params });
524
477
  const results = response.data.data || response.data;
525
- // Enhance results with additional context
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.
526
480
  const enhancedResults = await Promise.all(results.map(async (result) => {
527
- let contextualInfo = '';
528
- let contentPreview = result.preview_content?.content || '';
529
- try {
530
- // Get additional context based on content type
531
- if (result.type === 'page' && result.id) {
532
- const fullPage = await this.client.get(`/pages/${result.id}`);
533
- const pageData = fullPage.data;
534
- contentPreview = pageData.text?.substring(0, 200) || contentPreview;
535
- contextualInfo = `Updated in book: ${pageData.book?.name || 'Unknown Book'}`;
536
- if (pageData.chapter) {
537
- contextualInfo += `, chapter: ${pageData.chapter.name}`;
538
- }
539
- }
540
- else if (result.type === 'book' && result.id) {
541
- const fullBook = await this.client.get(`/books/${result.id}`);
542
- const bookData = fullBook.data;
543
- contentPreview = bookData.description?.substring(0, 200) || 'No description available';
544
- contextualInfo = `Book with ${bookData.page_count || 0} pages`;
545
- }
546
- else if (result.type === 'chapter' && result.id) {
547
- const fullChapter = await this.client.get(`/chapters/${result.id}`);
548
- const chapterData = fullChapter.data;
549
- contentPreview = chapterData.description?.substring(0, 200) || 'No description available';
550
- contextualInfo = `Chapter in book: ${chapterData.book?.name || 'Unknown Book'}`;
551
- }
552
- }
553
- catch (error) {
554
- // If we can't get additional context, use what we have
555
- contextualInfo = `${result.type.charAt(0).toUpperCase() + result.type.slice(1)} content`;
556
- }
557
481
  const url = await this.generateContentUrl(result);
558
- return {
559
- ...result,
560
- url,
561
- direct_link: `[${result.name}](${url})`,
562
- content_preview: contentPreview ? `${contentPreview}${contentPreview.length >= 200 ? '...' : ''}` : 'No preview available',
563
- contextual_info: contextualInfo,
564
- last_updated: this.formatDate(result.updated_at || result.created_at || ''),
565
- change_summary: `${result.type === 'page' ? 'Page' : result.type === 'book' ? 'Book' : 'Chapter'} "${result.name}" was updated`
566
- };
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;
567
488
  }));
568
489
  return {
569
- search_query: `Recent changes in the last ${days} days (${type})`,
570
490
  date_threshold: dateFilter,
571
- search_url: this.generateSearchUrl(searchQuery),
572
- total_found: results.length,
573
- summary: `Found ${results.length} items updated in the last ${days} days${type !== 'all' ? ` (${type}s only)` : ''}`,
491
+ type,
492
+ total: results.length,
574
493
  results: enhancedResults
575
494
  };
576
495
  }
577
- formatDate(dateString) {
578
- if (!dateString)
579
- return 'Unknown date';
580
- const date = new Date(dateString);
581
- const now = new Date();
582
- const diffInHours = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60));
583
- if (diffInHours < 1)
584
- return 'Less than an hour ago';
585
- if (diffInHours < 24)
586
- return `${diffInHours} hours ago`;
587
- const diffInDays = Math.floor(diffInHours / 24);
588
- if (diffInDays < 7)
589
- return `${diffInDays} days ago`;
590
- const diffInWeeks = Math.floor(diffInDays / 7);
591
- if (diffInWeeks < 4)
592
- return `${diffInWeeks} weeks ago`;
593
- return date.toLocaleDateString();
594
- }
595
496
  // Shelves (Book Collections) Management
596
497
  async getShelves(options) {
597
498
  const params = {
@@ -648,8 +549,7 @@ export class BookStackClient {
648
549
  ...data,
649
550
  data: data.data.map((attachment) => ({
650
551
  ...attachment,
651
- page_url: `${this.baseUrl}/books/${Math.floor(attachment.uploaded_to / 1000)}/page/${attachment.uploaded_to}`,
652
- direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`
552
+ download_url: `${this.baseUrl}/attachments/${attachment.id}`
653
553
  }))
654
554
  };
655
555
  }
@@ -658,8 +558,6 @@ export class BookStackClient {
658
558
  const attachment = response.data;
659
559
  return {
660
560
  ...attachment,
661
- page_url: `${this.baseUrl}/books/${Math.floor(attachment.uploaded_to / 1000)}/page/${attachment.uploaded_to}`,
662
- direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`,
663
561
  download_url: `${this.baseUrl}/attachments/${attachment.id}`
664
562
  };
665
563
  }
@@ -671,8 +569,7 @@ export class BookStackClient {
671
569
  const attachment = response.data;
672
570
  return {
673
571
  ...attachment,
674
- page_url: `${this.baseUrl}/books/${Math.floor(attachment.uploaded_to / 1000)}/page/${attachment.uploaded_to}`,
675
- direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`
572
+ download_url: `${this.baseUrl}/attachments/${attachment.id}`
676
573
  };
677
574
  }
678
575
  async updateAttachment(id, data) {
@@ -683,8 +580,7 @@ export class BookStackClient {
683
580
  const attachment = response.data;
684
581
  return {
685
582
  ...attachment,
686
- page_url: `${this.baseUrl}/books/${Math.floor(attachment.uploaded_to / 1000)}/page/${attachment.uploaded_to}`,
687
- direct_link: `[${attachment.name}](${this.baseUrl}/attachments/${attachment.id})`
583
+ download_url: `${this.baseUrl}/attachments/${attachment.id}`
688
584
  };
689
585
  }
690
586
  async deleteAttachment(id) {