Skip to main content
Glama

telegraph_export_page

Export Telegraph pages to Markdown or HTML format for backup, sharing, or content migration purposes.

Instructions

Export a Telegraph page to Markdown or HTML format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the Telegraph page
formatNoExport formatmarkdown

Implementation Reference

  • Handler function logic that executes the telegraph_export_page tool: parses input, fetches the page using telegraph.getPage, converts content to markdown or html, and returns structured JSON output.
    if (name === 'telegraph_export_page') {
      const input = ExportPageSchema.parse(args);
      const page = await telegraph.getPage(input.path, true);
    
      if (!page.content) {
        throw new Error('Page has no content');
      }
    
      const content = input.format === 'markdown'
        ? nodesToMarkdown(page.content)
        : nodesToHtml(page.content);
    
      return {
        content: [{
          type: 'text' as const,
          text: JSON.stringify({
            title: page.title,
            path: page.path,
            url: page.url,
            format: input.format,
            content,
          }, null, 2),
        }],
      };
    }
  • Zod schema defining input parameters for telegraph_export_page tool: path (required) and format (markdown or html).
    export const ExportPageSchema = z.object({
      path: z.string().describe('Path to the Telegraph page'),
      format: z.enum(['markdown', 'html']).default('markdown').describe('Export format'),
    });
  • Tool registration entry in exportTools array, including name, description, and JSON inputSchema.
    {
      name: 'telegraph_export_page',
      description: 'Export a Telegraph page to Markdown or HTML format',
      inputSchema: {
        type: 'object' as const,
        properties: {
          path: {
            type: 'string',
            description: 'Path to the Telegraph page',
          },
          format: {
            type: 'string',
            enum: ['markdown', 'html'],
            default: 'markdown',
            description: 'Export format',
          },
        },
        required: ['path'],
      },
    },
  • Helper function to convert Telegraph page nodes to Markdown format, used in the handler.
    function nodesToMarkdown(nodes: Node[]): string {
      let markdown = '';
    
      for (const node of nodes) {
        if (typeof node === 'string') {
          markdown += node;
        } else {
          markdown += nodeElementToMarkdown(node as NodeElement);
        }
      }
    
      return markdown;
    }
  • Helper function to convert individual Telegraph NodeElement to Markdown, supporting various tags.
    function nodeElementToMarkdown(node: NodeElement): string {
      const children = node.children ? nodesToMarkdown(node.children) : '';
    
      switch (node.tag) {
        case 'h3':
          return `\n# ${children}\n`;
        case 'h4':
          return `\n## ${children}\n`;
        case 'p':
          return `\n${children}\n`;
        case 'b':
        case 'strong':
          return `**${children}**`;
        case 'i':
        case 'em':
          return `*${children}*`;
        case 'a':
          return `[${children}](${node.attrs?.href || ''})`;
        case 'img':
          return `![image](${node.attrs?.src || ''})`;
        case 'figure':
          return children;
        case 'figcaption':
          return `\n*${children}*\n`;
        case 'ul':
          return `\n${children}`;
        case 'ol':
          return `\n${children}`;
        case 'li':
          return `- ${children}\n`;
        case 'blockquote':
          return `\n> ${children}\n`;
        case 'code':
          return `\`${children}\``;
        case 'pre':
          return `\n\`\`\`\n${children}\n\`\`\`\n`;
        case 'br':
          return '\n';
        case 'hr':
          return '\n---\n';
        case 's':
          return `~~${children}~~`;
        case 'u':
          return children; // No markdown equivalent
        case 'aside':
          return `\n*${children}*\n`;
        default:
          return children;
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the export function but lacks behavioral details: it doesn't disclose if this requires authentication, rate limits, whether it modifies the page, output structure, or error handling. For a tool with no annotations, this leaves significant gaps in understanding its operation.

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 that directly states the tool's function without redundancy. It is front-loaded with the core action and includes essential details (formats), 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.

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. It doesn't explain what the export returns (e.g., file content, download link), error conditions, or dependencies. For a tool with two parameters and potential complexity in output, more context is needed to guide effective use.

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 descriptions for both parameters ('path' and 'format' with enum). The description adds no additional meaning beyond the schema, such as path format examples or format-specific behaviors. Baseline 3 is appropriate since the schema adequately documents parameters.

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 action ('Export') and resource ('a Telegraph page'), specifying the target formats ('Markdown or HTML'). It distinguishes from siblings like 'telegraph_get_page' (retrieves content) or 'telegraph_backup_account' (account-level operation), though it doesn't explicitly contrast them. The purpose is specific but lacks explicit sibling differentiation.

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 is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing page access), compare to 'telegraph_get_page' (which might retrieve raw content), or specify use cases like archiving vs. editing. The description is purely functional without contextual advice.

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/NehoraiHadad/telegraph-mcp'

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