import { ChatGoogleGenerativeAI, GoogleGenerativeAIChatCallOptions } from '@langchain/google-genai'; /** * 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. * * ## Usage: * ```typescript * // 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({...}); * ``` * * ## Verbose Logging: * Set environment variable to see transformation details: * ```bash * 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 * ``` * * ## What Gets Fixed: * - "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 * * ## Key Benefits: * - 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 * * ## Known Limitations: * - **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. */ declare class ChatGoogleGenerativeAIEx extends ChatGoogleGenerativeAI { private static transformCache; private static simpleHash; /** * Binds tools with automatic schema transformation. * * This overridden method specifically handles tool binding after automatically * transforming all tools for Gemini compatibility. * * @param tools - Array of tools to bind (MCP tools, StructuredTools, etc.) * @param kwargs - Additional configuration options * @returns New ChatGoogleGenerativeAIEx instance with transformed tools * * @example * ```typescript * const llmWithTools = llm.bindTools(mcpTools, { temperature: 0 }); * ``` * * @note Set LANGCHAIN_GOOGLE_GENAI_EX_VERBOSE=true to see transformation details */ bindTools(tools: any[], kwargs?: Partial): ChatGoogleGenerativeAIEx; } export { ChatGoogleGenerativeAIEx };