@@ -120,18 +120,9 @@ def format_destination(
120120
121121def find_afc_incompatible_tool_indexes (
122122 config : Optional [types .GenerateContentConfigOrDict ] = None ,
123+ is_agent_platform : bool = False ,
123124) -> list [int ]:
124- """Checks if the config contains any AFC incompatible tools.
125-
126- A `types.Tool` object that contains `function_declarations` is considered a
127- non-AFC tool for this execution path.
128-
129- Args:
130- config: The GenerateContentConfig to check for incompatible tools.
131-
132- Returns:
133- A list of indexes of the incompatible tools in the config.
134- """
125+ """Checks if the config contains any AFC incompatible tools."""
135126 if not config :
136127 return []
137128 config_model = _create_generate_content_config_model (config )
@@ -143,9 +134,11 @@ def find_afc_incompatible_tool_indexes(
143134 for index , tool in enumerate (config_model .tools ):
144135 if not isinstance (tool , types .Tool ):
145136 continue
146- if tool . function_declarations :
137+ if getattr ( tool , ' function_declarations' , None ) :
147138 incompatible_tools_indexes .append (index )
148- if tool .mcp_servers :
139+
140+ # Only mark it incompatible if it's MLDev, not Agent Platform.
141+ if getattr (tool , 'mcp_servers' , None ) and not is_agent_platform :
149142 incompatible_tools_indexes .append (index )
150143 return incompatible_tools_indexes
151144
@@ -383,12 +376,15 @@ async def get_function_response_parts_async(
383376 if not part .function_call :
384377 continue
385378 func_name = part .function_call .name
386- if func_name is not None and part . function_call . args is not None :
379+ if func_name is not None :
387380 func = function_map [func_name ]
388- args = convert_number_values_for_dict_function_call_args (
381+ # Treat None as an empty dictionary for execution
382+ raw_args = (
389383 part .function_call .args
384+ if part .function_call .args is not None
385+ else {}
390386 )
391- func_response : _common . StringDict
387+ args = convert_number_values_for_dict_function_call_args ( raw_args )
392388 try :
393389 if isinstance (func , McpToGenAiToolAdapter ):
394390 mcp_tool_response = await func .call_tool (
@@ -409,7 +405,7 @@ async def get_function_response_parts_async(
409405 )
410406 }
411407 except Exception as e : # pylint: disable=broad-except
412- func_response = {'error' : str (e )}
408+ func_response = {'error' : str (e )} # type: ignore[dict-item]
413409 func_response_part = types .Part .from_function_response (
414410 name = func_name , response = func_response
415411 )
@@ -551,6 +547,7 @@ def parse_config_for_mcp_usage(
551547
552548async def parse_config_for_mcp_sessions (
553549 config : Optional [types .GenerateContentConfigOrDict ] = None ,
550+ is_agent_platform : bool = False ,
554551) -> tuple [
555552 Optional [types .GenerateContentConfig ],
556553 dict [str , McpToGenAiToolAdapter ],
@@ -571,7 +568,7 @@ async def parse_config_for_mcp_sessions(
571568 for tool in parsed_config .tools :
572569 if McpClientSession is not None and isinstance (tool , McpClientSession ):
573570 mcp_to_genai_tool_adapter = McpToGenAiToolAdapter (
574- tool , await tool .list_tools ()
571+ tool , await tool .list_tools (), is_agent_platform = is_agent_platform
575572 )
576573 # Extend the config with the MCP session tools converted to GenAI tools.
577574 parsed_config_copy .tools .extend (mcp_to_genai_tool_adapter .tools )
@@ -677,3 +674,19 @@ def prepare_resumable_upload(
677674 http_options .headers = {}
678675 http_options .headers ['X-Goog-Upload-File-Name' ] = os .path .basename (file )
679676 return http_options , size_bytes , mime_type
677+
678+
679+ def has_agent_platform_mcp_servers (
680+ config : Optional [types .GenerateContentConfigOrDict ] = None ,
681+ ) -> bool :
682+ """Checks whether the configuration contains any MCP server requests."""
683+ if not config :
684+ return False
685+ config_model = _create_generate_content_config_model (config )
686+ if not config_model .tools :
687+ return False
688+
689+ for tool in config_model .tools :
690+ if getattr (tool , 'mcp_servers' , None ):
691+ return True
692+ return False
0 commit comments