@@ -228,6 +228,36 @@ def spring_ai_zip(provider, ll_config, embed_config):
228228 zip_buffer .seek (0 )
229229 return zip_buffer
230230
231+ def langchain_mcp_zip (settings ):
232+ """Create LangChain MCP Zip File"""
233+
234+ # Source directory that you want to copy
235+ src_dir = Path (__file__ ).resolve ().parents [2 ] / "mcp/rag"
236+
237+ # Using TemporaryDirectory
238+ with tempfile .TemporaryDirectory () as temp_dir :
239+ dst_dir = os .path .join (temp_dir , "langchain_mcp" )
240+ logger .info ("Starting langchain mcp zip processing: %s" , dst_dir )
241+
242+ shutil .copytree (src_dir , dst_dir )
243+
244+ data = save_settings (settings )
245+ settings_path = os .path .join (dst_dir , "optimizer_settings.json" )
246+ with open (settings_path , "w" ) as f :
247+ f .write (data )
248+
249+ zip_buffer = io .BytesIO ()
250+ with zipfile .ZipFile (zip_buffer , "w" , zipfile .ZIP_DEFLATED ) as zip_file :
251+ for foldername , _ , filenames in os .walk (dst_dir ):
252+ for filename in filenames :
253+ file_path = os .path .join (foldername , filename )
254+
255+ arc_name = os .path .relpath (file_path , dst_dir ) # Make the path relative
256+ zip_file .write (file_path , arc_name )
257+ zip_buffer .seek (0 )
258+ return zip_buffer
259+
260+
231261
232262#####################################################
233263# MAIN
@@ -284,7 +314,7 @@ def main():
284314 else :
285315 st .info ("Please upload a Settings file." )
286316
287- st .header ("SpringAI Settings " , divider = "red" )
317+ st .header ("Export source code templates " , divider = "red" )
288318 # Merge the User Settings into the Model Config
289319 model_lookup = st_common .state_configs_lookup ("model_configs" , "id" )
290320 try :
@@ -307,13 +337,23 @@ def main():
307337 - Embedding Model: **{ embed_config .get ("model" , "Unset" )} **
308338 """ )
309339 else :
310- st .download_button (
340+ col_left , col_centre , _ = st .columns ([3 , 4 , 3 ])
341+ with col_left :
342+ st .download_button (
311343 label = "Download SpringAI" ,
312344 data = spring_ai_zip (spring_ai_conf , ll_config , embed_config ), # Generate zip on the fly
313345 file_name = "spring_ai.zip" , # Zip file name
314346 mime = "application/zip" , # Mime type for zip file
315347 disabled = spring_ai_conf == "hybrid" ,
316348 )
349+ with col_centre :
350+ st .download_button (
351+ label = "Download LangchainMCP" ,
352+ data = langchain_mcp_zip (settings ), # Generate zip on the fly
353+ file_name = "langchain_mcp.zip" , # Zip file name
354+ mime = "application/zip" , # Mime type for zip file
355+ disabled = spring_ai_conf == "hybrid" ,
356+ )
317357
318358
319359if __name__ == "__main__" or "page.py" in inspect .stack ()[1 ].filename :
0 commit comments