|
| 1 | +"""Trae integration utilities for MCP""" |
| 2 | + |
| 3 | +import logging |
| 4 | +import os |
| 5 | +from typing import Any, Dict |
| 6 | + |
| 7 | +from mcpm.clients.base import JSONClientManager |
| 8 | +from mcpm.schemas.server_config import ServerConfig |
| 9 | + |
| 10 | +logger = logging.getLogger(__name__) |
| 11 | + |
| 12 | + |
| 13 | +class TraeManager(JSONClientManager): |
| 14 | + """Manages Trae MCP server configurations""" |
| 15 | + |
| 16 | + # Client information |
| 17 | + client_key = "trae" |
| 18 | + display_name = "Trae" |
| 19 | + download_url = "https://trae.ai/" |
| 20 | + |
| 21 | + def __init__(self, config_path=None): |
| 22 | + """Initialize the Trae client manager |
| 23 | +
|
| 24 | + Args: |
| 25 | + config_path: Optional path to the config file. If not provided, uses default path. |
| 26 | + """ |
| 27 | + super().__init__() |
| 28 | + |
| 29 | + if config_path: |
| 30 | + self.config_path = config_path |
| 31 | + else: |
| 32 | + # Set config path based on detected platform |
| 33 | + if self._system == "Darwin": # macOS |
| 34 | + self.config_path = os.path.expanduser("~/Library/Application Support/Trae/User/mcp.json") |
| 35 | + elif self._system == "Windows": |
| 36 | + self.config_path = os.path.join(os.environ.get("APPDATA", ""), "Trae", "User", "mcp.json") |
| 37 | + else: |
| 38 | + # Linux |
| 39 | + self.config_path = os.path.expanduser("~/.config/trae/mcp.json") |
| 40 | + logger.warning("Trae is not supported on Linux yet.") |
| 41 | + |
| 42 | + def _get_empty_config(self) -> Dict[str, Any]: |
| 43 | + """Get empty config structure for Trae""" |
| 44 | + return {"mcpServers": {}} |
| 45 | + |
| 46 | + def to_client_format(self, server_config: ServerConfig) -> Dict[str, Any]: |
| 47 | + """Convert ServerConfig to Trae-specific format |
| 48 | +
|
| 49 | + Args: |
| 50 | + server_config: ServerConfig object |
| 51 | +
|
| 52 | + Returns: |
| 53 | + Dict containing Trae-specific configuration |
| 54 | + """ |
| 55 | + # Start with the standard conversion |
| 56 | + result = super().to_client_format(server_config) |
| 57 | + |
| 58 | + # the fromGalleryId field is Trae-specific and not supported yet |
| 59 | + |
| 60 | + return result |
| 61 | + |
| 62 | + def from_client_format(self, server_name: str, client_config: Dict[str, Any]) -> ServerConfig: |
| 63 | + """Convert Trae format to ServerConfig |
| 64 | +
|
| 65 | + Args: |
| 66 | + server_name: Name of the server |
| 67 | + client_config: Trae-specific configuration |
| 68 | +
|
| 69 | + Returns: |
| 70 | + ServerConfig object |
| 71 | + """ |
| 72 | + # Make a copy of the config to avoid modifying the original |
| 73 | + config_copy = client_config.copy() |
| 74 | + |
| 75 | + return super().from_client_format(server_name, config_copy) |
0 commit comments