export_chapter
Export BookStack wiki chapters to HTML, PDF, plaintext, or markdown formats for content sharing and documentation purposes.
Instructions
Export a chapter in various formats
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | Yes | Export format | |
| id | Yes | Chapter ID |
Implementation Reference
- src/tools/content-tools.ts:649-668 (handler)The handler logic within handleContentTool function that processes the 'export_chapter' tool call: parses id and format from args, then calls the corresponding BookStackClient exportChapter* method based on format and returns the result (notes PDF limitation).case "export_chapter": { const id = parseInteger(args.id); const format = args.format; switch (format) { case "html": const html = await client.exportChapterHtml(id); return html; case "pdf": return "PDF export is binary data - use API directly for file download"; case "plaintext": const text = await client.exportChapterPlainText(id); return text; case "markdown": const markdown = await client.exportChapterMarkdown(id); return markdown; default: throw new Error(`Unsupported export format: ${format}`); } }
- src/tools/content-tools.ts:277-292 (schema)Tool definition including name, description, and inputSchema for validating arguments: requires 'id' (number) and 'format' (enum: html, pdf, plaintext, markdown). This is returned in createContentTools for MCP list_tools.{ name: "export_chapter", description: "Export a chapter in various formats", inputSchema: { type: "object", properties: { id: { type: "number", description: "Chapter ID" }, format: { type: "string", enum: ["html", "pdf", "plaintext", "markdown"], description: "Export format", }, }, required: ["id", "format"], }, },
- src/index.ts:76-126 (registration)Registers 'export_chapter' in the list of content tools for dispatch: if name matches, calls handleContentTool in the MCP call_tool request handler.const contentToolNames = [ "list_books", "get_book", "create_book", "update_book", "delete_book", "export_book", "list_chapters", "get_chapter", "create_chapter", "update_chapter", "delete_chapter", "export_chapter", "list_pages", "get_page", "create_page", "update_page", "delete_page", "export_page", "list_shelves", "get_shelf", "create_shelf", "update_shelf", "delete_shelf", ]; // Search and user tools const searchUserToolNames = [ "search_all", "list_users", "get_user", "create_user", "update_user", "delete_user", "list_roles", "get_role", "create_role", "update_role", "delete_role", "list_attachments", "get_attachment", "delete_attachment", "list_images", "get_image", "update_image", "delete_image", ]; if (contentToolNames.includes(name)) { result = await handleContentTool(name, args, bookStackClient); } else if (searchUserToolNames.includes(name)) {
- src/index.ts:56-59 (registration)Includes the 'export_chapter' tool (via createContentTools) in allTools array returned by MCP list_tools request handler.const allTools: Tool[] = [ ...createContentTools(bookStackClient), ...createSearchAndUserTools(bookStackClient), ];
- src/lib/bookstack-client.ts:170-199 (helper)Supporting helper methods in BookStackClient that perform the actual HTTP API requests to BookStack for exporting a chapter in HTML, PDF (Buffer), plain text, or Markdown formats.async exportChapterHtml(id: number): Promise<string> { const response: AxiosResponse<string> = await this.api.get( `/chapters/${id}/export/html` ); return response.data; } async exportChapterPdf(id: number): Promise<Buffer> { const response: AxiosResponse<Buffer> = await this.api.get( `/chapters/${id}/export/pdf`, { responseType: "arraybuffer", } ); return response.data; } async exportChapterPlainText(id: number): Promise<string> { const response: AxiosResponse<string> = await this.api.get( `/chapters/${id}/export/plaintext` ); return response.data; } async exportChapterMarkdown(id: number): Promise<string> { const response: AxiosResponse<string> = await this.api.get( `/chapters/${id}/export/markdown` ); return response.data; }