Skip to main content
Glama
ttpears

BookStack MCP Server

by ttpears

Export Chapter

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
NameRequiredDescriptionDefault
idYesChapter ID
formatYesExport format

Implementation Reference

  • 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}`
            }]
          };
        }
  • 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")
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'various formats' but doesn't disclose behavioral traits like whether this is a read-only operation, if it requires authentication, rate limits, or what happens during export (e.g., file creation, download). The description is minimal and lacks critical context for a mutation-like tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's front-loaded with the core action. However, it could be more informative without sacrificing brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that likely performs an export operation. It doesn't explain return values, error conditions, or behavioral aspects like side effects. For a tool with 2 parameters and potential complexity, this is inadequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear parameter documentation (id as Chapter ID, format as Export format with enum). The description adds no additional meaning beyond the schema, such as explaining format implications or id constraints. Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Export a chapter in various formats' clearly states the action (export) and resource (chapter), but it's vague about scope and doesn't differentiate from siblings like export_book or export_page. It doesn't specify what 'export' entails (e.g., file generation, download link).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like export_book or export_page. It doesn't mention prerequisites (e.g., needing chapter access) or exclusions (e.g., not for attachments). Usage is implied by the name but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ttpears/bookstack-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server