17
17
18
18
from mcpm .clients .client_registry import ClientRegistry
19
19
from mcpm .router .share import Tunnel
20
- from mcpm .utils .config import ConfigManager
20
+ from mcpm .utils .config import MCPM_AUTH_HEADER , MCPM_PROFILE_HEADER , ConfigManager
21
21
from mcpm .utils .platform import get_log_directory , get_pid_directory
22
22
23
23
logging .basicConfig (level = logging .INFO , format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
@@ -116,8 +116,9 @@ def router():
116
116
117
117
@router .command (name = "on" )
118
118
@click .help_option ("-h" , "--help" )
119
+ @click .option ("--sse" , "-s" , is_flag = True , help = "Use SSE endpoint(deprecated)" )
119
120
@click .option ("--verbose" , "-v" , is_flag = True , help = "Enable verbose output" )
120
- def start_router (verbose ):
121
+ def start_router (sse , verbose ):
121
122
"""Start MCPRouter as a daemon process.
122
123
123
124
Example:
@@ -140,12 +141,17 @@ def start_router(verbose):
140
141
auth_enabled = config .get ("auth_enabled" , False )
141
142
api_key = config .get ("api_key" )
142
143
144
+ if sse :
145
+ app_path = "mcpm.router.sse_app:app"
146
+ else :
147
+ app_path = "mcpm.router.app:app"
148
+
143
149
# prepare uvicorn command
144
150
uvicorn_cmd = [
145
151
sys .executable ,
146
152
"-m" ,
147
153
"uvicorn" ,
148
- "mcpm.router.app:app" ,
154
+ app_path ,
149
155
"--host" ,
150
156
host ,
151
157
"--port" ,
@@ -197,17 +203,29 @@ def start_router(verbose):
197
203
198
204
api_key = api_key if auth_enabled else None
199
205
200
- # Show URL with or without authentication based on API key availability
201
- if api_key :
202
- # Show authenticated URL
203
- console .print (f"SSE Server URL: [green]http://{ host } :{ port } /sse?s={ api_key } [/]" )
204
- console .print ("\n [bold cyan]To use a specific profile with authentication:[/]" )
205
- console .print (f"[green]http://{ host } :{ port } /sse?s={ api_key } &profile=<profile_name>[/]" )
206
+ if sse :
207
+ console .print ("\n [bold yellow]SSE router is not recommended[/]" )
208
+ console .print (f"Remote Server URL: [green]http://{ host } :{ port } /sse[/]" )
209
+ if api_key :
210
+ console .print ("\n [bold cyan]To use a specific profile with authentication:[/]" )
211
+ console .print (
212
+ f"Remote Server URL with authentication: [green]http://{ host } :{ port } /sse?s={ api_key } &profile=<profile_name>[/]"
213
+ )
214
+ else :
215
+ console .print ("\n [bold cyan]To use a specific profile:[/]" )
216
+ console .print (
217
+ f"Remote Server URL with authentication: [green]http://{ host } :{ port } /sse?profile=<profile_name>[/]"
218
+ )
206
219
else :
207
- # Show URL without authentication
208
- console .print (f"SSE Server URL: [green]http://{ host } :{ port } /sse[/]" )
209
- console .print ("\n [bold cyan]To use a specific profile:[/]" )
210
- console .print (f"[green]http://{ host } :{ port } /sse?profile=<profile_name>[/]" )
220
+ console .print (f"Remote Server URL: [green]http://{ host } :{ port } /mcp/[/]" )
221
+ if api_key :
222
+ console .print ("\n [bold cyan]To use a specific profile with authentication:[/]" )
223
+ console .print ("[bold]Request headers:[/]" )
224
+ console .print (f"{ MCPM_AUTH_HEADER } : { api_key } " )
225
+ else :
226
+ console .print ("\n [bold cyan]To use a specific profile:[/]" )
227
+ console .print ("[bold]Request headers:[/]" )
228
+ console .print (f"{ MCPM_PROFILE_HEADER } : <profile_name>" )
211
229
212
230
console .print ("\n [yellow]Use 'mcpm router off' to stop the router.[/]" )
213
231
@@ -432,16 +450,18 @@ def share(address, profile, http):
432
450
share_url = tunnel .start_tunnel ()
433
451
share_pid = tunnel .proc .pid if tunnel .proc else None
434
452
api_key = config .get ("api_key" ) if config .get ("auth_enabled" ) else None
435
- share_url = share_url + "/sse"
453
+
454
+ share_url = share_url + "/mcp/"
436
455
# save share pid and link to config
437
456
config_manager .save_share_config (share_url , share_pid )
438
457
profile = profile or "<your_profile>"
439
458
440
459
# print share link
441
460
console .print (f"[bold green]Router is sharing at { share_url } [/]" )
442
- console .print (
443
- f"[green]Your profile can be accessed with the url { share_url } ?{ f's={ api_key } &' if api_key else '' } profile={ profile } [/]\n "
444
- )
461
+ console .print (f"[green]Your profile can be accessed with the url { share_url } [/]\n " )
462
+ if api_key :
463
+ console .print (f"[green]Authorize with header { MCPM_AUTH_HEADER } : { api_key } [/]" )
464
+ console .print (f"[green]Specify profile with header { MCPM_PROFILE_HEADER } : { profile } [/]" )
445
465
console .print (
446
466
"[bold yellow]Be careful about the share link, it will be exposed to the public. Make sure to share to trusted users only.[/]"
447
467
)
0 commit comments