22Base client manager module that defines the interface for all client managers.
33"""
44
5- import os
5+ import abc
66import json
77import logging
8+ import os
89import platform
9- from typing import Dict , Optional , Any , List , Union
10+ from typing import Any , Dict , List , Optional , Union
1011
1112from mcpm .utils .server_config import ServerConfig
1213
1314logger = logging .getLogger (__name__ )
1415
1516
16- class BaseClientManager :
17- """Base class for all client managers providing a common interface"""
17+ class BaseClientManager (abc .ABC ):
18+ """
19+ Abstract base class that defines the interface for all client managers.
20+
21+ This class establishes the contract that all client managers must fulfill,
22+ but does not provide implementations.
23+ """
1824
1925 # Client information properties
2026 client_key = "" # Client identifier (e.g., "claude-desktop")
@@ -24,9 +30,120 @@ class BaseClientManager:
2430 def __init__ (self ):
2531 """Initialize the client manager"""
2632 self .config_path = None # To be set by subclasses
27- self ._config = None
2833 self ._system = platform .system ()
2934
35+ @abc .abstractmethod
36+ def get_servers (self ) -> Dict [str , Any ]:
37+ """Get all MCP servers configured for this client
38+
39+ Returns:
40+ Dict of server configurations by name
41+ """
42+ pass
43+
44+ @abc .abstractmethod
45+ def get_server (self , server_name : str ) -> Optional [ServerConfig ]:
46+ """Get a server configuration
47+
48+ Args:
49+ server_name: Name of the server
50+
51+ Returns:
52+ ServerConfig object if found, None otherwise
53+ """
54+ pass
55+
56+ @abc .abstractmethod
57+ def add_server (self , server_config : Union [ServerConfig , Dict [str , Any ]], name : Optional [str ] = None ) -> bool :
58+ """Add or update a server in the client config
59+
60+ Args:
61+ server_config: ServerConfig object or dictionary in client format
62+ name: Required server name when using dictionary format
63+
64+ Returns:
65+ bool: Success or failure
66+ """
67+ pass
68+
69+ @abc .abstractmethod
70+ def to_client_format (self , server_config : ServerConfig ) -> Dict [str , Any ]:
71+ """Convert ServerConfig to client-specific format
72+
73+ Args:
74+ server_config: ServerConfig object
75+
76+ Returns:
77+ Dict containing client-specific configuration
78+ """
79+ pass
80+
81+ @abc .abstractmethod
82+ def from_client_format (self , server_name : str , client_config : Dict [str , Any ]) -> ServerConfig :
83+ """Convert client format to ServerConfig
84+
85+ Args:
86+ server_name: Name of the server
87+ client_config: Client-specific configuration
88+
89+ Returns:
90+ ServerConfig object
91+ """
92+ pass
93+
94+ @abc .abstractmethod
95+ def list_servers (self ) -> List [str ]:
96+ """List all MCP servers in client config
97+
98+ Returns:
99+ List of server names
100+ """
101+ pass
102+
103+ @abc .abstractmethod
104+ def remove_server (self , server_name : str ) -> bool :
105+ """Remove an MCP server from client config
106+
107+ Args:
108+ server_name: Name of the server to remove
109+
110+ Returns:
111+ bool: Success or failure
112+ """
113+ pass
114+
115+ @abc .abstractmethod
116+ def get_client_info (self ) -> Dict [str , str ]:
117+ """Get information about this client
118+
119+ Returns:
120+ Dict: Information about the client including display name, download URL, and config path
121+ """
122+ pass
123+
124+ @abc .abstractmethod
125+ def is_client_installed (self ) -> bool :
126+ """Check if this client is installed
127+
128+ Returns:
129+ bool: True if client is installed, False otherwise
130+ """
131+ pass
132+
133+
134+ class JSONClientManager (BaseClientManager ):
135+ """
136+ JSON-based implementation of the client manager interface.
137+
138+ This class implements the BaseClientManager interface using JSON files
139+ for configuration storage.
140+ """
141+
142+ def __init__ (self ):
143+ """Initialize the JSON client manager"""
144+ super ().__init__ ()
145+ self ._config = None
146+
30147 def _load_config (self ) -> Dict [str , Any ]:
31148 """Load client configuration file
32149
@@ -88,7 +205,6 @@ def get_servers(self) -> Dict[str, Any]:
88205 Returns:
89206 Dict of server configurations by name
90207 """
91- # To be overridden by subclasses
92208 config = self ._load_config ()
93209 return config .get ("mcpServers" , {})
94210
@@ -145,7 +261,7 @@ def add_server(self, server_config: Union[ServerConfig, Dict[str, Any]], name: O
145261 def to_client_format (self , server_config : ServerConfig ) -> Dict [str , Any ]:
146262 """Convert ServerConfig to client-specific format with common core fields
147263
148- This base implementation provides the common core fields (command, args, env)
264+ This implementation provides the common core fields (command, args, env)
149265 that are used by all client managers. Subclasses can override this method
150266 if they need to add additional client-specific fields.
151267
0 commit comments