1414from mcpm .core .tunnel import Tunnel
1515from mcpm .fastmcp_integration .proxy import create_mcpm_proxy
1616from mcpm .global_config import GlobalConfigManager
17- from mcpm .utils .config import DEFAULT_SHARE_ADDRESS , DEFAULT_PORT
18- from mcpm .utils .logging_config import setup_dependency_logging , ensure_dependency_logging_suppressed , get_uvicorn_log_level
17+ from mcpm .utils .config import DEFAULT_PORT , DEFAULT_SHARE_ADDRESS
18+ from mcpm .utils .logging_config import (
19+ ensure_dependency_logging_suppressed ,
20+ get_uvicorn_log_level ,
21+ setup_dependency_logging ,
22+ )
1923
2024console = Console ()
2125global_config_manager = GlobalConfigManager ()
@@ -49,7 +53,9 @@ async def find_available_port(preferred_port, max_attempts=10):
4953 return preferred_port
5054
5155
52- async def start_fastmcp_proxy (server_config , server_name , port : Optional [int ] = None , auth_enabled : bool = True , api_key : Optional [str ] = None ) -> int :
56+ async def start_fastmcp_proxy (
57+ server_config , server_name , port : Optional [int ] = None , auth_enabled : bool = True , api_key : Optional [str ] = None
58+ ) -> int :
5359 """
5460 Start FastMCP proxy in HTTP mode for sharing a single server.
5561
@@ -89,10 +95,10 @@ async def start_fastmcp_proxy(server_config, server_name, port: Optional[int] =
8995 )
9096
9197 logger .debug (f"FastMCP proxy ready on port { actual_port } " )
92-
98+
9399 # Set up dependency logging for FastMCP/MCP libraries
94100 setup_dependency_logging ()
95-
101+
96102 # Re-suppress library logging after FastMCP initialization
97103 ensure_dependency_logging_suppressed ()
98104
@@ -182,6 +188,7 @@ async def _share_async(server_config, server_name, port, remote_host, remote_por
182188
183189 if not no_auth :
184190 from mcpm .utils .config import ConfigManager
191+
185192 config_manager = ConfigManager ()
186193 auth_config = config_manager .get_auth_config ()
187194 api_key = auth_config .get ("api_key" )
@@ -193,10 +200,14 @@ async def _share_async(server_config, server_name, port, remote_host, remote_por
193200 try :
194201 # Start FastMCP proxy
195202 logger .debug (f"Starting FastMCP proxy to share server '{ server_name } '" )
196- actual_port , proxy = await start_fastmcp_proxy (server_config , server_name , port , auth_enabled = not no_auth , api_key = api_key )
203+ actual_port , proxy = await start_fastmcp_proxy (
204+ server_config , server_name , port , auth_enabled = not no_auth , api_key = api_key
205+ )
197206
198207 # Start the FastMCP proxy as an HTTP server in a background task
199- server_task = asyncio .create_task (proxy .run_http_async (port = actual_port , uvicorn_config = {"log_level" : get_uvicorn_log_level ()}))
208+ server_task = asyncio .create_task (
209+ proxy .run_http_async (port = actual_port , uvicorn_config = {"log_level" : get_uvicorn_log_level ()})
210+ )
200211
201212 # Wait a moment for server to start
202213 await asyncio .sleep (2 )
@@ -223,12 +234,12 @@ async def _share_async(server_config, server_name, port, remote_host, remote_por
223234 http_url = f"{ share_url } /mcp/"
224235 console .print (f"[bold green]Server '{ server_name } ' is now shared at:[/]" )
225236 console .print (f"[cyan]{ http_url } [/]" )
226-
237+
227238 if not no_auth and api_key :
228239 console .print (f"[bold green]API Key:[/] [cyan]{ api_key } [/]" )
229240 else :
230241 console .print ("[bold red]Warning:[/] Anyone with the URL can access your server." )
231-
242+
232243 console .print ("[dim]Press Ctrl+C to stop sharing[/]" )
233244
234245 # Keep running until interrupted
0 commit comments