11import os
22import shutil
3- from typing import Tuple , Optional , List
3+ from typing import List , Optional , Tuple
44
55import click
66from uipath ._cli ._utils ._console import ConsoleLogger
77from uipath ._cli .middlewares import MiddlewareResult
88
99console = ConsoleLogger ()
1010
11+
1112def clean_directory (directory : str ) -> None :
1213 """Clean up Python files in the specified directory.
1314
@@ -20,11 +21,17 @@ def clean_directory(directory: str) -> None:
2021 for file_name in os .listdir (directory ):
2122 file_path = os .path .join (directory , file_name )
2223
23- if os .path .isfile (file_path ) and file_name .endswith (' .py' ):
24+ if os .path .isfile (file_path ) and file_name .endswith (" .py" ):
2425 # Delete the file
2526 os .remove (file_path )
2627
27- def write_template_file (target_directory :str , file_path : str , file_name : str , replace_tuple : Optional [List [Tuple [str , str ]]] = None ) -> None :
28+
29+ def write_template_file (
30+ target_directory : str ,
31+ file_path : str ,
32+ file_name : str ,
33+ replace_tuple : Optional [List [Tuple [str , str ]]] = None ,
34+ ) -> None :
2835 """Write a template file to the target directory with optional placeholder replacements.
2936
3037 Args:
@@ -37,9 +44,7 @@ def write_template_file(target_directory:str, file_path: str, file_name: str, re
3744 This function copies a template file to the target directory and optionally replaces placeholders
3845 with specified values. It logs a success message after creating the file.
3946 """
40- template_path = os .path .join (
41- os .path .dirname (__file__ ), file_path
42- )
47+ template_path = os .path .join (os .path .dirname (__file__ ), file_path )
4348 target_path = os .path .join (target_directory , file_name )
4449 if replace_tuple is not None :
4550 # replace the template placeholders
@@ -67,24 +72,22 @@ def generate_files(target_directory: str, server_name: str):
6772 - pyproject.toml: Project metadata and dependencies
6873 """
6974 write_template_file (
70- target_directory ,
71- "_templates/server.py.template" ,
72- "server.py" ,
73- None
75+ target_directory , "_templates/server.py.template" , "server.py" , None
7476 )
7577 write_template_file (
7678 target_directory ,
7779 "_templates/mcp.json.template" ,
7880 "mcp.json" ,
79- [("$server_name" , server_name )]
81+ [("$server_name" , server_name )],
8082 )
8183 write_template_file (
8284 target_directory ,
8385 "_templates/pyproject.toml.template" ,
8486 "pyproject.toml" ,
85- [("$project_name" , server_name )]
87+ [("$project_name" , server_name )],
8688 )
8789
90+
8891def mcp_new_middleware (name : str ) -> MiddlewareResult :
8992 """Create a new MCP server project with template files.
9093
@@ -105,7 +108,9 @@ def mcp_new_middleware(name: str) -> MiddlewareResult:
105108 directory = os .getcwd ()
106109
107110 try :
108- with console .spinner (f"Creating new mcp server '{ name } ' in current directory ..." ):
111+ with console .spinner (
112+ f"Creating new mcp server '{ name } ' in current directory ..."
113+ ):
109114 clean_directory (directory )
110115 generate_files (directory , name )
111116 init_command = """uipath init"""
@@ -117,11 +122,21 @@ def mcp_new_middleware(name: str) -> MiddlewareResult:
117122 line = click .style ("═" * 60 , bold = True )
118123
119124 console .info (line )
120- console .info (click .style (f"""Start '{ name } ' as a self-hosted MCP server""" , fg = "magenta" , bold = True ))
125+ console .info (
126+ click .style (
127+ f"""Start '{ name } ' as a self-hosted MCP server""" ,
128+ fg = "magenta" ,
129+ bold = True ,
130+ )
131+ )
121132 console .info (line )
122133
123- console .hint (f""" 1. Set { click .style ("UIPATH_FOLDER_PATH" , fg = "cyan" )} environment variable""" )
124- console .hint (f""" 2. Start the server locally: { click .style (run_command , fg = "cyan" )} """ )
134+ console .hint (
135+ f""" 1. Set { click .style ("UIPATH_FOLDER_PATH" , fg = "cyan" )} environment variable"""
136+ )
137+ console .hint (
138+ f""" 2. Start the server locally: { click .style (run_command , fg = "cyan" )} """
139+ )
125140 return MiddlewareResult (should_continue = False )
126141 except Exception as e :
127142 console .error (f"Error creating demo agent { str (e )} " )
0 commit comments