Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ logs/
.env.test
.env.production
.envrc
*.ini

# MCP specific
.mcp/
Expand Down
9 changes: 9 additions & 0 deletions docs/dev_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ docker run --rm -it -v "$PWD:/srv/jekyll" jekyll/jekyll:4.2.0 jekyll build
```

The built site will be in `pages/_site/`.


## Debug mode for mcpm router
Set environment variable `MCPM_DEBUG` to `true` to enable debug mode.

```bash
export MCPM_DEBUG=true
```

2 changes: 1 addition & 1 deletion src/mcpm/commands/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def add(profile, force=False):
profile_config_manager.new_profile(profile)

console.print(f"\n[green]Profile '{profile}' added successfully.[/]\n")
console.print(f"You can now add servers to this profile with 'mcpm add --target #{profile} <server_name>'\n")
console.print(f"You can now add servers to this profile with 'mcpm add --target %{profile} <server_name>'\n")
console.print(
f"Or apply existing config to this profile with 'mcpm profile apply {profile} --server <server_name>'\n"
)
Expand Down
11 changes: 5 additions & 6 deletions src/mcpm/commands/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ def router_status():
@click.help_option("-h", "--help")
@click.option("-a", "--address", type=str, required=False, help="Remote address to bind the tunnel to")
@click.option("-p", "--profile", type=str, required=False, help="Profile to share")
def share(address, profile):
@click.option("--http", type=bool, flag_value=True, required=False, help="Use HTTP instead of HTTPS")
def share(address, profile, http):
"""Create a share link for the MCPRouter daemon process.

Example:
Expand All @@ -301,6 +302,7 @@ def share(address, profile):
# check if there is a router already running
pid = read_pid_file()
config_manager = ConfigManager()
config = config_manager.get_router_config()
if not pid:
console.print("[yellow]MCPRouter is not running.[/]")
return
Expand All @@ -324,22 +326,19 @@ def share(address, profile):
# get share address
if not address:
console.print("[cyan]Using share address from config...[/]")
config = config_manager.get_router_config()
address = config["share_address"]

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

# start tunnel
# TODO: tls certificate if necessary
tunnel = Tunnel(remote_host, remote_port, config["host"], config["port"], secrets.token_urlsafe(32), None)
tunnel = Tunnel(remote_host, remote_port, config["host"], config["port"], secrets.token_urlsafe(32), http, None)
share_url = tunnel.start_tunnel()
share_pid = tunnel.proc.pid if tunnel.proc else None
# generate random api key
api_key = str(uuid.uuid4())
console.print(f"[bold green]Generated secret for share link: {api_key}[/]")
# TODO: https is not supported yet
share_url = share_url.replace("https://", "http://") + "/sse"
share_url = share_url + "/sse"
# save share pid and link to config
config_manager.save_share_config(share_url, share_pid, api_key)
profile = profile or "<your_profile>"
Expand Down
4 changes: 2 additions & 2 deletions src/mcpm/router/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
CORS_ENABLED = os.environ.get("MCPM_ROUTER_CORS")

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

app = Starlette(
debug=False,
debug=os.environ.get("MCPM_DEBUG") == "true",
middleware=middlewares,
routes=[
Route("/sse", endpoint=handle_sse),
Expand Down
6 changes: 6 additions & 0 deletions src/mcpm/router/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(
local_host: str,
local_port: int,
share_token: str,
http: bool,
share_server_tls_certificate: str | None,
):
self.proc = None
Expand All @@ -73,6 +74,7 @@ def __init__(
self.local_host = local_host
self.local_port = local_port
self.share_token = share_token
self.http = http
self.share_server_tls_certificate = share_server_tls_certificate

@staticmethod
Expand Down Expand Up @@ -142,6 +144,8 @@ def _start_tunnel(self, binary: str) -> str:
self.share_server_tls_certificate,
]
)
if not self.http:
command.append("--tls_enable")
self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True)
return self._read_url_from_tunnel_stream()

Expand Down Expand Up @@ -182,4 +186,6 @@ def _raise_tunnel_error():
elif "login to server failed" in line:
_raise_tunnel_error()

if self.http:
url = url.replace("https://", "http://")
return url