-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsetup_mcp.py
More file actions
179 lines (144 loc) · 5.24 KB
/
setup_mcp.py
File metadata and controls
179 lines (144 loc) · 5.24 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python3
"""
Hushh MCP Server - Configuration Generator
Automatically generates the Claude Desktop configuration file
with correct paths for the current system.
Usage:
python setup_mcp.py
This will:
1. Detect the consent-protocol directory location
2. Generate the correct claude_desktop_config.json
3. Optionally copy it to the Claude Desktop config location
"""
import json
import os
import sys
from pathlib import Path
def get_claude_config_path() -> Path:
"""Get the Claude Desktop configuration file path for the current OS."""
if sys.platform == "win32":
appdata = os.environ.get("APPDATA")
if appdata:
return Path(appdata) / "Claude" / "claude_desktop_config.json"
elif sys.platform == "darwin": # macOS
return (
Path.home()
/ "Library"
/ "Application Support"
/ "Claude"
/ "claude_desktop_config.json"
)
else: # Linux
return Path.home() / ".config" / "Claude" / "claude_desktop_config.json"
raise RuntimeError("Could not determine Claude Desktop config path")
def get_consent_protocol_dir() -> Path:
"""Get the absolute path to the consent-protocol directory."""
# This script is in consent-protocol/, so parent is the dir itself
return Path(__file__).parent.resolve()
def generate_config() -> dict:
"""Generate the MCP server configuration."""
consent_dir = get_consent_protocol_dir()
mcp_server_path = consent_dir / "mcp_server.py"
if not mcp_server_path.exists():
raise FileNotFoundError(f"MCP server not found at: {mcp_server_path}")
config = {
"mcpServers": {
"hushh-consent": {
"command": "python",
"args": [str(mcp_server_path)],
"env": {"PYTHONPATH": str(consent_dir)},
}
}
}
return config
def save_example_config(config: dict, consent_dir: Path) -> Path:
"""Save the generated config as an example file in the repo."""
example_path = consent_dir / "claude_desktop_config.generated.json"
with open(example_path, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2)
return example_path
def install_config(config: dict) -> bool:
"""Install the config to Claude Desktop's config location."""
try:
config_path = get_claude_config_path()
# Create directory if it doesn't exist
config_path.parent.mkdir(parents=True, exist_ok=True)
# Check if config already exists
existing_config = {}
if config_path.exists():
with open(config_path, "r", encoding="utf-8") as f:
try:
existing_config = json.load(f)
except json.JSONDecodeError:
existing_config = {}
# Merge configs (add our server to existing)
if "mcpServers" not in existing_config:
existing_config["mcpServers"] = {}
existing_config["mcpServers"]["hushh-consent"] = config["mcpServers"]["hushh-consent"]
# Write merged config
with open(config_path, "w", encoding="utf-8") as f:
json.dump(existing_config, f, indent=2)
return True
except Exception as e:
print(f"❌ Could not install config: {e}")
return False
def main():
print("=" * 60)
print("🔐 Hushh MCP Server - Configuration Generator")
print("=" * 60)
print()
# Get consent-protocol directory
consent_dir = get_consent_protocol_dir()
print("📁 Consent Protocol Directory:")
print(f" {consent_dir}")
print()
# Generate config
try:
config = generate_config()
print("✅ Configuration generated successfully!")
print()
except FileNotFoundError as e:
print(f"❌ Error: {e}")
sys.exit(1)
# Show the generated config
print("📋 Generated Configuration:")
print("-" * 40)
print(json.dumps(config, indent=2))
print("-" * 40)
print()
# Save example config
example_path = save_example_config(config, consent_dir)
print(f"💾 Saved to: {example_path}")
print()
# Ask to install
claude_config_path = get_claude_config_path()
print("📍 Claude Desktop config location:")
print(f" {claude_config_path}")
print()
response = input("Install to Claude Desktop? (y/n): ").strip().lower()
if response == "y":
if install_config(config):
print()
print("✅ Configuration installed successfully!")
print()
print("🔄 Next steps:")
print(" 1. Fully quit Claude Desktop (check system tray)")
print(" 2. Reopen Claude Desktop")
print(" 3. Look for 🔧 tool icon")
print(" 4. Ask: 'What Hushh tools do you have?'")
else:
print()
print("⚠️ Could not auto-install. Please copy manually:")
print(f" From: {example_path}")
print(f" To: {claude_config_path}")
else:
print()
print("📋 Manual installation:")
print(" Copy the contents of:")
print(f" {example_path}")
print(" To:")
print(f" {claude_config_path}")
print()
print("=" * 60)
if __name__ == "__main__":
main()