This library provides a drop-in replacement for ChatGoogle from @langchain/google
that fixes Gemini function-calling schema errors when using LangChain.js with MCP servers.
It automatically transforms MCP tool schemas with unsupported constructs into
Gemini-compatible function-calling schemas at tool binding time.
The schema error usually appears as either a Gemini API request error:
RequestError: Invalid JSON payload received.
Unknown name "exclusiveMaximum" ...
Unknown name "exclusiveMinimum" ...
or a LangChain-side schema validation error before the request is sent:
InvalidInputError: Gemini does not support union types in function schemas.
Use a single type instead.
This commonly appears when tools from MultiServerMCPClient include schemas that are valid
JSON Schema but outside Gemini's supported OpenAPI-like subset.
Replace:
import { ChatGoogle } from "@langchain/google/node";
const model = new ChatGoogle({ model: "gemini-3.5-flash" });with:
import { ChatGoogleEx } from "@h1deya/langchain-google-ex";
const model = new ChatGoogleEx({ model: "gemini-3.5-flash" });That's it. Keep passing the original MCP tools to LangChain:
const mcpTools = await client.getTools();
const agent = createAgent({ model, tools: mcpTools });ChatGoogleEx transforms the tool schemas inside bindTools(), preserving the original
LangChain tool objects and their execution behavior.
When using a Google AI Studio / Gemini Developer API key, pass it explicitly:
const model = new ChatGoogleEx({
model: "gemini-3.5-flash",
apiKey: process.env.GOOGLE_API_KEY,
});This avoids accidentally falling back to Vertex AI / Google Cloud authentication when the
environment is not configured the way @langchain/google expects.
A simple usage example, which is ready to clone and run, can be found here.
This library is intentionally focused on
@langchain/googleusers who need a drop-in replacement forChatGoogleAI. If you use@langchain/google-genai, see the companion@h1deya/langchain-google-genai-expackage instead.This library addresses compatibility issues present as of August 25, 2026, with
langchainv1.5.10,@langchain/googlev0.2.3, and@langchain/mcp-adaptersv1.1.4.
- Node.js 20+
- Google API key configured for
@langchain/google @langchain/google,langchain, and@langchain/mcp-adapters- MCP servers you want to use
Tested with @langchain/google@0.2.3, langchain@1.5.10, and
@langchain/mcp-adapters@1.1.4.
npm i @h1deya/langchain-google-ex @langchain/google langchain @langchain/mcp-adapters// import { ChatGoogle } from "@langchain/google/node";
import { ChatGoogleEx } from "@h1deya/langchain-google-ex";
import { createAgent } from "langchain";
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
const client = new MultiServerMCPClient({
throwOnLoadError: true,
useStandardContentBlocks: true,
mcpServers: {
fetch: {
transport: "stdio",
command: "uvx",
args: ["--with", "mcp<2", "mcp-server-fetch==2025.4.7"],
},
},
});
(async () => { // workaround for top-level await
try {
const mcpTools = await client.getTools();
// const model = new ChatGoogle({
const model = new ChatGoogleEx({
model: "gemini-3.5-flash",
apiKey: process.env.GOOGLE_API_KEY,
});
const agent = createAgent({ model, tools: mcpTools });
const result = await agent.invoke({
messages: [
{
role: "user",
content: "Fetch the raw HTML content from bbc.com and tell me the title",
},
],
});
console.log(result.messages.at(-1)?.content);
} finally {
await client.close();
}
})();A simple usage example, which is ready to clone and run, can be found here.
Gemini's function-calling schema format accepts only a subset of JSON Schema. Some MCP
servers publish schemas containing fields such as exclusiveMinimum, exclusiveMaximum,
propertyNames, additionalProperties, or complex union shapes. Those schemas can be
rejected before any tool call runs.
@langchain/google already performs some schema normalization, but current versions still
pass through schema keywords that Gemini rejects in MCP tool definitions. ChatGoogleEx
adds a compatibility layer for those cases.
MCP servers that have shown this kind of issue include:
airtable-mcp-servermcp-server-fetch==2025.4.7- GitHub Copilot MCP server
@notionhq/notion-mcp-server
In local integration tests, simple schemas such as a weather MCP server worked with both
ChatGoogle and ChatGoogleEx. More complex schemas from Fetch, Airtable, and GitHub
failed with ChatGoogle and succeeded with ChatGoogleEx.
Set this environment variable to see schema transformations:
LANGCHAIN_GOOGLE_EX_VERBOSE=trueExample output:
Transforming 3 MCP tool(s) for Gemini compatibility...
fetch: 2 exclusive bound(s) converted, 1 unsupported format(s) removed
Summary: 1/3 tool(s) required schema transformation
- Drop-in replacement for
ChatGoogle - Automatic MCP tool schema transformation at
bindTools()time - Preserves original LangChain tool objects
- Converts type arrays such as
["string", "null"]to nullable schemas - Filters invalid
requiredfields - Removes or converts unsupported JSON Schema keywords
- Resolves local
$ref,$defs, anddefinitionswhere possible
- Unresolved references are simplified to generic object schemas.
- Tuple-style arrays keep only the first item schema.
- Non-string enum values are dropped.
- Complex
oneOf/allOfschemas may be simplified, which can loosen validation.
These adjustments keep most MCP tools working, but rare edge cases could behave differently from the original schema. Please report issues at GitHub Issues.
See DESIGN_DECISIONS.md for implementation details.
- A simple usage example which is ready to clone and run
- Design decision document describes the implementation details
Issues and pull requests welcome!
In particular, please share any issues relating to the latest versions of LLM models and specific MCP servers.