From 1f28d83bf3d5b9897fafd7539f29d46719fde334 Mon Sep 17 00:00:00 2001 From: Xavier Bouthillier Date: Wed, 16 Apr 2025 09:28:44 -0400 Subject: [PATCH] feat: add option for custom docker host socket Why: The socket is different when we use rootless mode with docker. --- mcontainer/cli.py | 4 ++++ mcontainer/container.py | 1 + mcontainer/mcp.py | 5 ++++- mcontainer/models.py | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mcontainer/cli.py b/mcontainer/cli.py index 14984fb..14e48e3 100644 --- a/mcontainer/cli.py +++ b/mcontainer/cli.py @@ -1347,6 +1347,9 @@ def add_mcp( env: List[str] = typer.Option( [], "--env", "-e", help="Environment variables (format: KEY=VALUE)" ), + docker_host: Optional[str] = typer.Option( + None, "--docker-host", help="Docker host socket file that should be mounted on the MCP container", + ), no_default: bool = typer.Option( False, "--no-default", help="Don't add MCP server to defaults" ), @@ -1380,6 +1383,7 @@ def add_mcp( proxy_options, environment, host_port, + docker_host, add_as_default=not no_default, ) diff --git a/mcontainer/container.py b/mcontainer/container.py index 0b90849..0de551b 100644 --- a/mcontainer/container.py +++ b/mcontainer/container.py @@ -28,6 +28,7 @@ class ContainerManager: ): self.config_manager = config_manager or ConfigManager() self.session_manager = session_manager or SessionManager() + self.user_config_manager = user_config_manager or UserConfigManager() self.mcp_manager = MCPManager(config_manager=self.user_config_manager) diff --git a/mcontainer/mcp.py b/mcontainer/mcp.py index 5495ccd..b814554 100644 --- a/mcontainer/mcp.py +++ b/mcontainer/mcp.py @@ -179,6 +179,7 @@ class MCPManager: proxy_options: Dict[str, Any] = None, env: Dict[str, str] = None, host_port: Optional[int] = None, + docker_host: Optional[str] = None, add_as_default: bool = True, ) -> Dict[str, Any]: """Add a proxy-based MCP server. @@ -191,6 +192,7 @@ class MCPManager: proxy_options: Options for the MCP proxy env: Environment variables to set in the container host_port: Host port to bind the MCP server to (auto-assigned if not specified) + docker_host: Docker host socket file that should be mounted on the MCP container add_as_default: Whether to add this MCP to the default MCPs list Returns: @@ -223,6 +225,7 @@ class MCPManager: proxy_options=proxy_options or {}, env=env or {}, host_port=host_port, + docker_host=docker_host or "/var/run/docker.sock", ) # Add to the configuration @@ -570,7 +573,7 @@ ENTRYPOINT ["/entrypoint.sh"] detach=True, network=None, # Start without network, we'll add it with aliases volumes={ - "/var/run/docker.sock": { + mcp_config.get("docker_host", "/var/run/docker.sock"): { "bind": "/var/run/docker.sock", "mode": "rw", } diff --git a/mcontainer/models.py b/mcontainer/models.py index 1636289..ee9cab6 100644 --- a/mcontainer/models.py +++ b/mcontainer/models.py @@ -79,6 +79,7 @@ class ProxyMCP(BaseModel): proxy_options: Dict[str, Any] = Field(default_factory=dict) env: Dict[str, str] = Field(default_factory=dict) host_port: Optional[int] = None # External port to bind the SSE port to on the host + docker_host: Optional[str] = None # Docker host to use for the proxy container MCP = Union[RemoteMCP, DockerMCP, ProxyMCP]