mastra-ai/mastra · error · Error

Invalid arguments for firecrawl_scrape

Error message

Invalid arguments for firecrawl_scrape

What it means

The executor runs `isScrapeOptions(args)`, a guard that requires `args` to be an object containing a string `url`. If the guard fails, the scrape branch throws this error instead of calling `client.scrapeUrl` with an unusable URL.

Source

Thrown at packages/mcp/src/__fixtures__/fire-crawl-complex-schema.ts:625

  }
}
// --- End added back helper functions ---

// Define the tool execution logic creator
const createExecuteFunction = (originalName: string) => async (args: any) => {
  const client = new FirecrawlApp({ apiKey: 'FIXTURE_API_KEY_PLACEHOLDER' });
  const startTime = Date.now();
  try {
    safeLog('info', `[${new Date().toISOString()}] Received request for tool: ${originalName}`);

    if (!args) {
      throw new Error('No arguments provided');
    }

    switch (originalName) {
      case 'firecrawl_scrape': {
        if (!isScrapeOptions(args)) {
          throw new Error('Invalid arguments for firecrawl_scrape');
        }
        const { url, ...options } = args;
        try {
          const scrapeStartTime = Date.now();
          safeLog('info', `Starting scrape for URL: ${url} with options: ${JSON.stringify(options)}`);

          const response = await client.scrapeUrl(url, {
            ...options,
          });

          safeLog('info', `Scrape completed in ${Date.now() - scrapeStartTime}ms`);

          if ('success' in response && !response.success) {
            throw new Error(response.error || 'Scraping failed');
          }

          const contentParts = [];

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass `url` as a plain string in the arguments object.
  2. Rename incorrect keys so the payload matches the tool's inputSchema (`url` plus optional scrape options like formats, onlyMainContent).
  3. Coerce non-string URL values with String(url) or read the URL from a nested field before invoking the tool.

Example fix

// before
{ 'link': 'https://example.com' }
// after
{ 'url': 'https://example.com', formats: ['markdown'] }
Defensive patterns

Strategy: validation

Validate before calling

function validateScrapeArgs(args: unknown): asserts args is { url: string } & Record<string, unknown> {
  if (typeof args !== 'object' || args === null || !('url' in args) || typeof (args as any).url !== 'string') {
    throw new TypeError('firecrawl_scrape requires { url: string }');
  }
}

Type guard

function isScrapeOptions(a: unknown): a is { url: string } & Record<string, unknown> {
  return typeof a === 'object' && a !== null && 'url' in a && typeof (a as { url: unknown }).url === 'string';
}

Try / catch

try {
  await callTool({ name: 'firecrawl_scrape', arguments: { url } });
} catch (e) {
  if ((e as Error).message.startsWith('Invalid arguments for firecrawl_scrape')) {
    // inspect and repair the arguments object, then retry
  }
}

Prevention

When it happens

Trigger: Calling firecrawl_scrape with a non-object payload, a missing `url` property, or a non-string `url` (number, null, object) — e.g. `{"arguments":{"url":123}}` or `{"arguments":{"formats":["markdown"]}}`.

Common situations: The LLM puts the URL in a wrong key (`link`, `target`, `pageUrl`), passes a URL object instead of a string, or hallucinates a parameter shape after a tool-schema version change.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/e29d13f3683ad144. Report an issue: GitHub.