-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathdefault_manager.py
More file actions
123 lines (91 loc) · 4.19 KB
/
default_manager.py
File metadata and controls
123 lines (91 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""Implementation of the default MCP package manager."""
from ...config import get_default_client
from ...registry.integration import RegistryIntegration
from .base import MCPPackageManagerAdapter
class DefaultMCPPackageManager(MCPPackageManagerAdapter):
"""Implementation of the default MCP package manager."""
def install(self, package_name, version=None):
"""Install an MCP package.
Args:
package_name (str): Name of the package to install.
version (str, optional): Version of the package to install.
Returns:
bool: True if successful, False otherwise.
"""
try:
# Import here to avoid circular import
from ...factory import ClientFactory
client_type = get_default_client()
client_adapter = ClientFactory.create_client(client_type)
# For VSCode, configure MCP server in mcp.json
result = client_adapter.configure_mcp_server(package_name, package_name, True)
if result:
print(f"Successfully installed {package_name}")
return result
except Exception as e:
print(f"Error installing package {package_name}: {e}")
return False
def uninstall(self, package_name):
"""Uninstall an MCP package.
Args:
package_name (str): Name of the package to uninstall.
Returns:
bool: True if successful, False otherwise.
"""
try:
# Import here to avoid circular import
from ...factory import ClientFactory
client_type = get_default_client()
client_adapter = ClientFactory.create_client(client_type)
config = client_adapter.get_current_config()
# For VSCode, remove the server from mcp.json
if "servers" in config and package_name in config["servers"]:
servers = config["servers"]
servers.pop(package_name, None)
result = client_adapter.update_config({"servers": servers})
if result:
print(f"Successfully uninstalled {package_name}")
return result
else:
print(f"Package {package_name} not found in configuration")
return False
except Exception as e:
print(f"Error uninstalling package {package_name}: {e}")
return False
def list_installed(self):
"""List all installed MCP packages.
Returns:
list: List of installed packages.
"""
try:
# Import here to avoid circular import
from ...factory import ClientFactory
# Get client type from configuration (default is vscode)
client_type = get_default_client()
# Create client adapter
client_adapter = ClientFactory.create_client(client_type)
# Get config from local .vscode/mcp.json file
config = client_adapter.get_current_config()
# Extract server names from the config
servers = config.get("servers", {})
# Return the list of server names
return list(servers.keys())
except Exception as e:
print(f"Error retrieving installed MCP servers: {e}")
return []
def search(self, query):
"""Search for MCP packages.
Args:
query (str): Search query.
Returns:
list: List of packages matching the query.
"""
try:
# Use the registry integration to search for packages
registry = RegistryIntegration()
packages = registry.search_packages(query)
# Return the list of package IDs/names
return [pkg.get("id", pkg.get("name", "Unknown")) for pkg in packages] if packages else []
except Exception as e:
print(f"Error searching for packages: {e}")
return []