@@ -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 )
@@ -145,7 +136,9 @@ def find_afc_incompatible_tool_indexes(
145136 continue
146137 if tool .function_declarations :
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 tool .mcp_servers and not is_agent_platform :
149142 incompatible_tools_indexes .append (index )
150143 return incompatible_tools_indexes
151144
@@ -551,6 +544,7 @@ def parse_config_for_mcp_usage(
551544
552545async def parse_config_for_mcp_sessions (
553546 config : Optional [types .GenerateContentConfigOrDict ] = None ,
547+ is_agent_platform : bool = False ,
554548) -> tuple [
555549 Optional [types .GenerateContentConfig ],
556550 dict [str , McpToGenAiToolAdapter ],
@@ -571,7 +565,7 @@ async def parse_config_for_mcp_sessions(
571565 for tool in parsed_config .tools :
572566 if McpClientSession is not None and isinstance (tool , McpClientSession ):
573567 mcp_to_genai_tool_adapter = McpToGenAiToolAdapter (
574- tool , await tool .list_tools ()
568+ tool , await tool .list_tools (), is_agent_platform = is_agent_platform
575569 )
576570 # Extend the config with the MCP session tools converted to GenAI tools.
577571 parsed_config_copy .tools .extend (mcp_to_genai_tool_adapter .tools )
@@ -677,3 +671,19 @@ def prepare_resumable_upload(
677671 http_options .headers = {}
678672 http_options .headers ['X-Goog-Upload-File-Name' ] = os .path .basename (file )
679673 return http_options , size_bytes , mime_type
674+
675+
676+ def has_agent_platform_mcp_servers (
677+ config : Optional [types .GenerateContentConfigOrDict ] = None ,
678+ ) -> bool :
679+ """Checks whether the configuration contains any MCP server requests."""
680+ if not config :
681+ return False
682+ config_model = _create_generate_content_config_model (config )
683+ if not config_model .tools :
684+ return False
685+
686+ for tool in config_model .tools :
687+ if isinstance (tool , types .Tool ) and tool .mcp_servers :
688+ return True
689+ return False
0 commit comments