Skip to content

Commit 51403b8

Browse files
authored
Remove server hostname function and simplify server naming (#594)
### TL;DR Simplified server naming and added a restart notification for MCP client installations. ### What changed? - Removed the `_server_hostname()` function that generated server names from URLs - Replaced dynamic server naming with a simple default value of "mcp_agent" - Added a notification message informing users they may need to restart their MCP client after installation - Removed redundant app info fetching in the ChatGPT client flow <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a reminder after successful installation prompting users to restart the MCP client for changes to take effect. - **Refactor** - Simplified server name selection during installation; when no name is provided, it now defaults to the application name or "mcp_agent", reducing hostname derivation complexity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 7418086 commit 51403b8

File tree

2 files changed

+6
-62
lines changed

2 files changed

+6
-62
lines changed

src/mcp_agent/cli/commands/install.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from copy import deepcopy
2929
from pathlib import Path
3030
from typing import Optional
31-
from urllib.parse import urlparse
3231

3332
import typer
3433
from rich.panel import Panel
@@ -182,36 +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"
213-
214-
215184
def _build_server_config(
216185
server_url: str,
217186
transport: str = "http",
@@ -363,9 +332,6 @@ def install(
363332
# For ChatGPT, check if server has unauthenticated access enabled
364333
if client_lc == "chatgpt":
365334
try:
366-
if not app_info:
367-
app_info = run_async(mcp_client.get_app(server_url=server_url))
368-
369335
has_unauth_access = app_info.unauthenticatedAccess is True or (
370336
app_info.appServerInfo
371337
and app_info.appServerInfo.unauthenticatedAccess is True
@@ -417,7 +383,7 @@ def install(
417383
)
418384
return
419385

420-
server_name = name or _server_hostname(server_url, app_name)
386+
server_name = name or app_name or "mcp_agent"
421387

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

@@ -550,3 +516,8 @@ def install(
550516
border_style="green",
551517
)
552518
)
519+
520+
console.print(
521+
"\n💡 You may need to restart your MCP client for the changes to take effect.",
522+
style="dim",
523+
)

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)