fix(schema): replace anyOf unions with flat params for Gemini compatibility#165
Open
firecrawl-spring[bot] wants to merge 1 commit intomainfrom
Open
fix(schema): replace anyOf unions with flat params for Gemini compatibility#165firecrawl-spring[bot] wants to merge 1 commit intomainfrom
firecrawl-spring[bot] wants to merge 1 commit intomainfrom
Conversation
546b948 to
2f05302
Compare
…bility 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Google Gemini's function calling API rejects the MCP server's tool schemas because
anyOfis used alongside other fields in theformatsandparsersparameters. Gemini requires that whenanyOfis present in a schema node, it must be the only property — no sibling fields are allowed.This PR removes all
z.union()(which producesanyOfin 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.buildFormatsArray,buildParsersArray,buildWebhook,transformScrapeParams) that reassemble the nested format the Firecrawl API expects from the flat MCP params at execution time.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):
{ "formats": [{ "type": "json", "prompt": "Extract data", "schema": {...} }] }After (works everywhere):
{ "formats": ["json"], "jsonOptions": { "prompt": "Extract data", "schema": {...} } }Testing
npm run build)z.union()calls in source["markdown"]works unchangedCloses #164