-
Notifications
You must be signed in to change notification settings - Fork 697
Description
Environment details
Programming language: Python
OS: macOS Darwin 24.6.0 / Linux
Language runtime version: Python 3.11 / 3.13
Package version: google-genai==1.53.0
MCP packages: mcp==1.9.4, databricks-mcp==0.3.0
Model: gemini-2.5-pro
Issue details
When using automatic function calling with MCP tools that have session-specific UUID identifiers, the Google GenAI SDK randomly corrupts func names during the function calling process. This causes KeyError exceptions when the SDK attempts to look up the corrupted name in the function_map.
The SDK corrupts func names in unpredictable ways during automatic function calling:
- Leading/trailing whitespace: Adds spaces before func names.
- UUID corruption: Inserts underscores, hyphens, or modifies characters within the UUID portion
- Character replacement: Changes valid hex digits to invalid characters
Examples
MCP session creates the name poll_response_01f0aa74324312bbaef790169f0ef410
Error from SDK
KeyError: 'poll_response_01f0aa74324312bbaef790169f0ef4-10'
Expected name: poll_response_01f0aa74324312bbaef790169f0ef410
Actual lookup name: poll_response_01f0aa74324312bbaef790169f0ef4-10
More detailed error:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/google/genai/models.py", line 7054, in generate_content
await _extra_utils.get_function_response_parts_async(
File "/usr/local/lib/python3.11/site-packages/google/genai/_extra_utils.py", line 384, in get_function_response_parts_async
func = function_map[func_name]
│ └ 'poll_response_01f0aa74324312bbaef790169f0ef4-10' # , <- CORRUPTED
└ {
'query_space_01f0aa74324312bbaef790169f0ef410': <McpToGenAiToolAdapter>,
'poll_response_01f0aa74324312bbaef790169f0ef410': <McpToGenAiToolAdapter> # <- CORRECT
}
KeyError: 'poll_response_01f0aa74324312bbaef790169f0ef4-10'Expected Behavior
- When using automatic function calling, func names from MCP's
list_tools()should be used exactly as provided when: - The LLM generates a function call in its response
- The SDK looks up the tool in
function_map. - The SDK calls
session.call_tool(name, arguments) - The SDK should perform exact string matching without any transformations.
Actual Behavior
- The SDK corrupts names between the LLM response and the
function_map lookup, causing KeyError
Corruption patterns observed:
- Character replacement:
poll_response_...ef410->poll_response_...ef4-10(last 3 chars become -10) - Leading whitespace:
poll_response_...->poll_response_...(space added at start) - UUID mangling:
poll_response_01f083de8626... ->poll_response_01f_083_de_8626...(underscores inserted randomly)
Key finding: The corruption is non-deterministic - the same func name may work correctly on one call but get corrupted on the next.
Steps to Reproduce
- Create an MCP session with a server that generates UUID-based tool names (e.g., databricks genie MCP)
- Create a Gemini client with automatic function calling enabled
- Make the first request passing the MCP session as a tool
- Automatic function calling completes (may succeed or fail randomly)
- Close the MCP session
- Open a NEW MCP session (with new UUID-based tool names)
- Build conversation history from the first request
- Make the second request with the new MCP session and conversation history
- Bug may occur - SDK corrupts the UUID portion of the func name
- KeyError is raised when SDK tries to look up the corrupted func name
Expected Behavior
The SDK should preserve the exact func name returned by the current MCP session.
Actual Behavior
The SDK non-deterministically corrupts UUID portions of func names. The bug can occur on any request (1st, 2nd, 3rd, 4th) randomly:
- Sometimes fails on 1st request
- Sometimes succeeds on 1st but fails on 2nd
- Sometimes succeeds on 1st and 2nd but fails on 3rd
- Sometimes fails on 2nd and 3rd but succeeds on 4th
- Failure rate: approximately 30% of requests
Common corruption patterns include character splits with hyphens, leading spaces, or random underscores inserted into UUIDs.