Skip to main content
Glama
ttpears

BookStack MCP Server

by ttpears

Export Page

export_page

Export BookStack pages to HTML, PDF, markdown, plaintext, or ZIP formats for offline use, sharing, or backup purposes.

Instructions

Export a page in various formats (PDF/ZIP provide direct BookStack download URLs)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesPage ID
formatYesExport format

Implementation Reference

  • The `exportPage` method in `BookStackClient` handles exporting a page by either generating a web download link for binary formats (PDF, ZIP) or fetching the content via API for text formats (HTML, Markdown, Plaintext).
    async exportPage(id: number, format: 'html' | 'pdf' | 'markdown' | 'plaintext' | 'zip'): Promise<any> {
      try {
        // For binary formats (PDF, ZIP), return BookStack web URL using slugs
        if (format === 'pdf' || format === 'zip') {
          // First fetch the page data to get slugs
          const page = await this.getPage(id);
          const book = await this.getBook(page.book_id);
          
          // Construct the correct web URL with slugs
          const directUrl = `${this.baseUrl}/books/${book.slug}/page/${page.slug}/export/${format}`;
          const filename = `${page.slug}.${format}`;
          const contentType = format === 'pdf' ? 'application/pdf' : 'application/zip';
          
          return {
            format: format,
            filename: filename,
            download_url: directUrl,
            content_type: contentType,
            export_success: true,
            page_id: id,
            page_name: page.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."
          };
        } else {
          // For text formats, fetch the content via API
          console.error(`Exporting page ${id} as ${format}...`);
          const response = await this.client.get(`/pages/${id}/export/${format}`);
          console.error(`Export response status: ${response.status}`);
          
          // For text formats, validate and return as string
          if (!response.data) {
            throw new Error(`Empty ${format} content returned from BookStack API`);
          }
          
          console.error(`Text export length: ${response.data.length} characters`);
          return response.data;
        }
      } catch (error) {
        console.error(`Export error for page ${id}:`, error);
        throw new Error(`Failed to export page ${id} as ${format}: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/index.ts:232-267 (registration)
    Registration of the `export_page` tool in `src/index.ts`, which invokes `client.exportPage` and handles the output formatting for the MCP client.
    server.registerTool(
      "export_page",
      {
        title: "Export Page",
        description: "Export a page in various formats (PDF/ZIP provide direct BookStack download URLs)",
        inputSchema: {
          id: z.coerce.number().min(1).describe("Page ID"),
          format: z.enum(["html", "pdf", "markdown", "plaintext", "zip"]).describe("Export format")
        }
      },
      async (args) => {
        const content = await client.exportPage(args.id, args.format);
    
        // Handle binary formats with direct URLs
        if (typeof content === 'object' && content.download_url && content.direct_download) {
          const format = args.format.toUpperCase();
          return {
            content: [{
              type: "text",
              text: `✅ **${format} Export Ready**\n\n` +
                    `📄 **Page:** ${content.page_name}\n` +
                    `📚 **Book:** ${content.book_name}\n` +
                    `📁 **File:** ${content.filename}\n\n` +
                    `🚀 **Direct Download Link:**\n${content.download_url}\n\n` +
                    `â„šī¸  **Note:** ${content.note}`
            }]
          };
        }
    
        // Handle text formats
        const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
        return {
          content: [{ type: "text", text }]
        };
      }
    );
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 discloses that PDF/ZIP formats 'provide direct BookStack download URLs', which adds useful context about output behavior. However, it lacks details on permissions, rate limits, side effects, or what happens with other formats. For a tool with no annotations, this is minimal disclosure.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It front-loads the core action ('Export a page in various formats') and adds a clarifying note about specific formats. Every word earns its place, making it highly concise and well-structured.

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

Completeness3/5

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

Given 2 parameters with full schema coverage and no output schema, the description is adequate but has gaps. It covers the basic purpose and hints at format-specific behavior, but lacks details on permissions, error cases, or output structure. For a tool with no annotations and no output schema, it's minimally complete but could be more informative.

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%, so the schema fully documents both parameters (id and format with enum). The description adds marginal value by noting 'PDF/ZIP provide direct BookStack download URLs', which hints at format-specific behavior but doesn't explain parameter semantics beyond the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb 'Export' and resource 'a page', specifying it works with 'various formats'. It distinguishes from siblings like 'export_book' and 'export_chapter' by focusing on pages, but doesn't explicitly contrast with them. The purpose is specific and actionable.

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_chapter' is provided. The description mentions 'PDF/ZIP provide direct BookStack download URLs', which hints at behavioral differences, but doesn't give explicit usage context or prerequisites. It's left to the agent to infer based on tool names.

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