{"record":{"id":"e29d13f3683ad144","repo":"mastra-ai/mastra","slug":"invalid-arguments-for-firecrawl-scrape","errorCode":null,"errorMessage":"Invalid arguments for firecrawl_scrape","messagePattern":"Invalid arguments for firecrawl_scrape","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/__fixtures__/fire-crawl-complex-schema.ts","lineNumber":625,"sourceCode":"  }\n}\n// --- End added back helper functions ---\n\n// Define the tool execution logic creator\nconst createExecuteFunction = (originalName: string) => async (args: any) => {\n  const client = new FirecrawlApp({ apiKey: 'FIXTURE_API_KEY_PLACEHOLDER' });\n  const startTime = Date.now();\n  try {\n    safeLog('info', `[${new Date().toISOString()}] Received request for tool: ${originalName}`);\n\n    if (!args) {\n      throw new Error('No arguments provided');\n    }\n\n    switch (originalName) {\n      case 'firecrawl_scrape': {\n        if (!isScrapeOptions(args)) {\n          throw new Error('Invalid arguments for firecrawl_scrape');\n        }\n        const { url, ...options } = args;\n        try {\n          const scrapeStartTime = Date.now();\n          safeLog('info', `Starting scrape for URL: ${url} with options: ${JSON.stringify(options)}`);\n\n          const response = await client.scrapeUrl(url, {\n            ...options,\n          });\n\n          safeLog('info', `Scrape completed in ${Date.now() - scrapeStartTime}ms`);\n\n          if ('success' in response && !response.success) {\n            throw new Error(response.error || 'Scraping failed');\n          }\n\n          const contentParts = [];\n","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/__fixtures__/fire-crawl-complex-schema.ts#L607-L643","documentation":"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.","triggerScenarios":"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\"]}}`.","commonSituations":"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.","solutions":["Pass `url` as a plain string in the arguments object.","Rename incorrect keys so the payload matches the tool's inputSchema (`url` plus optional scrape options like formats, onlyMainContent).","Coerce non-string URL values with String(url) or read the URL from a nested field before invoking the tool."],"exampleFix":"// before\n{ 'link': 'https://example.com' }\n// after\n{ 'url': 'https://example.com', formats: ['markdown'] }","handlingStrategy":"validation","validationCode":"function validateScrapeArgs(args: unknown): asserts args is { url: string } & Record<string, unknown> {\n  if (typeof args !== 'object' || args === null || !('url' in args) || typeof (args as any).url !== 'string') {\n    throw new TypeError('firecrawl_scrape requires { url: string }');\n  }\n}","typeGuard":"function isScrapeOptions(a: unknown): a is { url: string } & Record<string, unknown> {\n  return typeof a === 'object' && a !== null && 'url' in a && typeof (a as { url: unknown }).url === 'string';\n}","tryCatchPattern":"try {\n  await callTool({ name: 'firecrawl_scrape', arguments: { url } });\n} catch (e) {\n  if ((e as Error).message.startsWith('Invalid arguments for firecrawl_scrape')) {\n    // inspect and repair the arguments object, then retry\n  }\n}","preventionTips":["Coerce URL to string before dispatching: url: String(input.url).","Keep key names aligned with the tool's inputSchema (`url`, not `link`).","Validate payloads with a schema library (zod) matching the tool's declared inputSchema."],"tags":["mcp","validation","type-guard"],"backgroundTag":"invalid-tool-arguments","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}