Skip to content

Fix: Make tool schemas compatible with Gemini models#3

Open
zzgael wants to merge 5 commits intoAugmented-Nature:mainfrom
zzgael:gemini-fix-plus-features
Open

Fix: Make tool schemas compatible with Gemini models#3
zzgael wants to merge 5 commits intoAugmented-Nature:mainfrom
zzgael:gemini-fix-plus-features

Conversation

@zzgael
Copy link
Copy Markdown

@zzgael zzgael commented Sep 13, 2025

Problem

Gemini/VertexAI models cannot process tool schemas that contain union types. This causes the error:

zod_to_gemini_parameters: Gemini cannot handle union types

This issue affects all MCP clients when using Gemini models, not just specific implementations.

Fixes #1 - This addresses the same root cause: union types in tool schemas are incompatible with Gemini's parameter processing.

Solution

Changed all cid parameters from union type ['number', 'string'] to single type 'string'.

Changes Made

  • Modified 18 tool parameter definitions in src/index.ts
  • Changed from: cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }
  • Changed to: cid: { type: 'string', description: 'PubChem Compound ID (CID) - accepts numeric or string values' }

Why This Works

  1. No functionality loss: JavaScript automatically coerces numbers to strings when needed
  2. Validation unchanged: The server's validation functions already accept both number and string types
  3. API compatibility: PubChem API calls convert CIDs to strings in URLs anyway
  4. Backward compatible: Existing code passing numbers will continue to work

Additional Improvements

This PR also incorporates the excellent work from @lighteternal's fork, including:

  • New toxicity and regulatory tools
  • Environmental fate assessment
  • Enhanced bioassay functionality
  • Additional safety data tools

Testing

  • ✅ Server builds and runs successfully
  • ✅ All tools accept both numeric (e.g., 2244) and string (e.g., "2244") CIDs
  • ✅ Compatible with Gemini/VertexAI models in all MCP clients
  • ✅ Maintains compatibility with other AI providers (OpenAI, Anthropic, etc.)

Related Issues

cc: @lighteternal - incorporated your improvements as well!

Dimitris Papadopoulos and others added 5 commits June 16, 2025 17:29
…ss_environmental_fate, get_regulatory_info with comprehensive analysis
- Incorporated all new tools and features from lighteternal/PubChem-MCP-Server
- Fixed Gemini/VertexAI compatibility by removing union types in tool schemas
- Changed all 'cid' parameters from type: ['number', 'string'] to type: 'string'
- Maintains full backward compatibility (JavaScript coerces numbers to strings)

This combines:
1. lighteternal's extensive new tools for toxicity, regulatory info, and more
2. Gemini compatibility fix for all tool schemas

Fixes: zod_to_gemini_parameters: Gemini cannot handle union types
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.

TypeError: unhashable type: 'list' when connecting via mcpadapt

1 participant