Drop-in replacement for ChatGoogleGenerativeAI that automatically transforms MCP tool schemas to be compatible with Gemini's strict schema requirements.

Simply replace your ChatGoogleGenerativeAI import with ChatGoogleGenerativeAIEx and all MCP tool schemas will be automatically transformed for Gemini compatibility.

// Before
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
...
const model = new ChatGoogleGenerativeAI({...});

// After (drop-in)
import { ChatGoogleGenerativeAIEx } from "@h1deya/langchain-google-genai-ex";
...
const model = new ChatGoogleGenerativeAIEx({...});

Set environment variable to see transformation details:

LANGCHAIN_GOOGLE_GENAI_EX_VERBOSE=true npm run your-script

This will show:

πŸ”§ Transforming 3 MCP tool(s) for Gemini compatibility...
βœ… get-alerts: No transformation needed (simple schema)
βœ… get-forecast: No transformation needed (simple schema)
πŸ”„ fetch: 2 exclusive bound(s) converted, 1 unsupported format(s) removed (uri)
πŸ“Š Summary: 1/3 tool(s) required schema transformation
  • "anyOf must be the only field set" errors (Gemini 1.5-flash)
  • "Unknown name 'exclusiveMaximum'" and similar schema validation errors
  • "Invalid JSON payload" errors from complex MCP schemas
  • Cascading failures where one complex server breaks entire MCP integration
  • Simple to useβ€Š-β€ŠJust replace the import and the classname
  • All original ChatGoogleGenerativeAI features (streaming, system instructions, etc.)
  • Full LangChain.js integration
  • Tested with Gemini 1.5 and 2.5 models
  • Unresolved references: If a schema points to $ref definitions that aren't available, they're simplified to a generic object.
  • Tuple-style arrays: For schemas that define arrays with position-specific types, only the first item is used.
  • Enums and formats: Only string enums and a small set of formats are kept; others are dropped.
  • Complex combinations: oneOf/allOf are simplified, which may loosen or slightly change validation rules.

These adjustments keep most MCP tools working, but rare edge cases could behave differently from the original schema.

Hierarchy

  • ChatGoogleGenerativeAI
    • ChatGoogleGenerativeAIEx

Constructors

Methods

Constructors

  • Parameters

    • fields: GoogleGenerativeAIChatInput

    Returns ChatGoogleGenerativeAIEx

Methods

  • Binds tools with automatic schema transformation.

    This overridden method specifically handles tool binding after automatically transforming all tools for Gemini compatibility.

    Parameters

    • tools: any[]

      Array of tools to bind (MCP tools, StructuredTools, etc.)

    • Optionalkwargs: Partial<GoogleGenerativeAIChatCallOptions>

      Additional configuration options

    Returns ChatGoogleGenerativeAIEx

    New ChatGoogleGenerativeAIEx instance with transformed tools

    const llmWithTools = llm.bindTools(mcpTools, { temperature: 0 });
    

    Set LANGCHAIN_GOOGLE_GENAI_EX_VERBOSE=true to see transformation details