Skip to content

Commit 345b9b3

Browse files
committed
Remove server hostname function and simplify server naming
1 parent a856e0d commit 345b9b3

File tree

2 files changed

+7
-61
lines changed

2 files changed

+7
-61
lines changed

src/mcp_agent/cli/commands/install.py

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
ENV_API_BASE_URL,
4141
ENV_API_KEY,
4242
)
43-
from mcp_agent.cli.core.utils import run_async
4443
from mcp_agent.cli.exceptions import CLIError
4544
from mcp_agent.cli.mcp_app.api_client import MCPAppClient
4645
from mcp_agent.cli.utils.ux import (
@@ -182,34 +181,6 @@ def _write_json(path: Path, data: dict) -> None:
182181
pass
183182

184183

185-
def _server_hostname(server_url: str, app_name: Optional[str] = None) -> str:
186-
"""
187-
Generate a friendly server name from the URL.
188-
189-
Extracts the subdomain or hostname to create a short, readable name.
190-
For example, "https://abc123.deployments.mcp-agent.com/sse" -> "abc123"
191-
192-
Args:
193-
server_url: The server URL
194-
app_name: Optional app name from API (preferred if available)
195-
196-
Returns:
197-
A friendly server name
198-
"""
199-
if app_name:
200-
return app_name
201-
202-
parsed = urlparse(server_url)
203-
hostname = parsed.hostname or ""
204-
205-
parts = hostname.split(".")
206-
if len(parts) > 2 and "deployments" in hostname:
207-
return parts[0]
208-
209-
if len(parts) >= 2:
210-
return ".".join(parts[:-1])
211-
212-
return hostname or "mcp-server"
213184

214185

215186
def _build_server_config(
@@ -353,7 +324,7 @@ def install(
353324
)
354325

355326
try:
356-
app_info = run_async(mcp_client.get_app(server_url=server_url))
327+
app_info = mcp_client.get_app(server_url=server_url)
357328
app_name = app_info.name if app_info else None
358329
print_info(f"App name: {app_name}")
359330
except Exception as e:
@@ -363,9 +334,6 @@ def install(
363334
# For ChatGPT, check if server has unauthenticated access enabled
364335
if client_lc == "chatgpt":
365336
try:
366-
if not app_info:
367-
app_info = run_async(mcp_client.get_app(server_url=server_url))
368-
369337
has_unauth_access = app_info.unauthenticatedAccess is True or (
370338
app_info.appServerInfo
371339
and app_info.appServerInfo.unauthenticatedAccess is True
@@ -417,7 +385,7 @@ def install(
417385
)
418386
return
419387

420-
server_name = name or _server_hostname(server_url, app_name)
388+
server_name = name or "mcp_agent"
421389

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

@@ -550,3 +518,8 @@ def install(
550518
border_style="green",
551519
)
552520
)
521+
522+
console.print(
523+
"\n💡 You may need to restart your MCP client for the changes to take effect.",
524+
style="dim",
525+
)

tests/cli/commands/test_install.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77
from mcp_agent.cli.commands.install import (
88
_build_server_config,
9-
_server_hostname,
109
_merge_mcp_json,
1110
install,
1211
)
@@ -42,32 +41,6 @@ def mock_app_without_auth():
4241
return app
4342

4443

45-
def test_server_hostname():
46-
"""Test friendly server name generation from URLs."""
47-
# Test with deployment URL
48-
assert _server_hostname("https://abc123.deployments.mcp-agent.com/sse") == "abc123"
49-
assert _server_hostname("https://xyz456.deployments.example.com/mcp") == "xyz456"
50-
51-
# Test with app name override
52-
assert (
53-
_server_hostname("https://abc123.deployments.mcp-agent.com/sse", "my-app")
54-
== "my-app"
55-
)
56-
57-
# Test with regular domain
58-
assert _server_hostname("https://api.example.com/sse") == "api.example"
59-
assert (
60-
_server_hostname("https://subdomain.api.example.com/mcp")
61-
== "subdomain.api.example"
62-
)
63-
64-
# Test with simple domain
65-
assert _server_hostname("https://example.com") == "example"
66-
67-
# Test fallback
68-
assert _server_hostname("invalid-url") == "mcp-server"
69-
70-
7144
def test_build_server_config():
7245
"""Test server configuration building with auth header."""
7346
config = _build_server_config("https://example.com/mcp", "http", api_key="test-key")

0 commit comments

Comments
 (0)