langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Gemini with MCP tools sporadically returns errors 400

Open omerabr opened this issue 1 year ago • 3 comments

Bug Description

This is happening only with Gemini models. OpenAI works fine under the same simple setup.

s/grpc/aio/_call.py", line 272, in
_raise_for_status
raise _create_rpc_error(
-> <function
_create_rpc_error at 0xec18345ef060>

                         grpc.aio._call.AioRpcError:                        
                         <AioRpcError of RPC that terminated                
                         with:                                              
                                 status =                                   
                         StatusCode.INVALID_ARGUMENT                        
                                 details = "*                               
                         GenerateContentRequest.contents[3].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[4].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[5].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[6].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[7].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[8].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[9].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[10].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[11].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[12].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[13].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[14].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[15].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         *                                                  
                         GenerateContentRequest.contents[16].par            
                         ts[0].function_response.name: Name                 
                         cannot be empty.                                   
                         "                                                  
                                 debug_error_string =                       
                         "UNKNOWN:Error received from peer                  
                         ipv4:142.250.75.138:443                            
                         {created_time:"2025-08-19T06:37:10.6152            
                         16388+00:00", grpc_status:3,                       
                         grpc_message:"*                                    
                         GenerateContentRequest.contents[3].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.\n*                                
                         GenerateContentRequest.contents[4].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.\n*                                
                         GenerateContentRequest.contents[5].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.\n*                                
                         GenerateContentRequest.contents[6].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.\n*                                
                         GenerateContentRequest.contents[7].part            
                         s[0].function_response.name: Name                  
                         cannot be empty.\n*                                
                         GenerateContentRequest.contents[8].part            
                         s[0].function_response.name: Name                  

-- │ 270 │ │ code = await self.cod │
│ 271 │ │ if code != grpc.Statu │
│ ❱ 272 │ │ │ raise _create_rpc │
│ 273 │ │ │ │ await self.in │
│ 274 │ │ │ ) │
│ 275 │
╰─────────────────────────────────────╯
AioRpcError: <AioRpcError of RPC that
terminated with:
status =
StatusCode.INVALID_ARGUMENT
details = "*
GenerateContentRequest.contents[3].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[4].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[5].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[6].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[7].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[8].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[9].part
s[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[10].par
ts[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[11].par
ts[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[12].par
ts[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[13].par
ts[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[14].par
ts[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[15].par
ts[0].function_response.name: Name
cannot be empty.
*
GenerateContentRequest.contents[16].par
ts[0].function_response.name: Name
cannot be empty.
"
debug_error_string =
"UNKNOWN:Error received from peer
ipv4:142.250.75.138:443
{created_time:"2025-08-19T06:37:10.6152
16388+00:00", grpc_status:3,
grpc_message:"*
GenerateContentRequest.contents[3].part
s[0].function_response.name: Name
cannot be empty.\n*
GenerateContentRequest.contents[4].part
s[0].function_response.name: Name
cannot be empty.\n*
GenerateContentRequest.contents[5].part
s[0].function_response.name: Name
cannot be empty.\n*
GenerateContentRequest.contents[6].part
s[0].function_response.name: Name
cannot be empty.\n*
GenerateContentRequest.contents[7].part
s[0].function_response.name: Name
cannot be empty.\n*
GenerateContentRequest.contents[8].part
s[0].function_response.name: Name

Reproduction

  1. Setup https://github.com/nolleh/mcp-vertica
  2. Add an MCP tool pointing to Vertica MCP
  3. Add an Agent with Gemini pro preview 2.5 06-05, switch Tool Model Enabled = true
  4. Run the flow
  5. Sometimes it's working fine, sometimes it throws this errors.

Expected behavior

Work seamlessly like with OpenAI models.

Who can help?

@italojohnny @lucaseduoli

Operating System

MacOS 15.6 (24G84)

Langflow Version

1.5.0.post1 (Docker)

Python Version

None

Screenshot

Image

Flow File

No response

omerabr avatar Aug 19 '25 06:08 omerabr

Hi @omerabr,

Thank you for reporting this issue with Gemini models and MCP tools. This is a confirmed compatibility problem between Google's Gemini API requirements and Langflow's MCP tool message handling.

Root Cause Identified

The error you're encountering:

GenerateContentRequest.contents[X].parts[0].function_response.name: Name cannot be empty

This occurs due to missing tool message handling in Langflow's message conversion system:

1. Missing Tool Message Type Handling

Located in src/backend/base/langflow/schema/message.py:156-170:

  • The from_lc_message method only handles "human", "ai", and "system" message types
  • No handling for "tool" message types which carry function responses
  • This causes function response names to be empty when sent to Gemini

2. Gemini vs OpenAI Differences

  • OpenAI: More permissive, accepts function responses without strict name validation
  • Gemini: Requires explicit function_response.name field to be populated
  • Validation: Gemini's API strictly validates and rejects empty name fields

3. MCP Tool Result Formatting

The MCP component returns raw tool results without proper message wrapping:

  • Tool results are not converted to proper ToolMessage objects
  • Missing the required name field that Gemini expects

Why It's Intermittent

The sporadic nature occurs because:

  • Some tool calls may include name fields by chance
  • Error only triggers when multiple function responses accumulate without names
  • OpenAI works fine because it doesn't enforce this validation

Immediate Workarounds

Option 1: Use OpenAI Models (Recommended)

  • Switch to OpenAI models which don't have this strict validation
  • Works seamlessly with current MCP implementation

Option 2: Disable Tool Mode

  • Set Tool Model Enabled = false in your Agent component
  • This prevents MCP tools from being passed to Gemini

Option 3: Wait for Fix

  • Monitor issue #9437 for updates
  • Related issue #9309 also tracks Gemini MCP tool registration problems

Technical Details

Files requiring modification:

  • src/backend/base/langflow/schema/message.py - Add tool message handling
  • src/backend/base/langflow/base/mcp/util.py - Format tool responses properly
  • Message conversion needs to populate function_response.name for Gemini compatibility

Expected Resolution

This requires updates to:

  1. Extend message conversion to handle tool message types
  2. Populate function response names for Gemini compatibility
  3. Add LLM-specific formatting for different providers

Related Issues

  • Issue #9437 (this issue) - Gemini MCP error 400
  • Issue #9309 - Gemini API not registering MCP tools

Thank you for the detailed error report - it clearly shows the validation failures from Gemini's API.

Best regards

Vigtu avatar Aug 23 '25 00:08 Vigtu

Hi @omerabr,

Thank you for reporting this issue with Gemini models and MCP tools. This is a confirmed compatibility problem between Google's Gemini API requirements and Langflow's MCP tool message handling.

Root Cause Identified

The error you're encountering:

GenerateContentRequest.contents[X].parts[0].function_response.name: Name cannot be empty

This occurs due to missing tool message handling in Langflow's message conversion system:

1. Missing Tool Message Type Handling

Located in src/backend/base/langflow/schema/message.py:156-170:

  • The from_lc_message method only handles "human", "ai", and "system" message types
  • No handling for "tool" message types which carry function responses
  • This causes function response names to be empty when sent to Gemini

2. Gemini vs OpenAI Differences

  • OpenAI: More permissive, accepts function responses without strict name validation
  • Gemini: Requires explicit function_response.name field to be populated
  • Validation: Gemini's API strictly validates and rejects empty name fields

3. MCP Tool Result Formatting

The MCP component returns raw tool results without proper message wrapping:

  • Tool results are not converted to proper ToolMessage objects
  • Missing the required name field that Gemini expects

Why It's Intermittent

The sporadic nature occurs because:

  • Some tool calls may include name fields by chance
  • Error only triggers when multiple function responses accumulate without names
  • OpenAI works fine because it doesn't enforce this validation

Immediate Workarounds

Option 1: Use OpenAI Models (Recommended)

  • Switch to OpenAI models which don't have this strict validation
  • Works seamlessly with current MCP implementation

Option 2: Disable Tool Mode

  • Set Tool Model Enabled = false in your Agent component
  • This prevents MCP tools from being passed to Gemini

Option 3: Wait for Fix

  • Monitor issue #9437 for updates
  • Related issue #9309 also tracks Gemini MCP tool registration problems

Technical Details

Files requiring modification:

  • src/backend/base/langflow/schema/message.py - Add tool message handling
  • src/backend/base/langflow/base/mcp/util.py - Format tool responses properly
  • Message conversion needs to populate function_response.name for Gemini compatibility

Expected Resolution

This requires updates to:

  1. Extend message conversion to handle tool message types
  2. Populate function response names for Gemini compatibility
  3. Add LLM-specific formatting for different providers

Related Issues

  • Issue #9437 (this issue) - Gemini MCP error 400
  • Issue #9309 - Gemini API not registering MCP tools

Thank you for the detailed error report - it clearly shows the validation failures from Gemini's API.

Best regards

Thanks @Vigtu for confirming. Looking forward to having this resolved soon as we heavily relay on Gemini. Thanks again!

omerabr avatar Aug 24 '25 12:08 omerabr

Hi @omerabr,

I tried to reproduce this on Langflow v1.9.0 with the following setup:

  • Agent component using Gemini 3 Pro Preview
  • Two MCP servers connected via component_as_tool: Tavily (HTTP/SSE) and a local MCP server (STDIO)
  • Ran 15 different prompts in sequence, each one triggering at least one tool call, some triggering multiple sequential tool calls All 15 runs completed successfully with proper tool invocations and responses - no function_response.name: Name cannot be empty errors, no 400s from the Gemini API.

Could you try again on v1.9.0 and let us know if it's still happening for you?

I'm closing this as resolved. If the issue is still happening for you, please share the following and I'll reopen it:

Exact Langflow version Gemini model name Flow export (or at least the MCP server type/transport you're using) Full error traceback

lice-reis avatar Apr 16 '26 18:04 lice-reis