Repository navigation
fix(mcp): document python -I -m cli; test the entry point as clients run it - #150
Merged
Merged
Conversation
…s run it #146 documented `"args": ["-m", "cli", "mcp"]`. MCP clients start servers inside the user's project, and `python -m` puts the working directory first on sys.path, so any project with its own `cli/` package runs ITS `cli/__main__.py` instead of OpenPulse - in an untrusted repository, its code executes when the client starts the server. Reproduced, and now pinned by a test. - docs/MCP.md: interpreter config uses `-I` (isolated mode, 3.10+; `-P` on 3.11+ drops only the cwd) with the reason spelled out; Windows `Scripts\python.exe` example with escaped backslashes; troubleshooting row for "something other than OpenPulse starts". - cli/__main__.py: `cli(prog_name="openpulse")` - usage lines no longer say `python -m cli`; docstring states the -I requirement. - tests/test_mcp_server.py: the stdio end-to-end test launches `python -P|-I -m cli mcp` from tmp_path, not the checkout, as a real client does. - tests/test_cli_entrypoints.py (new, replaces the test in test_packaging.py, whose module-level tomllib skip hid it on 3.10): every subprocess has a timeout and runs outside the checkout; covers --version, prog_name, a project-local `cli/` NOT winning with the flag, and the bare form being shadowed (why the docs insist on -I). - CHANGELOG Unreleased entry. Verified on Python 3.10, 3.11 and 3.14. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WintersCoder
approved these changes
Oct 25, 2026
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.
Why
#146 (merged) documents this MCP interpreter config:
MCP clients start stdio servers inside the user's project, and
python -mputs the working directory first onsys.path. Any project with its owncli/package, which is a common name, therefore runs itscli/__main__.pyinstead of OpenPulse. In an untrusted repository, its code executes as soon as the client starts the server. I reproduced this, andtests/test_cli_entrypoints.py::test_bare_python_m_cli_is_shadowed_by_a_project_clinow pins it.The #146 tests didn't catch it because they ran from inside the OpenPulse checkout.
What
docs/MCP.md:["-I", "-m", "cli", "mcp"].-Iis isolated mode (Python 3.10+): it ignores the working directory, user site-packages andPYTHON*variables.-Pis mentioned as the 3.11+ option that drops only the working directory.C:\path\to\venv\Scripts\python.exe, with escaped backslashes).cli/__main__.py:cli(prog_name="openpulse"), so usage lines sayopenpulseinstead ofpython -m cli.tests/test_mcp_server.py: the stdio end-to-end test now launchespython -P|-I -m cli mcpfromtmp_path, the way a real client does.tests/test_cli_entrypoints.py(new): replaces the cli: add cli/__main__.py so MCP clients can run python -m cli mcp #146 test intest_packaging.py, whose module-leveltomllibskip hid it on Python 3.10.--version,prog_name, a project-localcli/not winning when the flag is used, and the bare form being shadowed.Checks
prog_namefails the help test, and the barepython -m cli mcpform run from a project withcli/executes the project's code.Follow-up to the #146 review findings.
🤖 Generated with Claude Code