Skip to main content
Glama

firecrawl_extract

Extract structured data from web pages using LLM prompts. Specify URLs and define output schema to transform web content into organized information.

Instructions

Extract structured information from web pages using LLM. Supports both cloud AI and self-hosted LLM extraction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlsYesList of URLs to extract information from
promptNoPrompt for the LLM extraction
systemPromptNoSystem prompt for LLM extraction
schemaNoJSON schema for structured data extraction
allowExternalLinksNoAllow extraction from external links
enableWebSearchNoEnable web search for additional context
includeSubdomainsNoInclude subdomains in extraction

Implementation Reference

  • Tool schema definition including input schema for firecrawl_extract
    const EXTRACT_TOOL: Tool = { name: 'firecrawl_extract', description: 'Extract structured information from web pages using LLM. ' + 'Supports both cloud AI and self-hosted LLM extraction.', inputSchema: { type: 'object', properties: { urls: { type: 'array', items: { type: 'string' }, description: 'List of URLs to extract information from', }, prompt: { type: 'string', description: 'Prompt for the LLM extraction', }, systemPrompt: { type: 'string', description: 'System prompt for LLM extraction', }, schema: { type: 'object', description: 'JSON schema for structured data extraction', }, allowExternalLinks: { type: 'boolean', description: 'Allow extraction from external links', }, enableWebSearch: { type: 'boolean', description: 'Enable web search for additional context', }, includeSubdomains: { type: 'boolean', description: 'Include subdomains in extraction', }, }, required: ['urls'], }, };
  • src/index.ts:960-973 (registration)
    Registration of all tools including firecrawl_extract (EXTRACT_TOOL) in the listTools handler
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ SCRAPE_TOOL, MAP_TOOL, CRAWL_TOOL, BATCH_SCRAPE_TOOL, CHECK_BATCH_STATUS_TOOL, CHECK_CRAWL_STATUS_TOOL, SEARCH_TOOL, EXTRACT_TOOL, DEEP_RESEARCH_TOOL, GENERATE_LLMSTXT_TOOL, ], }));
  • Main handler logic for firecrawl_extract: validates args with isExtractOptions, calls Firecrawl client.extract(), handles response, credits, errors, and formats output
    case 'firecrawl_extract': { if (!isExtractOptions(args)) { throw new Error('Invalid arguments for firecrawl_extract'); } try { const extractStartTime = Date.now(); safeLog( 'info', `Starting extraction for URLs: ${args.urls.join(', ')}` ); // Log if using self-hosted instance if (FIRECRAWL_API_URL) { safeLog('info', 'Using self-hosted instance for extraction'); } const extractResponse = await withRetry( async () => client.extract(args.urls, { prompt: args.prompt, systemPrompt: args.systemPrompt, schema: args.schema, allowExternalLinks: args.allowExternalLinks, enableWebSearch: args.enableWebSearch, includeSubdomains: args.includeSubdomains, origin: 'mcp-server', } as ExtractParams), 'extract operation' ); // Type guard for successful response if (!('success' in extractResponse) || !extractResponse.success) { throw new Error(extractResponse.error || 'Extraction failed'); } const response = extractResponse as ExtractResponse; // Monitor credits for cloud API if (!FIRECRAWL_API_URL && hasCredits(response)) { await updateCreditUsage(response.creditsUsed || 0); } // Log performance metrics safeLog( 'info', `Extraction completed in ${Date.now() - extractStartTime}ms` ); // Add warning to response if present const result = { content: [ { type: 'text', text: trimResponseText(JSON.stringify(response.data, null, 2)), }, ], isError: false, }; if (response.warning) { safeLog('warning', response.warning); } return result; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); // Special handling for self-hosted instance errors if ( FIRECRAWL_API_URL && errorMessage.toLowerCase().includes('not supported') ) { safeLog( 'error', 'Extraction is not supported by this self-hosted instance' ); return { content: [ { type: 'text', text: trimResponseText( 'Extraction is not supported by this self-hosted instance. Please ensure LLM support is configured.' ), }, ], isError: true, }; } return { content: [{ type: 'text', text: trimResponseText(errorMessage) }], isError: true, }; } }
  • Type guard helper function to validate arguments for firecrawl_extract
    function isExtractOptions(args: unknown): args is ExtractArgs { if (typeof args !== 'object' || args === null) return false; const { urls } = args as { urls?: unknown }; return ( Array.isArray(urls) && urls.every((url): url is string => typeof url === 'string') ); }
  • Type interfaces for ExtractArgs and ExtractResponse used by firecrawl_extract handler and validator.
    interface ExtractArgs { urls: string[]; prompt?: string; systemPrompt?: string; schema?: object; allowExternalLinks?: boolean; enableWebSearch?: boolean; includeSubdomains?: boolean; origin?: string; } interface ExtractResponse<T = any> { success: boolean; data: T; error?: string; warning?: string; creditsUsed?: number; } // Type guards function isScrapeOptions( args: unknown ): args is ScrapeParams & { url: string } { return ( typeof args === 'object' && args !== null && 'url' in args && typeof (args as { url: unknown }).url === 'string' ); } function isMapOptions(args: unknown): args is MapParams & { url: string } { return ( typeof args === 'object' && args !== null && 'url' in args && typeof (args as { url: unknown }).url === 'string' ); } function isCrawlOptions(args: unknown): args is CrawlParams & { url: string } { return ( typeof args === 'object' && args !== null && 'url' in args && typeof (args as { url: unknown }).url === 'string' ); } function isBatchScrapeOptions(args: unknown): args is BatchScrapeOptions { return ( typeof args === 'object' && args !== null && 'urls' in args && Array.isArray((args as { urls: unknown }).urls) && (args as { urls: unknown[] }).urls.every((url) => typeof url === 'string') ); } function isStatusCheckOptions(args: unknown): args is StatusCheckOptions { return ( typeof args === 'object' && args !== null && 'id' in args && typeof (args as { id: unknown }).id === 'string' ); } function isSearchOptions(args: unknown): args is SearchOptions { return ( typeof args === 'object' && args !== null && 'query' in args && typeof (args as { query: unknown }).query === 'string' ); } function isExtractOptions(args: unknown): args is ExtractArgs { if (typeof args !== 'object' || args === null) return false; const { urls } = args as { urls?: unknown }; return ( Array.isArray(urls) && urls.every((url): url is string => typeof url === 'string') ); }

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/Krieg2065/firecrawl-mcp-server'

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