Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 7 additions & 37 deletions src/mcp_agent/cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from copy import deepcopy
from pathlib import Path
from typing import Optional
from urllib.parse import urlparse

import typer
from rich.panel import Panel
Expand All @@ -40,7 +39,6 @@
ENV_API_BASE_URL,
ENV_API_KEY,
)
from mcp_agent.cli.core.utils import run_async
from mcp_agent.cli.exceptions import CLIError
from mcp_agent.cli.mcp_app.api_client import MCPAppClient
from mcp_agent.cli.utils.ux import (
Expand Down Expand Up @@ -182,36 +180,6 @@ def _write_json(path: Path, data: dict) -> None:
pass


def _server_hostname(server_url: str, app_name: Optional[str] = None) -> str:
"""
Generate a friendly server name from the URL.

Extracts the subdomain or hostname to create a short, readable name.
For example, "https://abc123.deployments.mcp-agent.com/sse" -> "abc123"

Args:
server_url: The server URL
app_name: Optional app name from API (preferred if available)

Returns:
A friendly server name
"""
if app_name:
return app_name

parsed = urlparse(server_url)
hostname = parsed.hostname or ""

parts = hostname.split(".")
if len(parts) > 2 and "deployments" in hostname:
return parts[0]

if len(parts) >= 2:
return ".".join(parts[:-1])

return hostname or "mcp-server"


def _build_server_config(
server_url: str,
transport: str = "http",
Expand Down Expand Up @@ -353,7 +321,7 @@ def install(
)

try:
app_info = run_async(mcp_client.get_app(server_url=server_url))
app_info = mcp_client.get_app(server_url=server_url)
app_name = app_info.name if app_info else None
print_info(f"App name: {app_name}")
except Exception as e:
Expand All @@ -363,9 +331,6 @@ def install(
# For ChatGPT, check if server has unauthenticated access enabled
if client_lc == "chatgpt":
try:
if not app_info:
app_info = run_async(mcp_client.get_app(server_url=server_url))

has_unauth_access = app_info.unauthenticatedAccess is True or (
app_info.appServerInfo
and app_info.appServerInfo.unauthenticatedAccess is True
Expand Down Expand Up @@ -417,7 +382,7 @@ def install(
)
return

server_name = name or _server_hostname(server_url, app_name)
server_name = name or "mcp_agent"

transport = "sse" if server_url.rstrip("/").endswith("/sse") else "http"

Expand Down Expand Up @@ -550,3 +515,8 @@ def install(
border_style="green",
)
)

console.print(
"\n💡 You may need to restart your MCP client for the changes to take effect.",
style="dim",
)
27 changes: 0 additions & 27 deletions tests/cli/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest
from mcp_agent.cli.commands.install import (
_build_server_config,
_server_hostname,
_merge_mcp_json,
install,
)
Expand Down Expand Up @@ -42,32 +41,6 @@ def mock_app_without_auth():
return app


def test_server_hostname():
"""Test friendly server name generation from URLs."""
# Test with deployment URL
assert _server_hostname("https://abc123.deployments.mcp-agent.com/sse") == "abc123"
assert _server_hostname("https://xyz456.deployments.example.com/mcp") == "xyz456"

# Test with app name override
assert (
_server_hostname("https://abc123.deployments.mcp-agent.com/sse", "my-app")
== "my-app"
)

# Test with regular domain
assert _server_hostname("https://api.example.com/sse") == "api.example"
assert (
_server_hostname("https://subdomain.api.example.com/mcp")
== "subdomain.api.example"
)

# Test with simple domain
assert _server_hostname("https://example.com") == "example"

# Test fallback
assert _server_hostname("invalid-url") == "mcp-server"


def test_build_server_config():
"""Test server configuration building with auth header."""
config = _build_server_config("https://example.com/mcp", "http", api_key="test-key")
Expand Down
Loading