export_chapter
Export BookStack chapters in HTML, PDF, Markdown, plaintext, or ZIP formats by specifying the chapter ID and desired format for documentation sharing or archiving.
Instructions
Export a chapter in various formats
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Chapter ID | |
| format | Yes | Export format |
Implementation Reference
- src/bookstack-client.ts:504-540 (handler)The actual logic for exporting a chapter. Handles binary formats by constructing a URL and text formats by fetching 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') { // First fetch the chapter data to get slugs const chapter = await this.getChapter(id); const book = await this.getBook(chapter.book_id); // Construct the correct web URL with both book and chapter slugs const directUrl = `${this.baseUrl}/books/${book.slug}/chapter/${chapter.slug}/export/${format}`; const filename = `${chapter.slug}.${format}`; const contentType = format === 'pdf' ? 'application/pdf' : 'application/zip'; return { format: format, filename: filename, download_url: directUrl, content_type: contentType, export_success: true, chapter_id: id, chapter_name: chapter.name, 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(`/chapters/${id}/export/${format}`); return response.data; } async getRecentChanges(options?: { type?: 'all' | 'page' | 'book' | 'chapter'; limit?: number; days?: number; }): Promise<any> { const limit = Math.min(options?.limit || 20, 100); - src/index.ts:303-330 (registration)Registration of the export_chapter tool in the MCP server instance.
server.registerTool( "export_chapter", { title: "Export Chapter", description: "Export a chapter in various formats", inputSchema: { id: z.coerce.number().min(1).describe("Chapter ID"), format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"]).describe("Export format") } }, async (args) => { const content = await client.exportChapter(args.id, args.format); if (typeof content === 'object' && content.download_url) { const format = args.format.toUpperCase(); return { content: [{ type: "text", text: `β **${format} Chapter Export Ready**\n\n` + `π **Chapter:** ${content.chapter_name}\n` + `π **Book:** ${content.book_name}\n` + `π **File:** ${content.filename}\n\n` + `π **Direct Download Link:**\n${content.download_url}\n\n` + `βΉοΈ **Note:** ${content.note}` }] }; } - src/index.ts:308-311 (schema)Input validation schema for the export_chapter tool.
inputSchema: { id: z.coerce.number().min(1).describe("Chapter ID"), format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"]).describe("Export format") }