Skip to content

Commit dba0dc5

Browse files
feat: router share with https by default
1 parent 5a4cb75 commit dba0dc5

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ logs/
5959
.env.test
6060
.env.production
6161
.envrc
62+
*.ini
6263

6364
# MCP specific
6465
.mcp/

docs/dev_guide.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ docker run --rm -it -v "$PWD:/srv/jekyll" jekyll/jekyll:4.2.0 jekyll build
5151
```
5252

5353
The built site will be in `pages/_site/`.
54+
55+
56+
## Debug mode for mcpm router
57+
Set environment variable `MCPM_DEBUG` to `true` to enable debug mode.
58+
59+
```bash
60+
export MCPM_DEBUG=true
61+
```
62+

src/mcpm/commands/router.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ def router_status():
289289
@click.help_option("-h", "--help")
290290
@click.option("-a", "--address", type=str, required=False, help="Remote address to bind the tunnel to")
291291
@click.option("-p", "--profile", type=str, required=False, help="Profile to share")
292-
def share(address, profile):
292+
@click.option("-http", type=bool, flag_value=True, required=False, help="Use HTTP instead of HTTPS")
293+
def share(address, profile, http):
293294
"""Create a share link for the MCPRouter daemon process.
294295
295296
Example:
@@ -301,6 +302,7 @@ def share(address, profile):
301302
# check if there is a router already running
302303
pid = read_pid_file()
303304
config_manager = ConfigManager()
305+
config = config_manager.get_router_config()
304306
if not pid:
305307
console.print("[yellow]MCPRouter is not running.[/]")
306308
return
@@ -324,22 +326,22 @@ def share(address, profile):
324326
# get share address
325327
if not address:
326328
console.print("[cyan]Using share address from config...[/]")
327-
config = config_manager.get_router_config()
328329
address = config["share_address"]
329330

330331
# create share link
331332
remote_host, remote_port = address.split(":")
332333

333334
# start tunnel
334335
# TODO: tls certificate if necessary
335-
tunnel = Tunnel(remote_host, remote_port, config["host"], config["port"], secrets.token_urlsafe(32), None)
336+
tunnel = Tunnel(remote_host, remote_port, config["host"], config["port"], secrets.token_urlsafe(32), http, None)
336337
share_url = tunnel.start_tunnel()
337338
share_pid = tunnel.proc.pid if tunnel.proc else None
338339
# generate random api key
339340
api_key = str(uuid.uuid4())
340341
console.print(f"[bold green]Generated secret for share link: {api_key}[/]")
341-
# TODO: https is not supported yet
342-
share_url = share_url.replace("https://", "http://") + "/sse"
342+
if http:
343+
share_url = share_url.replace("https://", "http://")
344+
share_url = share_url + "/sse"
343345
# save share pid and link to config
344346
config_manager.save_share_config(share_url, share_pid, api_key)
345347
profile = profile or "<your_profile>"

src/mcpm/router/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
CORS_ENABLED = os.environ.get("MCPM_ROUTER_CORS")
2525

2626
logging.basicConfig(
27-
level=logging.INFO,
27+
level=logging.INFO if not os.environ.get("MCPM_DEBUG") else logging.DEBUG,
2828
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
2929
handlers=[logging.FileHandler(LOG_FILE), logging.StreamHandler()],
3030
)
@@ -137,7 +137,7 @@ async def lifespan(app):
137137
)
138138

139139
app = Starlette(
140-
debug=False,
140+
debug=os.environ.get("MCPM_DEBUG") == "true",
141141
middleware=middlewares,
142142
routes=[
143143
Route("/sse", endpoint=handle_sse),

src/mcpm/router/share.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
local_host: str,
6565
local_port: int,
6666
share_token: str,
67+
http: bool,
6768
share_server_tls_certificate: str | None,
6869
):
6970
self.proc = None
@@ -73,6 +74,7 @@ def __init__(
7374
self.local_host = local_host
7475
self.local_port = local_port
7576
self.share_token = share_token
77+
self.http = http
7678
self.share_server_tls_certificate = share_server_tls_certificate
7779

7880
@staticmethod
@@ -142,6 +144,8 @@ def _start_tunnel(self, binary: str) -> str:
142144
self.share_server_tls_certificate,
143145
]
144146
)
147+
if not self.http:
148+
command.append("--tls_enable")
145149
self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True)
146150
return self._read_url_from_tunnel_stream()
147151

0 commit comments

Comments
 (0)