Skip to content

Commit 7b53e42

Browse files
author
LittleCoinCoin
committed
feat: add get_server_config method for server existence detection
- Add get_server_config() method to MCPHostConfigurationManager - Enables detection of existing server configurations for partial update support - Returns Optional[MCPServerConfig] - None if server doesn't exist - Graceful error handling with debug-level logging - Reuses existing host_registry and strategy pattern infrastructure - Supports all MCP hosts (claude-desktop, cursor, vs-code, gemini)
1 parent 47dd21e commit 7b53e42

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

hatch/mcp_host_config/host_management.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,32 @@ def configure_server(self, server_config: MCPServerConfig,
180180
hostname=hostname,
181181
error_message=str(e)
182182
)
183-
184-
def remove_server(self, server_name: str, hostname: str,
183+
184+
def get_server_config(self, hostname: str, server_name: str) -> Optional[MCPServerConfig]:
185+
"""
186+
Get existing server configuration from host.
187+
188+
Args:
189+
hostname: The MCP host to query (e.g., 'claude-desktop', 'cursor')
190+
server_name: Name of the server to retrieve
191+
192+
Returns:
193+
MCPServerConfig if server exists, None otherwise
194+
"""
195+
try:
196+
host_type = MCPHostType(hostname)
197+
strategy = self.host_registry.get_strategy(host_type)
198+
current_config = strategy.read_configuration()
199+
200+
if server_name in current_config.servers:
201+
return current_config.servers[server_name]
202+
return None
203+
204+
except Exception as e:
205+
logger.debug(f"Failed to retrieve server config for {server_name} on {hostname}: {e}")
206+
return None
207+
208+
def remove_server(self, server_name: str, hostname: str,
185209
no_backup: bool = False) -> ConfigurationResult:
186210
"""Remove MCP server from specified host."""
187211
try:

0 commit comments

Comments
 (0)