bookstack-mcp-server icon indicating copy to clipboard operation
bookstack-mcp-server copied to clipboard

uploading images / base 64 / json limitation

Open jsapede opened this issue 6 months ago • 0 comments

BookStack MCP Server — add support for file_path


Summary

bookstack-mcp-diff.patch

Root cause: the BookStack MCP server (pnocera/bookstack-mcp-server v1.0.0) serialized every API request as application/json — including image uploads and attachment file uploads. But BookStack's REST API requires multipart/form-data for those two endpoints (POST /api/image-gallery, POST /api/attachments, and their PUT equivalents). Every call to bookstack_images_create or bookstack_attachments_create would fail with a 500 or 422 error because the server received a JSON body but couldn't parse it as file content.

The fix — 5 source files modified:

File Change
src/api/client.ts Added uploadFile() — reads the file from the local filesystem (fs.readFile), builds a FormData multipart payload, and posts it with the correct Content-Type: multipart/form-data header
src/tools/images.ts Routes file_path parameter to uploadFile() instead of the JSON request(); also added the missing uploaded_to field
src/tools/attachments.ts Same routing — file_path bypasses JSON, goes straight to multipart
src/types.ts Added optional file_path field to CreateImageParams, UpdateImageParams, CreateAttachmentParams, UpdateAttachmentParams
src/validation/validator.ts Zod schemas updated: refine() now accepts file || file_path || link; image field made optional

Why it works now: when the caller provides file_path instead of base64 file, the server reads the file from disk and sends it as a proper multipart upload — exactly what BookStack's API expects. The image base64 path is still supported for small files; the MCP tool auto-selects the right method.


jsapede avatar May 27 '26 14:05 jsapede