Export Book
export_bookExport an entire book from BookStack in HTML, PDF, Markdown, plain text, or ZIP format using the book ID.
Instructions
Export an entire book in various formats
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Book ID | |
| format | Yes | Export format |
Implementation Reference
- src/index.ts:279-299 (handler)Tool handler for 'export_book' that calls the BookStack client and formats the response.
async (args) => { const content = await client.exportBook(args.id, args.format); if (typeof content === 'object' && content.download_url) { const format = args.format.toUpperCase(); return { content: [{ type: "text", text: `â **${format} Book Export Ready**\n\n` + `đ **Book:** ${content.book_name}\n` + `đ **File:** ${content.filename}\n\n` + `đ **Direct Download Link:**\n${content.download_url}\n\n` + `âšī¸ **Note:** ${content.note}` }] }; } const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2); return { content: [{ type: "text", text }] }; - src/index.ts:269-278 (registration)Registration of 'export_book' tool with its schema definition.
server.registerTool( "export_book", { title: "Export Book", description: "Export an entire book in various formats", inputSchema: { id: z.coerce.number().min(1).describe("Book ID"), format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"]).describe("Export format") } }, - src/bookstack-client.ts:475-506 (handler)Implementation of exportBook logic in the BookStack client.
async exportBook(id: number, format: 'html' | 'pdf' | 'markdown' | 'plaintext' | 'zip'): Promise<any> { // For binary formats (PDF, ZIP), return BookStack web URL using slug if (format === 'pdf' || format === 'zip') { // First fetch the book data to get slug const book = await this.getBook(id); // Construct the correct web URL with slug const directUrl = `${this.baseUrl}/books/${book.slug}/export/${format}`; const filename = `${book.slug}.${format}`; const contentType = format === 'pdf' ? 'application/pdf' : 'application/zip'; return { format: format, filename: filename, download_url: directUrl, content_type: contentType, export_success: true, book_id: id, book_name: book.name, direct_download: true, note: "This is a direct link to BookStack's web export. You may need to be logged in to BookStack to access it." }; } // For text formats, fetch the content via API const response = await this.client.get(`/books/${id}/export/${format}`); return response.data; } async exportChapter(id: number, format: 'html' | 'pdf' | 'markdown' | 'plaintext' | 'zip'): Promise<any> { // For binary formats (PDF, ZIP), return BookStack web URL using slugs if (format === 'pdf' || format === 'zip') {