Skip to content

[Fix] Gemini requests fail when user enables the full MCP tool set#148

Open
roomote[bot] wants to merge 8 commits into
mainfrom
feature/add-gemini-provider-e2e-tests-1ke9f2v2afjjv
Open

[Fix] Gemini requests fail when user enables the full MCP tool set#148
roomote[bot] wants to merge 8 commits into
mainfrom
feature/add-gemini-provider-e2e-tests-1ke9f2v2afjjv

Conversation

@roomote
Copy link
Copy Markdown
Contributor

@roomote roomote Bot commented May 16, 2026

Opened on behalf of Elliott de Launay. View the task or mention @roomote for follow-up asks.

Related GitHub Issue

Closes: N/A - Roomote task linked above.
References: RooCodeInc/Roo-Code#12202

Description

Fixes Gemini 400 INVALID_ARGUMENT failures that occurred when the provider sent the full MCP/native tool set.

Key changes:

  • Stops sending broad allowedFunctionNames lists to Gemini after live API testing showed generic INVALID_ARGUMENT failures with larger restriction lists and history-incompatible function names.
  • Continues sending all function declarations to Gemini for tool-call history compatibility.
  • Sanitizes outbound Gemini function schemas into a narrower compatibility shape for third-party MCP schemas, including $ref resolution, allOf merging, and recursion guards for self-referential schemas.
  • Keeps mode/tool restrictions enforced by execution-time validation.
  • Expands Gemini provider and e2e coverage, including request-shape assertions for parametersJsonSchema, absence of broad allowedFunctionNames, reasoning config, recursive schema handling, and e2e record/replay behavior.

Reviewers should pay closest attention to the provider trade-off: Gemini no longer receives broad provider-side callable restrictions, so the execution layer remains the final guard for mode-disallowed tools.

Test Procedure

Manual verification:

  • Rebuilt and installed the VSIX with pnpm run install:vsix:force -y --editor=code.
  • Reloaded VS Code.
  • Confirmed a fresh Gemini chat with MCP tools enabled no longer fails with 400 INVALID_ARGUMENT.

Automated checks:

pnpm --filter zoo-code exec vitest run api/providers/__tests__/gemini-handler.spec.ts
pnpm --filter zoo-code exec vitest run core/tools/__tests__/validateToolUse.spec.ts
pnpm --filter @roo-code/vscode-e2e check-types
pnpm --dir apps/web-roo-code test

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - no UI changes.

Documentation Updates

  • No documentation updates are required.
  • Yes, documentation updates are required. (Please describe what needs to be updated or link to a PR in the docs repository).

Additional Notes

Direct Gemini API testing found that function declaration count alone was not the failing condition: requests with more than 25 declarations could succeed when broad allowedFunctionNames was omitted. The failure reproduced when allowedFunctionNames grew beyond the backend's effective tolerance or excluded names needed by prior tool-call history.

Schema compatibility cleanup is intentionally conservative. Gemini documents function declaration schemas as an OpenAPI-style subset with single-value type plus nullable, while third-party MCP servers may emit broader JSON Schema constructs.

Get in Touch

Elliott de Launay

@roomote roomote Bot added the roomote:auto-resolve-conflicts Allow Roomote to auto-resolve merge conflicts for this PR label May 16, 2026
@roomote
Copy link
Copy Markdown
Contributor Author

roomote Bot commented May 16, 2026

No new code issues found. platform-unit-test (windows-latest) is still pending. See task

  • Make the Gemini e2e suite recordable without a missing-key crash in test:record.
  • Keep the mocked Gemini fixtures aligned with the new reasoningEffort prompt tags so e2e-mock does not time out.
  • Resolve $ref entries before stripping $defs/definitions from Gemini tool schemas.
  • Merge allOf object fragments without overwriting earlier properties/required entries.
  • platform-unit-test (windows-latest) is no longer pending.
  • Keep top-level properties/required when Gemini tool schemas also include allOf fragments.
  • e2e-mock is failing: apps/vscode-e2e/src/suite/providers/zai.test.ts still expects glm-5-turbo to send max_tokens = 40_551, but the CI run captured 40_000. — dismissed: stale after the branch diverged; the current PR no longer includes that Z.ai diff and e2e-mock now passes.
  • Current rerun: platform-unit-test (windows-latest) is still pending after the 10-minute wait cap. — dismissed: stale; the current Windows job passed.
  • Avoid infinite recursion when sanitizing recursive Gemini tool schemas; recursive $ref chains now stop at a finite leaf instead of overflowing the stack before the request is sent.
  • Latest rerun: platform-unit-test (windows-latest) is still pending after the 10-minute wait cap. — dismissed: superseded by the newer rerun on head 121762cbc04463bb52b43ed5b89df2356e19890f.
  • platform-unit-test (ubuntu-latest) is no longer pending.
  • platform-unit-test (windows-latest) is no longer pending.
  • platform-unit-test (windows-latest) is still pending on the latest rerun.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

❌ Patch coverage is 91.80328% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/api/providers/gemini.ts 91.80% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread apps/vscode-e2e/src/suite/providers/gemini.test.ts
Comment thread src/api/providers/gemini.ts
Comment thread src/api/providers/gemini.ts Outdated
Comment thread apps/vscode-e2e/src/suite/providers/gemini.test.ts
@edelauna edelauna changed the title [Chore] Add Google Gemini provider end-to-end coverage [Fix] Avoid Gemini failures with full MCP tool set May 16, 2026
@edelauna edelauna force-pushed the feature/add-gemini-provider-e2e-tests-1ke9f2v2afjjv branch from 0ab7b1f to 2edf5d8 Compare May 17, 2026 01:45
@edelauna edelauna marked this pull request as ready for review May 17, 2026 01:45
Comment thread src/api/providers/gemini.ts Outdated
@roomote
Copy link
Copy Markdown
Contributor Author

roomote Bot commented May 17, 2026

Addressed the new PR feedback on the existing branch and refreshed the PR metadata. See task

Shipped commit: 22d0bf9

What changed:

  • guarded recursive $ref expansion in Gemini schema sanitization so self-referential MCP tool schemas stop at a finite leaf instead of overflowing the stack
  • added a focused regression test covering a recursive $defs schema and verifying the sanitized payload stays serializable

Validation:

  • pnpm --dir /vercel/sandbox/repos/Zoo-Code-Org/Zoo-Code/src exec vitest run api/providers/__tests__/gemini-handler.spec.ts
  • pnpm --dir /vercel/sandbox/repos/Zoo-Code-Org/Zoo-Code/apps/web-roo-code test

Browser proof: not applicable for this non-visual provider/schema fix.

The recursive-schema review thread is resolved. GitHub now shows review required again because this new commit replaced the previously approved head.

@roomote roomote Bot changed the title [Fix] Avoid Gemini failures with full MCP tool set [Fix] Gemini requests fail when user enables the full MCP tool set May 17, 2026
edelauna
edelauna previously approved these changes May 17, 2026
Copy link
Copy Markdown
Contributor

@edelauna edelauna left a comment

Choose a reason for hiding this comment

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

Fix for an issue I was getting with Gemini and some mcp usage.

@edelauna edelauna force-pushed the feature/add-gemini-provider-e2e-tests-1ke9f2v2afjjv branch 2 times, most recently from 71776f8 to 63a6f25 Compare May 18, 2026 19:05
Comment thread src/api/providers/gemini.ts Outdated
@edelauna edelauna force-pushed the feature/add-gemini-provider-e2e-tests-1ke9f2v2afjjv branch 2 times, most recently from 3c8eb15 to 121762c Compare May 19, 2026 02:21
Copy link
Copy Markdown
Contributor

@edelauna edelauna left a comment

Choose a reason for hiding this comment

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

Updating e2e tests and fixing an issue with MCP tool calling and gemini.

@edelauna edelauna force-pushed the feature/add-gemini-provider-e2e-tests-1ke9f2v2afjjv branch from 121762c to aff8241 Compare May 20, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

roomote:auto-resolve-conflicts Allow Roomote to auto-resolve merge conflicts for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants