Skip to content

fix: Gemini requires parameters of type Array to provide schemas for array elements#24

Closed
vlymar wants to merge 3 commits intomainfrom
victor-kno-8641-mcp-issue-with-mcp-in-gemini
Closed

fix: Gemini requires parameters of type Array to provide schemas for array elements#24
vlymar wants to merge 3 commits intomainfrom
victor-kno-8641-mcp-issue-with-mcp-in-gemini

Conversation

@vlymar
Copy link
Copy Markdown
Contributor

@vlymar vlymar commented May 15, 2025

We saw an error in cursor that referenced the create_sms_step_in_workflow tool.

And I saw this error in Zed:

Error interacting with language model
failed to stream completion
error during streamGenerateContent, status code: 400, body: {
  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.tools[0].function_declarations[21].parameters.properties[blocks].items: missing field.\n",
    "status": "INVALID_ARGUMENT"
  }
}

If you combine the zed error message with the cursor error message you see that there's a problem with the blocks parameter of the create_sms_step_in_workflow tool.

After a bit of digging I found that Gemini has a history of being quite picky with the subset of OpenAPI that it supports.

Loom showing the mcp error failing against a locally version of the MCP server, then succeeding when I checkout and build this branch.

References

@linear
Copy link
Copy Markdown

linear bot commented May 15, 2025

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented May 15, 2025

⚠️ No Changeset found

Latest commit: 0469b76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vlymar vlymar changed the title fix: Gemini requires Array types to provide schemas fix: Gemini requires parameters of type Array to provide schemas for array elements May 15, 2025
The following variables are always available to use in liquid:

- \`recipient.id\`: The ID of the recipient.
- \`recipient.id\`: The ID of the recipient.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, my editor deleted a bunch of whitespace

.describe("(string): The key of the workflow to add the step to."),
blocks: z
.array(z.any())
.array(contentBlockSchema)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the key fix .array(z.any()) does not work


const contentBlockSchema = z.object({
type: contentTypes,
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a comprehensive schema for content blocks, but it demonstrates that the mcp server starts working once some schema is provided.

type: contentTypes,
});

// const contentBlockSchema = z.union([
Copy link
Copy Markdown
Contributor Author

@vlymar vlymar May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to create a schema for content blocks, but I couldn't get one to work. I suspect that zod is emitting an openapi schema that isn't compatible with gemini for this union type (or I have some other bug here).

Specifically, items.anyOf looks sus. Googles docs show that the items field should contain Schema types, and while anyOf is a field on Schema, I don't think its valid for it to be the only field present. There's probably a clever re-expression of this schema that would be compatible with google's Schema but I ran out of time to figure it out.
CleanShot 2025-05-14 at 20 24 02@2x

@vlymar vlymar requested a review from cjbell May 15, 2025 03:27
@cjbell cjbell marked this pull request as ready for review June 9, 2025 02:29
@cjbell cjbell closed this Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants