{"record":{"id":"21b09e7f04abd06c","repo":"mastra-ai/mastra","slug":"invalid-arguments-for-firecrawl-search","errorCode":null,"errorMessage":"Invalid arguments for firecrawl_search","messagePattern":"Invalid arguments for firecrawl_search","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/__fixtures__/fire-crawl-complex-schema.ts","lineNumber":753,"sourceCode":"        const response = await client.checkCrawlStatus(args.id);\n        if (!response.success) {\n          throw new Error(response.error);\n        }\n        const status = `Crawl Status:\nStatus: ${response.status}\nProgress: ${response.completed}/${response.total}\nCredits Used: ${response.creditsUsed}\nExpires At: ${response.expiresAt}\n${response.data.length > 0 ? '\\nResults:\\n' + formatResults(response.data) : ''}`;\n        return {\n          content: [{ type: 'text', text: trimResponseText(status) }],\n          isError: false,\n        };\n      }\n\n      case 'firecrawl_search': {\n        if (!isSearchOptions(args)) {\n          throw new Error('Invalid arguments for firecrawl_search');\n        }\n        try {\n          const response = await withRetry(async () => client.search(args.query, { ...args }), 'search operation');\n\n          if (!response.success) {\n            throw new Error(`Search failed: ${response.error || 'Unknown error'}`);\n          }\n\n          const results = response.data\n            .map(\n              result =>\n                `URL: ${result.url}\nTitle: ${result.title || 'No title'}\nDescription: ${result.description || 'No description'}\n${result.markdown ? `\\nContent:\\n${result.markdown}` : ''}`,\n            )\n            .join('\\n\\n');\n","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/__fixtures__/fire-crawl-complex-schema.ts#L735-L771","documentation":"The firecrawl_search tool executor validates its arguments with isSearchOptions(args) before calling the Firecrawl API. When the incoming arguments object fails that predicate — missing/invalid query, out-of-range limit, bad timeout, or wrong types for optional fields — the executor throws 'Invalid arguments for firecrawl_search' instead of making a network call. It is a pre-flight argument-shape guard, not an API error.","triggerScenarios":"Calling firecrawl_search with args that fail isSearchOptions: args is null/undefined, query is missing or not a non-empty string, limit is not a number within allowed range, timeout invalid, or optional fields like scrapeOptions have wrong types.","commonSituations":"LLM/agent clients hallucinating malformed tool arguments; hand-written JSON args with limit as a string ('5' instead of 5); omitting query entirely; passing tbs or other option fields with wrong types after a schema change.","solutions":["Ensure args includes a non-empty string `query` field.","Validate numeric fields (limit, timeout) are actual numbers within allowed ranges before invoking the tool.","Compare your call against the firecrawl_search Zod schema in the server's tool definitions and fix the argument object.","If arguments come from an LLM, tighten the tool's input schema/JSON-schema so invalid args are rejected before execution."],"exampleFix":"// before\nfirecrawl_search({ query: \"news\", limit: \"5\" })\n// after\nfirecrawl_search({ query: \"news\", limit: 5 })","handlingStrategy":"validation","validationCode":"function canCallSearch(args) {\n  return (\n    !!args &&\n    typeof args.query === 'string' &&\n    args.query.trim().length > 0 &&\n    (args.limit === undefined || (typeof args.limit === 'number' && args.limit > 0 && args.limit <= 100)) &&\n    (args.timeout === undefined || typeof args.timeout === 'number')\n  );\n}\nif (!canCallSearch(args)) throw new TypeError('firecrawl_search requires non-empty string query and numeric limit/timeout');","typeGuard":"function isSearchArgs(a: unknown): a is { query: string; limit?: number; timeout?: number } {\n  if (typeof a !== 'object' || a === null) return false;\n  const o = a as Record<string, unknown>;\n  return typeof o.query === 'string' && o.query.length > 0 &&\n    (o.limit === undefined || typeof o.limit === 'number') &&\n    (o.timeout === undefined || typeof o.timeout === 'number');\n}","tryCatchPattern":"try {\n  return await firecrawlSearch(args);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Invalid arguments for firecrawl_search')) {\n    console.error('Bad search args, fix schema:', JSON.stringify(args));\n    return { corrected: false, error: e.message };\n  }\n  throw e;\n}","preventionTips":["Mirror the tool's Zod schema in client-side validation before each call.","Coerce numeric-looking strings (limit: '5') to numbers before sending.","For LLM callers, attach a strict JSON schema to the tool definition so invalid args are rejected at generation time.","Log the exact args payload when this error occurs to spot systematic schema drift."],"tags":["mcp","validation","tool-arguments","firecrawl"],"backgroundTag":"invalid-tool-arguments","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}