-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcp.py
More file actions
89 lines (70 loc) · 2.8 KB
/
Copy pathmcp.py
File metadata and controls
89 lines (70 loc) · 2.8 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
"""apc mcp commands — list, sync, and remove MCP server configurations.
No login required. No network calls.
"""
import click
from cache import load_mcp_servers, save_mcp_servers
from sync_helpers import resolve_target_tools, sync_mcp
from ui import header, info, mcp_list, success, warning
@click.group()
def mcp():
"""Manage MCP server configurations."""
pass
@mcp.command("list")
def mcp_list_cmd():
"""List cached MCP servers."""
servers = load_mcp_servers()
mcp_list(servers)
@mcp.command("sync")
@click.option("--tools", default=None, help="Comma-separated list of target tools")
@click.option("--all", "apply_all", is_flag=True, help="Apply to all detected tools")
@click.option("--override", is_flag=True, help="Replace existing MCP servers instead of merging")
@click.option(
"--all-sources",
"all_sources",
is_flag=True,
help="Sync ALL cached servers to every tool, ignoring source_tool origin.",
)
@click.option("--yes", "-y", is_flag=True, help="Skip confirmation prompt")
def mcp_sync(tools, apply_all, override, all_sources, yes):
"""Sync MCP servers to target tools.
By default each server is only applied to the tool it was originally
collected from (source_tool). Use --all-sources to broadcast every
cached server to every target tool regardless of origin.
"""
header("MCP Sync")
tool_list = resolve_target_tools(tools, apply_all)
if not tool_list:
return
if not yes:
if not override:
override = click.confirm(
"Override existing MCP servers? (No = append/merge)", default=False
)
if not click.confirm(f"Sync MCP servers to {', '.join(tool_list)}?"):
click.echo("Cancelled.")
return
sync_mcp(tool_list, override=override, all_sources=all_sources)
@mcp.command("remove")
@click.argument("name")
@click.option("--yes", "-y", is_flag=True, help="Skip confirmation prompt")
def mcp_remove(name, yes):
"""Remove an MCP server from the cache by name.
The server will be pruned from target tools on next 'apc sync'.
"""
servers = load_mcp_servers()
matches = [s for s in servers if s.get("name") == name]
if not matches:
warning(f"No MCP server named '{name}' in cache.")
info("Run 'apc mcp list' to see cached servers.")
return
if not yes:
for m in matches:
source = m.get("source_tool", "unknown")
info(f" {name} (from {source})")
if not click.confirm(f"\nRemove {len(matches)} server(s)?"):
info("Cancelled.")
return
remaining = [s for s in servers if s.get("name") != name]
save_mcp_servers(remaining)
success(f"Removed '{name}' from cache ({len(matches)} entry/entries).")
info("Run 'apc sync' to propagate the removal to target tools.")