Skip to content

word_count is always 0 for WYSIWYG pages, even when content is returned #10

Description

@scocchiarella

Summary

get_page returns word_count: 0 for WYSIWYG-authored pages even when content is successfully returned (e.g. content_total_chars: 6393). This can mislead consumers into treating populated pages as empty stubs.

Steps to Reproduce

  1. Create a page using BookStack's WYSIWYG editor
  2. Ensure the API token's role has "Export Content" so the markdown fallback works
  3. Call get_page with default format (markdown)

Expected: word_count reflects actual content
Actual: word_count: 0 despite content_total_chars: 6393 and full content in the response

Root Cause

In enhancePageResponse (bookstack-client.js line 136):

word_count: page.text ? page.text.split(' ').length : 0

word_count is derived from page.text, but for WYSIWYG pages BookStack's API returns page.text as empty. The markdown fallback at line 287-291 populates pageData.markdown via the export endpoint, but never backfills page.text. So word_count stays 0.

Requesting format: "text" directly also returns empty content for WYSIWYG pages, confirming page.text is not populated by BookStack for these pages.

Suggested Fix

Derive word_count from whichever content was actually resolved:

word_count: page.text
  ? page.text.split(' ').length
  : fullContent
    ? fullContent.split(/\s+/).filter(Boolean).length
    : 0

Side note: Export Content permission

Separately, the WYSIWYG→markdown fallback requires the "Export Content" role permission, which isn't included in the default Viewer role. When missing, the fallback silently fails (caught error, logged to stderr) and returns empty content. This isn't a code bug — it's the correct BookStack permission model — but it might be worth documenting in the README since it's a common setup for read-only API tokens.

Environment

  • bookstack-mcp v5.1.0
  • BookStack hosted on PikaPod, WYSIWYG editor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions