-
Notifications
You must be signed in to change notification settings - Fork 639
fix(schema): replace anyOf unions with flat params for Gemini compatibility#165
fix(schema): replace anyOf unions with flat params for Gemini compatibility#165leonardogrig merged 1 commit intomainfrom
Conversation
Summary
Google Gemini's function calling API rejects the MCP server's tool schemas because anyOf is used alongside other fields in the formats and parsers parameters. Gemini requires that when anyOf is present in a schema node, it must be the only property -- no sibling fields are allowed.
This PR removes all z.union() (which produces anyOf in JSON Schema) from the tool definitions and replaces them with flat parameter alternatives that are compatible with all LLM providers.
Changes
formats: Changed fromz.union([enum, object, object])to a simplez.enum()array. Added'json'to the enum values.jsonOptions: New optional param for JSON extractionpromptandschema(used when'json'is in formats).screenshotOptions: New optional param for screenshotfullPage,quality, andviewport(used when'screenshot'is in formats).parsers: Changed fromz.union([enum, object])to a simplez.enum(['pdf'])array.pdfOptions: New optional param formaxPages(used when'pdf'is in parsers).webhook(crawl tool): Changed fromz.union([string, object])to a simplez.string(), with a newwebhookHeadersparam.- Added helper functions (
buildFormatsArray,buildParsersArray,buildWebhook,transformScrapeParams) that reassemble the nested format the Firecrawl API expects from the flat MCP params at execution time. - Updated tool description examples to use the new flat param style.
How it works
The MCP schema now uses simple, flat parameters that all LLM function-calling implementations can handle. At execution time, helper functions transform these flat params back into the nested format the Firecrawl API expects. This is transparent to both the LLM and the API.
Before (breaks Gemini):
After (works everywhere):
Testing
- Build passes (
npm run build) - No remaining
z.union()calls in source - Backward compatible: simple format usage like
["markdown"]works unchanged
Closes #164
546b948 to
2f05302
Compare
Google Gemini's function calling API rejects tool schemas that use
anyOf alongside other fields. This replaces all z.union() usages with
flat parameter alternatives:
- formats: now a simple string enum array (added 'json' to the enum)
- jsonOptions: new param for JSON extraction prompt/schema
- screenshotOptions: new param for screenshot fullPage/quality/viewport
- parsers: now a simple string enum array
- pdfOptions: new param for PDF maxPages
- webhook (crawl): now a simple string, with separate webhookHeaders
Helper functions (buildFormatsArray, buildParsersArray, buildWebhook,
transformScrapeParams) reassemble the nested format the API expects
from the flat MCP params at execution time.
Closes #164
2f05302 to
4e8da30
Compare
|
I've verified this fix locally |