mastra-ai/mastra · error · Error

Invalid arguments for firecrawl_generate_llmstxt

Error message

Invalid arguments for firecrawl_generate_llmstxt

What it means

firecrawl_generate_llmstxt validates args with isGenerateLLMsTextOptions(args) before calling client.generateLLMsText. The guard requires a valid `url` plus allowed optional fields (maxUrls, showFullText, etc.); failure throws this error pre-flight. It protects the expensive LLMs.txt generation job from malformed input.

Source

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

              {
                type: 'text',
                text: trimResponseText(formattedResponse.finalAnalysis),
              },
            ],
            isError: false,
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [{ type: 'text', text: trimResponseText(errorMessage) }],
            isError: true,
          };
        }
      }

      case 'firecrawl_generate_llmstxt': {
        if (!isGenerateLLMsTextOptions(args)) {
          throw new Error('Invalid arguments for firecrawl_generate_llmstxt');
        }

        try {
          const { url, ...params } = args;
          const generateStartTime = Date.now();

          safeLog('info', `Starting LLMs.txt generation for URL: ${url}`);

          const response = await withRetry(
            async () => client.generateLLMsText(url, { ...params }),
            'LLMs.txt generation',
          );

          if (!response.success) {
            throw new Error(response.error || 'LLMs.txt generation failed');
          }

          safeLog('info', `LLMs.txt generation completed in ${Date.now() - generateStartTime}ms`);

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass a complete http(s) URL in the `url` field, e.g. https://example.com.
  2. Type optional params correctly: maxUrls as a number, showFullText as a boolean.
  3. Cross-check arguments against the firecrawl_generate_llmstxt Zod schema in the server.
  4. Validate/normalize the URL client-side (new URL(...)) before invoking the tool.

Example fix

// before
firecrawl_generate_llmstxt({ url: "example.com", maxUrls: "100" })
// after
firecrawl_generate_llmstxt({ url: "https://example.com", maxUrls: 100 })
Defensive patterns

Strategy: validation

Validate before calling

function canGenerateLlmsTxt(args) {
  if (!args || typeof args.url !== 'string') return false;
  try {
    const p = new URL(args.url);
    if (p.protocol !== 'http:' && p.protocol !== 'https:') return false;
  } catch { return false; }
  if (args.maxUrls !== undefined && (typeof args.maxUrls !== 'number' || args.maxUrls <= 0)) return false;
  if (args.showFullText !== undefined && typeof args.showFullText !== 'boolean') return false;
  return true;
}

Type guard

function isGenerateLlmsTxtArgs(a: unknown): a is { url: string; maxUrls?: number; showFullText?: boolean } {
  if (typeof a !== 'object' || a === null) return false;
  const o = a as Record<string, unknown>;
  return typeof o.url === 'string' && /^https?:\/\//.test(o.url) &&
    (o.maxUrls === undefined || typeof o.maxUrls === 'number') &&
    (o.showFullText === undefined || typeof o.showFullText === 'boolean');
}

Try / catch

try {
  return await generateLlmsTxt(args);
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Invalid arguments for firecrawl_generate_llmstxt')) {
    // auto-fix scheme-less URLs
    if (typeof args?.url === 'string' && !/^https?:\/\//.test(args.url)) {
      return generateLlmsTxt({ ...args, url: 'https://' + args.url });
    }
    throw new TypeError('generate_llmstxt needs { url: absolute http(s) URL }');
  }
  throw e;
}

Prevention

When it happens

Trigger: args fails isGenerateLLMsTextOptions: url missing or not a valid http(s) string, maxUrls not a positive number, showFullText not boolean, or extra/mistyped fields present.

Common situations: Passing a domain without scheme (example.com instead of https://example.com); LLM client omitting url and passing only options; maxUrls sent as a string; schema drift after tool-definition updates.

Related errors


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