|
| 1 | +""" |
| 2 | +Claude Code CLI integration utilities for MCP |
| 3 | +""" |
| 4 | + |
| 5 | +import logging |
| 6 | +import os |
| 7 | +import shutil |
| 8 | +from typing import Any, Dict |
| 9 | + |
| 10 | +from mcpm.clients.base import JSONClientManager |
| 11 | + |
| 12 | +logger = logging.getLogger(__name__) |
| 13 | + |
| 14 | + |
| 15 | +class ClaudeCodeManager(JSONClientManager): |
| 16 | + """Manages Claude Code CLI MCP server configurations""" |
| 17 | + |
| 18 | + # Client information |
| 19 | + client_key = "claude-code" |
| 20 | + display_name = "Claude Code" |
| 21 | + download_url = "https://docs.anthropic.com/en/docs/claude-code" |
| 22 | + |
| 23 | + def __init__(self, config_path=None): |
| 24 | + """Initialize the Claude Code client manager |
| 25 | +
|
| 26 | + Args: |
| 27 | + config_path: Optional path to the config file. If not provided, uses default path. |
| 28 | + """ |
| 29 | + super().__init__() |
| 30 | + |
| 31 | + if config_path: |
| 32 | + self.config_path = config_path |
| 33 | + else: |
| 34 | + self.config_path = os.path.expanduser("~/.claude.json") |
| 35 | + |
| 36 | + def _get_empty_config(self) -> Dict[str, Any]: |
| 37 | + """Get empty config structure for Claude Code""" |
| 38 | + return {"mcpServers": {}} |
| 39 | + |
| 40 | + def is_client_installed(self) -> bool: |
| 41 | + """Check if Claude Code CLI is installed |
| 42 | + Returns: |
| 43 | + bool: True if claude command is available, False otherwise |
| 44 | + """ |
| 45 | + claude_executable = "claude.exe" if self._system == "Windows" else "claude" |
| 46 | + return shutil.which(claude_executable) is not None |
| 47 | + |
| 48 | + def get_client_info(self) -> Dict[str, str]: |
| 49 | + """Get information about this client |
| 50 | +
|
| 51 | + Returns: |
| 52 | + Dict: Information about the client including display name, download URL, and config path |
| 53 | + """ |
| 54 | + return { |
| 55 | + "name": self.display_name, |
| 56 | + "download_url": self.download_url, |
| 57 | + "config_file": self.config_path, |
| 58 | + "description": "Anthropic's Claude Code CLI tool" |
| 59 | + } |
0 commit comments