Skip to main content
Glama
amotivv

cloudflare-browser-rendering-mcp

extract_structured_content

Extract structured data from web pages using specified CSS selectors, enabling precise content retrieval for processing in LLMs or other applications.

Instructions

Extracts structured content from a web page using CSS selectors

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorsYesCSS selectors to extract content
urlYesURL to extract content from

Implementation Reference

  • The handler function for the extract_structured_content tool. Validates input arguments (url and selectors object), simulates content extraction using mock data for each selector, formats the results as Markdown sections, and returns a structured text content response. Includes error handling.
    /**
     * Handle the extract_structured_content tool
     */
    private async handleExtractStructuredContent(args: any) {
      // Validate arguments
      if (
        typeof args !== 'object' || 
        args === null || 
        typeof args.url !== 'string' ||
        typeof args.selectors !== 'object'
      ) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for extract_structured_content');
      }
    
      const { url, selectors } = args;
    
      try {
        // In a real implementation, you would:
        // 1. Use Cloudflare Browser Rendering to fetch the page
        // 2. Use the /scrape endpoint to extract content based on selectors
        
        // For this simulation, we'll return mock results
        const mockResults: Record<string, string> = {};
        
        for (const [key, selector] of Object.entries(selectors)) {
          if (typeof selector === 'string') {
            // Simulate extraction based on selector
            mockResults[key] = `Extracted content for selector "${selector}"`;
          }
        }
        
        // Format the results
        const formattedResults = Object.entries(mockResults)
          .map(([key, value]) => `## ${key}\n${value}`)
          .join('\n\n');
        
        return {
          content: [
            {
              type: 'text',
              text: `# Structured Content from ${url}\n\n${formattedResults}`,
            },
          ],
        };
      } catch (error) {
        console.error('[Error] Error extracting structured content:', error);
        return {
          content: [
            {
              type: 'text',
              text: `Error extracting structured content: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Tool schema definition returned by listTools, specifying name, description, and inputSchema requiring 'url' string and 'selectors' object (CSS selectors as keys with string values).
    {
      name: 'extract_structured_content',
      description: 'Extracts structured content from a web page using CSS selectors',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL to extract content from',
          },
          selectors: {
            type: 'object',
            description: 'CSS selectors to extract content',
            additionalProperties: {
              type: 'string',
            },
          },
        },
        required: ['url', 'selectors'],
      },
    },
  • src/server.ts:189-191 (registration)
    Registration in the CallToolRequest handler switch statement, logging the call and dispatching to the specific handleExtractStructuredContent method.
    case 'extract_structured_content':
      console.error(`[API] Extracting structured content from: ${args?.url}`);
      return await this.handleExtractStructuredContent(args);
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 states what the tool does but lacks critical behavioral details: it doesn't specify if it fetches the page internally, handles errors, requires internet access, has rate limits, or what the output format is. 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 extremely concise and front-loaded: a single sentence that directly states the tool's function without any fluff. Every word earns its place by conveying essential information about extraction, content type, source, and method. It's efficiently structured for quick understanding.

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 complexity of web extraction (involving network calls, parsing, and structured data output), the description is incomplete. There's no output schema, and the description doesn't explain return values, error handling, or behavioral traits. With no annotations and only basic parameter coverage, it fails to provide enough context for effective use in real-world scenarios.

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 schema description coverage is 100%, meaning the input schema already documents both parameters ('url' and 'selectors') with descriptions. The tool description adds no additional meaning beyond what's in the schema—it doesn't explain parameter interactions, provide examples, or clarify semantics. With high schema coverage, the baseline score of 3 is appropriate.

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: 'Extracts structured content from a web page using CSS selectors'. It specifies the verb ('extracts'), resource ('structured content'), and method ('CSS selectors'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'fetch_page' or 'summarize_content', which would require a 5.

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 doesn't mention scenarios where extraction is preferred over fetching the whole page, searching documentation, summarizing, or taking a screenshot. Without any context or exclusions, users must infer usage from the purpose alone.

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

Related 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/amotivv/cloudflare-browser-rendering-mcp'

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