Add API key management during SuperClaude MCP setup

Features:
- Secure API key collection via getpass (hidden input)
- Cross-platform environment variable setup
- Automatic .claude.json configuration with ${ENV_VAR} syntax
- Seamless integration with existing MCP server selection flow
- Skip options for manual configuration later

Implementation:
- Added prompt_api_key() function to setup/utils/ui.py
- Created setup/utils/environment.py for cross-platform env management
- Enhanced MCP server selection in setup/cli/commands/install.py
- Updated MCP component to handle API key configuration
- Preserves user customizations while adding environment variables

Security:
- Hidden input prevents API keys from being displayed
- No logging of sensitive data
- OS-native environment variable storage
- Basic validation with user confirmation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
NomenAK
2025-08-15 13:48:14 +02:00
parent c05aa872b2
commit 01b8d2a05a
5 changed files with 1221 additions and 2 deletions

View File

@@ -75,6 +75,9 @@ class MCPComponent(Component):
# This will be set during installation - initialize as empty list
self.selected_servers: List[str] = []
# Store collected API keys for configuration
self.collected_api_keys: Dict[str, str] = {}
def _lock_file(self, file_handle, exclusive: bool = False):
"""Cross-platform file locking"""
@@ -225,9 +228,23 @@ class MCPComponent(Component):
else:
self.logger.debug(f"Preserved user customization for '{server_name}.{key}'")
# NEW: Apply environment variable references for API keys
if "env" in existing_server and self.collected_api_keys:
for env_key, env_value in existing_server["env"].items():
if env_key in self.collected_api_keys and env_value == "":
# Update to use environment variable reference
existing_server["env"][env_key] = f"${{{env_key}}}"
self.logger.info(f"Configured {env_key} to use environment variable")
self.logger.info(f"Updated existing MCP server '{server_name}' (preserved user customizations)")
else:
# New server - add complete configuration
# Apply environment variable references if we have collected keys
if "env" in server_def and self.collected_api_keys:
for env_key in server_def["env"]:
if env_key in self.collected_api_keys and server_def["env"][env_key] == "":
server_def["env"][env_key] = f"${{{env_key}}}"
existing_config[server_name] = server_def
self.logger.info(f"Added new MCP server '{server_name}' from {server_key}")
@@ -264,6 +281,10 @@ class MCPComponent(Component):
self.set_selected_servers(selected_servers)
# NEW: Log collected API keys information
if hasattr(self, 'collected_api_keys') and self.collected_api_keys:
self.logger.info(f"Using {len(self.collected_api_keys)} collected API keys for configuration")
# Validate prerequisites
success, errors = self.validate_prerequisites()
if not success: