@@ -233,22 +233,32 @@ async def create(
233233 kwargs = use_kwargs
234234 from_coder .ok_to_warm_cache = False
235235
236+ res = None
236237 if (
237238 getattr (main_model , "copy_paste_mode" , False )
238239 and getattr (main_model , "copy_paste_transport" , "api" ) == "clipboard"
239240 ):
240241 res = coders .CopyPasteCoder (main_model , io , args = args , ** kwargs )
242+
243+ if not res :
244+ for coder in coders .__all__ :
245+ if hasattr (coder , "edit_format" ) and coder .edit_format == edit_format :
246+ res = coder (main_model , io , args = args , ** kwargs )
247+
248+ if res is not None :
249+ if from_coder :
250+ if from_coder .mcp_servers and kwargs .get ("mcp_servers" , False ):
251+ res .mcp_servers = from_coder .mcp_servers
252+ res .mcp_tools = from_coder .mcp_tools
253+
254+ # Transfer TUI app weak reference
255+ res .tui = from_coder .tui
256+
241257 await res .initialize_mcp_tools ()
258+
242259 res .original_kwargs = dict (kwargs )
243260 return res
244261
245- for coder in coders .__all__ :
246- if hasattr (coder , "edit_format" ) and coder .edit_format == edit_format :
247- res = coder (main_model , io , args = args , ** kwargs )
248- await res .initialize_mcp_tools ()
249- res .original_kwargs = dict (kwargs )
250- return res
251-
252262 valid_formats = [
253263 str (c .edit_format )
254264 for c in coders .__all__
@@ -2703,6 +2713,12 @@ async def initialize_mcp_tools(self):
27032713 tools = []
27042714
27052715 async def get_server_tools (server ):
2716+ # Check if we already have tools for this server in mcp_tools
2717+ if self .mcp_tools :
2718+ for server_name , server_tools in self .mcp_tools :
2719+ if server_name == server .name :
2720+ return (server .name , server_tools )
2721+
27062722 try :
27072723 session = await server .connect ()
27082724 server_tools = await experimental_mcp_client .load_mcp_tools (
@@ -3266,8 +3282,20 @@ def consolidate_chunks(self):
32663282 self .partial_response_reasoning_content = reasoning_content or ""
32673283
32683284 try :
3269- if not self .partial_response_reasoning_content :
3270- self .partial_response_content = response .choices [0 ].message .content or ""
3285+ content = response .choices [0 ].message .content
3286+ if isinstance (content , list ):
3287+ # OpenAI-compatible APIs sometimes return content as a list
3288+ # of blocks; join the textual pieces for display.
3289+ content = "" .join (
3290+ block .get ("text" , "" )
3291+ for block in content
3292+ if isinstance (block , dict ) and block .get ("type" ) == "output_text"
3293+ ) or "" .join (
3294+ block .get ("text" , "" )
3295+ for block in content
3296+ if isinstance (block , dict ) and block .get ("type" ) == "text"
3297+ )
3298+ self .partial_response_content = content or ""
32713299 except AttributeError as e :
32723300 content_err = e
32733301
0 commit comments