fix: make sandbox_docker_mcp an optional extra to fix default CLI crash - #7
Closed
Ariasu123 wants to merge 1 commit into
Closed
fix: make sandbox_docker_mcp an optional extra to fix default CLI crash#7Ariasu123 wants to merge 1 commit into
Ariasu123 wants to merge 1 commit into
Conversation
The Docker sandbox already lives in the standalone sandbox-docker-mcp MCP server, which only the `pion mcp` server child needs. But it was declared as a core dependency and imported unconditionally at package-import time (sandbox/__init__.py -> docker.py), so a missing package crashed the whole CLI with ModuleNotFoundError even under the default `--sandbox off`. Decouple the main process from the optional package entirely: - pyproject: move the git dependency from core deps to a `sandbox` optional extra; the dev group excludes it so CI runs in a package-absent env as a decoupling regression gate. - sandbox/__init__.py: stop importing `.docker`; drop the two names from __all__. The main-process `pion.sandbox` no longer touches the extra. - cli/__init__.py: import only build_runtime. - cli/bootstrap.py: remove the in-process Docker preflight; fail fast after MCP startup if the sandbox server did not connect (its only tool source). - mcp/client.py: add MCPClientManager.connected_server_names. - mcp/sandbox_server.py: defer the external imports into serve()/ build_server_runtime() with a friendly ModuleNotFoundError exit, and push the Docker preflight down into this `pion mcp` child. Docs: README.md / README.zh-CN.md clarify the main process is an MCP client, the sandbox ships as an opt-in extra, and give the install commands. Tests: importorskip the adapter suite; rewrite the CLI startup tests for the new fail-fast path; add a subprocess regression proving the default import path works with sandbox_docker_mcp absent. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Docker sandbox 早已抽成独立的
sandbox-docker-mcpMCP server,只有pion mcp子进程需要它。但它被声明为核心依赖,并在包导入时被无条件 import(sandbox/__init__.py→docker.py),导致缺包时默认--sandbox off也会ModuleNotFoundError崩溃,整个 CLI 起不来。改动
P0 — 主进程与可选包彻底解耦
pyproject.toml:git 依赖从核心dependencies移到[project.optional-dependencies].sandboxextra;dev 组不含它,让 CI 默认在"缺包"环境跑,作为解耦回归门。pion/sandbox/__init__.py:不再 import.docker,从__all__移除两个名字。主进程侧的pion.sandbox完全不碰外部包。pion/cli/__init__.py:只导入build_runtime。pion/cli/bootstrap.py:移除主进程内的 Docker 预检;改为 MCP 启动后 fail-fast——mcp 后端下 sandbox server(唯一工具来源)没连上就报错并Exit(1)。pion/mcp/client.py:新增MCPClientManager.connected_server_names。pion/mcp/sandbox_server.py:外部 import 下沉到serve()/build_server_runtime(),缺包给出友好错误并退出;Docker 预检下推到该pion mcp子进程。P1 — 文档
README.md/README.zh-CN.md:讲清主进程是 MCP client、sandbox 是可选 extra 默认不装,并给出安装命令。测试
tests/test_sandbox_adapter.py:加pytest.importorskip("sandbox_docker_mcp")。tests/test_cli.py:改写启动测试以覆盖新的 fail-fast 路径;新增 subprocess 回归测试,用sys.modules['sandbox_docker_mcp']=None模拟缺包,证明默认导入路径不需要该 extra。验证
pytest:312 passed(含新回归测试)demos/mock_e2e.py:MOCK E2E OK🤖 Generated with Claude Code