Skip to main content
Glama

extract

Extract structured JSON data from webpages using AI, bypassing bot detection and CAPTCHA to scrape any site reliably.

Instructions

Scrape a webpage and extract structured data as JSON. First scrapes the page as markdown, then uses AI sampling to convert it to structured JSON format. This tool can unlock any webpage even if it uses bot detection or CAPTCHA.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
extraction_promptNoCustom prompt to guide the extraction process. If not provided, will extract general structured data from the page.

Implementation Reference

  • The main handler function for the 'extract' tool. It scrapes the given URL using Bright Data API to get markdown content, then uses the MCP session's AI sampling to extract structured JSON data based on the optional extraction_prompt.
    execute: tool_fn('extract', async ({ url, extraction_prompt }, ctx) => {
        let scrape_response = await axios({
            url: 'https://api.brightdata.com/request',
            method: 'POST',
            data: {
                url,
                zone: unlocker_zone,
                format: 'raw',
                data_format: 'markdown',
            },
            headers: api_headers(),
            responseType: 'text',
        });
    
        let markdown_content = scrape_response.data;
    
        let system_prompt = 'You are a data extraction specialist. You MUST respond with ONLY valid JSON, no other text or formatting. '
            + 'Extract the requested information from the markdown content and return it as a properly formatted JSON object. '
            + 'Do not include any explanations, markdown formatting, or text outside the JSON response.';
    
        let user_prompt = extraction_prompt ||
            'Extract the requested information from this markdown content and return ONLY a JSON object:';
    
        let session = server.sessions[0]; // Get the first active session
        if (!session) throw new Error('No active session available for sampling');
    
        let sampling_response = await session.requestSampling({
            messages: [
                {
                    role: "user",
                    content: {
                        type: "text",
                        text: `${user_prompt}\n\nMarkdown content:\n${markdown_content}\n\nRemember: Respond with ONLY valid JSON, no other text.`,
                    },
                },
            ],
            systemPrompt: system_prompt,
            includeContext: "thisServer",
        });
    
        return sampling_response.content.text;
    }),
  • Zod schema defining the input parameters for the 'extract' tool: required 'url' (string URL) and optional 'extraction_prompt' (string).
    parameters: z.object({
        url: z.string().url(),
        extraction_prompt: z.string().optional().describe(
            'Custom prompt to guide the extraction process. If not provided, '
            + 'will extract general structured data from the page.'
        ),
    }),
  • server.js:207-262 (registration)
    The addTool call that registers the 'extract' tool on the FastMCP server, including name, description, parameters schema, and execute handler.
    addTool({
        name: 'extract',
        description: 'Scrape a webpage and extract structured data as JSON. '
            + 'First scrapes the page as markdown, then uses AI sampling to convert '
            + 'it to structured JSON format. This tool can unlock any webpage even '
            + 'if it uses bot detection or CAPTCHA.',
        parameters: z.object({
            url: z.string().url(),
            extraction_prompt: z.string().optional().describe(
                'Custom prompt to guide the extraction process. If not provided, '
                + 'will extract general structured data from the page.'
            ),
        }),
        execute: tool_fn('extract', async ({ url, extraction_prompt }, ctx) => {
            let scrape_response = await axios({
                url: 'https://api.brightdata.com/request',
                method: 'POST',
                data: {
                    url,
                    zone: unlocker_zone,
                    format: 'raw',
                    data_format: 'markdown',
                },
                headers: api_headers(),
                responseType: 'text',
            });
    
            let markdown_content = scrape_response.data;
    
            let system_prompt = 'You are a data extraction specialist. You MUST respond with ONLY valid JSON, no other text or formatting. '
                + 'Extract the requested information from the markdown content and return it as a properly formatted JSON object. '
                + 'Do not include any explanations, markdown formatting, or text outside the JSON response.';
    
            let user_prompt = extraction_prompt ||
                'Extract the requested information from this markdown content and return ONLY a JSON object:';
    
            let session = server.sessions[0]; // Get the first active session
            if (!session) throw new Error('No active session available for sampling');
    
            let sampling_response = await session.requestSampling({
                messages: [
                    {
                        role: "user",
                        content: {
                            type: "text",
                            text: `${user_prompt}\n\nMarkdown content:\n${markdown_content}\n\nRemember: Respond with ONLY valid JSON, no other text.`,
                        },
                    },
                ],
                systemPrompt: system_prompt,
                includeContext: "thisServer",
            });
    
            return sampling_response.content.text;
        }),
    });
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the two-step process (scrape as markdown, then AI conversion) and mentions capabilities like handling bot detection, which adds useful context. However, it lacks details on potential limitations, rate limits, error handling, or output structure, leaving gaps for a tool with no output schema.

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 efficiently structured in three sentences: the core functionality, the technical process, and a key capability. Each sentence adds distinct value without redundancy, making it front-loaded and easy to parse.

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 the tool's complexity (AI-powered extraction with bot bypass), no annotations, no output schema, and 50% schema coverage, the description is incomplete. It covers the high-level process and a unique feature but misses details on output format, error cases, or performance constraints, which are critical for effective use.

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

Parameters4/5

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

Schema description coverage is 50% (only the extraction_prompt parameter has a description). The description compensates by explaining the overall process and implying the url parameter's role, but doesn't add specific details about parameter usage beyond what's in the schema. With 2 parameters and partial coverage, this is above the baseline of 3 for adequate but not comprehensive support.

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

Purpose5/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 with specific verbs ('scrape', 'extract') and resources ('webpage', 'structured data as JSON'), and distinguishes it from siblings by mentioning the AI-powered conversion to JSON format, unlike simpler scraping tools like scrape_as_html or scrape_as_markdown.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('to unlock any webpage even if it uses bot detection or CAPTCHA'), suggesting it's for challenging sites. However, it doesn't explicitly state when not to use it or name specific alternatives among the many sibling tools, such as simpler scraping options for straightforward pages.

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/dsouza-anush/brightdata-mcp-heroku'

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