-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathconfig.py
More file actions
74 lines (59 loc) · 2.33 KB
/
Copy pathconfig.py
File metadata and controls
74 lines (59 loc) · 2.33 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
"""Config command for MCPM - Manage MCPM configuration"""
import os
import click
from rich.console import Console
from rich.prompt import Prompt
from mcpm.utils.config import NODE_EXECUTABLES, ConfigManager
from mcpm.utils.repository import RepositoryManager
console = Console()
repo_manager = RepositoryManager()
@click.group()
@click.help_option("-h", "--help")
def config():
"""Manage MCPM configuration.
Commands for managing MCPM configuration and cache.
"""
pass
@config.command()
@click.help_option("-h", "--help")
def set():
"""Set MCPM configuration."""
set_key = Prompt.ask("Configuration key to set", choices=["node_executable"], default="node_executable")
node_executable = Prompt.ask(
"Select default node executable, it will be automatically applied when adding npx server with mcpm add",
choices=NODE_EXECUTABLES,
)
config_manager = ConfigManager()
config_manager.set_config(set_key, node_executable)
console.print(f"[green]Default node executable set to:[/] {node_executable}")
@config.command()
@click.argument("name", required=True)
@click.help_option("-h", "--help")
def get(name):
"""Get MCPM configuration."""
config_manager = ConfigManager()
current_config = config_manager.get_config()
if name not in current_config:
console.print(f"[red]Configuration '{name}' not set or not supported.[/]")
return
console.print(f"[green]{name}:[/] {current_config[name]}")
@config.command()
@click.help_option("-h", "--help")
def clear_cache():
"""Clear the local repository cache.
Removes the cached server information, forcing a fresh download on next search.
Examples:
mcpm config clear-cache # Clear the local repository cache
"""
try:
# Check if cache file exists
if os.path.exists(repo_manager.cache_file):
# Remove the cache file
os.remove(repo_manager.cache_file)
console.print(f"[green]Successfully cleared repository cache at:[/] {repo_manager.cache_file}")
console.print("Cache will be rebuilt on next search.")
else:
console.print(f"[yellow]Cache file not found at:[/] {repo_manager.cache_file}")
console.print("No action needed.")
except Exception as e:
console.print(f"[bold red]Error clearing cache:[/] {str(e)}")