Skip to main content
Glama

browser_get_markdown

Extract webpage content as Markdown formatted text optimized for AI processing, supporting parallel browser instances and configurable content selection.

Instructions

Get page content in Markdown format, optimized for large language models

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdYesInstance ID
includeLinksNoWhether to include links
maxLengthNoMaximum content length in characters
selectorNoOptional CSS selector to extract content from specific element only

Implementation Reference

  • The primary handler function for 'browser_get_markdown'. It retrieves the browser instance and uses page.evaluate to run a comprehensive JavaScript function that traverses the DOM and converts HTML elements to Markdown format, handling headings, links, lists, tables, etc. Supports options like includeLinks, maxLength, and selector.
    private async getMarkdown(instanceId: string, options: {
      includeLinks: boolean;
      maxLength: number;
      selector?: string;
    }): Promise<ToolResult> {
      const instance = this.browserManager.getInstance(instanceId);
      if (!instance) {
        return { success: false, error: `Instance ${instanceId} not found` };
      }
    
      try {
        // JavaScript function to extract page content and convert to Markdown
        const markdownContent = await instance.page.evaluate((opts) => {
          const { includeLinks, maxLength, selector } = opts;
          
          // Select the root element to process
          const rootElement = selector ? document.querySelector(selector) : document.body;
          if (!rootElement) {
            return 'Specified element or page content not found';
          }
    
          // HTML to Markdown conversion function
          function htmlToMarkdown(element: any, depth = 0) {
            let markdown = '';
            const indent = '  '.repeat(depth);
            
            for (const node of element.childNodes) {
              if (node.nodeType === Node.TEXT_NODE) {
                const text = node.textContent?.trim();
                if (text) {
                  markdown += text + ' ';
                }
              } else if (node.nodeType === Node.ELEMENT_NODE) {
                const el = node as Element;
                const tagName = el.tagName.toLowerCase();
                
                switch (tagName) {
                  case 'h1':
                    markdown += `\n\n# ${el.textContent?.trim()}\n\n`;
                    break;
                  case 'h2':
                    markdown += `\n\n## ${el.textContent?.trim()}\n\n`;
                    break;
                  case 'h3':
                    markdown += `\n\n### ${el.textContent?.trim()}\n\n`;
                    break;
                  case 'h4':
                    markdown += `\n\n#### ${el.textContent?.trim()}\n\n`;
                    break;
                  case 'h5':
                    markdown += `\n\n##### ${el.textContent?.trim()}\n\n`;
                    break;
                  case 'h6':
                    markdown += `\n\n###### ${el.textContent?.trim()}\n\n`;
                    break;
                  case 'p':
                    const pText = htmlToMarkdown(el, depth);
                    if (pText.trim()) {
                      markdown += `\n\n${pText.trim()}\n`;
                    }
                    break;
                  case 'br':
                    markdown += '\n';
                    break;
                  case 'strong':
                  case 'b':
                    markdown += `**${el.textContent?.trim()}**`;
                    break;
                  case 'em':
                  case 'i':
                    markdown += `*${el.textContent?.trim()}*`;
                    break;
                  case 'code':
                    markdown += `\`${el.textContent?.trim()}\``;
                    break;
                  case 'pre':
                    markdown += `\n\`\`\`\n${el.textContent?.trim()}\n\`\`\`\n`;
                    break;
                  case 'a':
                    const href = el.getAttribute('href');
                    const linkText = el.textContent?.trim();
                    if (includeLinks && href && linkText) {
                      if (href.startsWith('http')) {
                        markdown += `[${linkText}](${href})`;
                      } else {
                        markdown += linkText;
                      }
                    } else {
                      markdown += linkText || '';
                    }
                    break;
                  case 'ul':
                  case 'ol':
                    markdown += '\n';
                    const listItems = el.querySelectorAll('li');
                    listItems.forEach((li, index) => {
                      const bullet = tagName === 'ul' ? '-' : `${index + 1}.`;
                      markdown += `${indent}${bullet} ${li.textContent?.trim()}\n`;
                    });
                    markdown += '\n';
                    break;
                  case 'blockquote':
                    const quoteText = el.textContent?.trim();
                    if (quoteText) {
                      markdown += `\n> ${quoteText}\n\n`;
                    }
                    break;
                  case 'div':
                  case 'section':
                  case 'article':
                  case 'main':
                    // Recursively process container elements
                    markdown += htmlToMarkdown(el, depth);
                    break;
                  case 'table':
                    // Simplified table processing
                    const rows = el.querySelectorAll('tr');
                    if (rows.length > 0) {
                      markdown += '\n\n';
                      rows.forEach((row, rowIndex) => {
                        const cells = row.querySelectorAll('td, th');
                        const cellTexts = Array.from(cells).map(cell => cell.textContent?.trim() || '');
                        markdown += '| ' + cellTexts.join(' | ') + ' |\n';
                        if (rowIndex === 0) {
                          markdown += '|' + ' --- |'.repeat(cells.length) + '\n';
                        }
                      });
                      markdown += '\n';
                    }
                    break;
                  case 'script':
                  case 'style':
                  case 'nav':
                  case 'footer':
                  case 'aside':
                    // Ignore these elements
                    break;
                  default:
                    // For other elements, continue recursive processing of child elements
                    markdown += htmlToMarkdown(el, depth);
                    break;
                }
              }
            }
            
            return markdown;
          }
    
          // Extract page title
          const title = document.title;
          const url = window.location.href;
          
          // Generate Markdown content
          let content = `# ${title}\n\n**URL:** ${url}\n\n`;
          content += htmlToMarkdown(rootElement);
          
          // Clean up extra line breaks and spaces
          content = content
            .replace(/\n{3,}/g, '\n\n')
            .replace(/[ \t]+/g, ' ')
            .trim();
          
          // Truncate content if exceeds maximum length
          if (content.length > maxLength) {
            content = content.substring(0, maxLength) + '\n\n[Content truncated...]';
          }
          
          return content;
        }, options);
    
        return {
          success: true,
          data: { 
            markdown: markdownContent,
            length: markdownContent.length,
            truncated: markdownContent.length >= options.maxLength,
            url: instance.page.url(),
            title: await instance.page.title()
          },
          instanceId
        };
      } catch (error) {
        return {
          success: false,
          error: `Get markdown failed: ${error instanceof Error ? error.message : error}`,
          instanceId
        };
      }
    }
  • Defines the input schema for the browser_get_markdown tool, specifying parameters like instanceId (required), includeLinks, maxLength, and optional selector.
    inputSchema: {
      type: 'object',
      properties: {
        instanceId: {
          type: 'string',
          description: 'Instance ID'
        },
        includeLinks: {
          type: 'boolean',
          description: 'Whether to include links',
          default: true
        },
        maxLength: {
          type: 'number',
          description: 'Maximum content length in characters',
          default: 10000
        },
        selector: {
          type: 'string',
          description: 'Optional CSS selector to extract content from specific element only'
        }
      },
      required: ['instanceId']
  • src/tools.ts:461-488 (registration)
    Registers the browser_get_markdown tool in the getTools() method by including it in the returned Tool[] array.
    {
      name: 'browser_get_markdown',
      description: 'Get page content in Markdown format, optimized for large language models',
      inputSchema: {
        type: 'object',
        properties: {
          instanceId: {
            type: 'string',
            description: 'Instance ID'
          },
          includeLinks: {
            type: 'boolean',
            description: 'Whether to include links',
            default: true
          },
          maxLength: {
            type: 'number',
            description: 'Maximum content length in characters',
            default: 10000
          },
          selector: {
            type: 'string',
            description: 'Optional CSS selector to extract content from specific element only'
          }
        },
        required: ['instanceId']
      }
    }
  • src/tools.ts:578-584 (registration)
    In the executeTools switch statement, routes calls to 'browser_get_markdown' to the getMarkdown handler method.
    case 'browser_get_markdown':
      return await this.getMarkdown(args.instanceId, {
        includeLinks: args.includeLinks ?? true,
        maxLength: args.maxLength || 10000,
        selector: args.selector
      });
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 of behavioral disclosure. It mentions optimization for large language models, which adds some context about output format, but fails to describe key behaviors: whether it's read-only, if it requires specific permissions, rate limits, or what happens on errors. For a tool with no annotation coverage, this is a significant gap.

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's front-loaded with the core purpose and includes a useful optimization note. 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.

Completeness2/5

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

Given the tool's complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on behavioral traits, error handling, and output specifics. While it states the format and optimization, it doesn't cover enough context for safe and effective use, especially for a tool that interacts with browser instances.

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?

The description adds no parameter-specific information beyond what the input schema provides. Schema description coverage is 100%, so all parameters are documented in the schema. The description implies content extraction but doesn't elaborate on parameter usage or interactions. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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 tool's purpose: 'Get page content in Markdown format, optimized for large language models.' It specifies the verb ('Get'), resource ('page content'), and format ('Markdown'), distinguishing it from siblings like browser_get_element_text or browser_get_page_info. However, it doesn't explicitly differentiate from all siblings (e.g., browser_evaluate might also retrieve content).

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?

The description provides no guidance on when to use this tool versus alternatives. It mentions optimization 'for large language models,' which hints at a context but doesn't specify scenarios or exclusions. No explicit alternatives or prerequisites are stated, leaving usage unclear relative to siblings like browser_get_element_text or browser_get_page_info.

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/sailaoda/concurrent-browser-mcp'

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