mcp-pystub
English | 日本語
An MCP server that removes heavy packages from your exe: the ones your dependencies import but your own code never uses.
Use it when your PyInstaller exe is too big. For example, an app that only reads and writes MDF files with asammdf still ends up as a 252 MB exe, because asammdf's GUI code pulls in PySide6 (Qt). mcp-pystub finds the parts your app never actually calls, even inside your dependencies, replaces them with stubs (empty stand-in modules), and runs your program to check that the output does not change. The replacement can be undone.
| Library (example use) | exe (as is) | exe (after) | Removed |
|---|---|---|---|
| asammdf (read/write MDF) | 252.0 MB | 38.9 MB | asammdf.gui -> PySide6 |
| networkx | 76.7 MB | 40.8 MB | scipy, fontTools, pandas |
| tqdm | 47.7 MB | 33.3 MB | pandas, fontTools, PIL |
| matplotlib | 44.6 MB | 36.0 MB | pandas, PIL.ImageQt |
| openpyxl | 26.2 MB | 20.3 MB | PIL |
| Pillow | 25.7 MB | 14.4 MB | numpy |
PyInstaller (onefile), Windows 11, Python 3.13. In every case the exe's output was confirmed identical to the original (conditions: Verified results).
Usage
You need an MCP client such as Claude Code, a venv with your app's dependencies, and PyInstaller to build the exe. Tested on Windows 11 with Python 3.13.
Add it to Claude Code once, then ask Claude.
claude mcp add pystub -- uvx mcp-pystub
Then ask in your project folder:
Use mcp-pystub to make the exe of main.py smaller. The venv is .venv. You can run it to check.
Saying where the venv is, and that Claude may run your program, lets it check the result by actually running it. Claude goes on from there: finding the unused parts, running with them removed, swapping in the stubs and building the exe. The stubs stay in the venv only for the build; afterwards Claude puts the venv back. No uv, or using another client (Claude Desktop etc.)? See Tools and setup.
Why not just exclude modules by hand?
You can drop packages with PyInstaller's --exclude-module, but only if you know they are never imported at run time. Guess wrong and the exe crashes with an ImportError, sometimes only on a rarely used path, long after you shipped it.
- Finds what is really unused: an import is not the same as a use. mcp-pystub tells apart code that is imported but never called, even deep inside your dependencies (how it works).
- Runs to check:
verifyplugs in the stubs, runs your program, and checks that the output and exit code are unchanged (your program is run only when you ask for it). - Clear error instead of a mystery crash: if your app later starts using a removed part, the stub stops with a message that names what was removed and why (exceptions to this rule are listed in Safety and limitations).
- Reversible: original files are backed up and the restore commands are printed.
Static analysis alone cannot promise that nothing breaks for every input, so proposals are candidates and the final check is to run the program. For the scope of the guarantee and the limits, see Safety and limitations.
Documentation
Detailed documents are currently in Japanese.
- How it works (verdicts, confidence, the three layers, execution trace)
- Safety and limitations (scope of the guarantee, differences from a normal run, limitations, safety policy)
- Tools and setup (installation, MCP configuration, tool inputs and outputs)
- Verified results and performance (measurement conditions, analysis time and memory)
- Verdict specification
- Changelog
- Development (tests, how the README GIF is made)
License
MIT
Metadata
Release files for mcp-pystub 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_pystub-0.3.1.tar.gz | 217.9 kB | Without provenance | Details for mcp_pystub-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_pystub-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for mcp_pystub-0.3.1-py3-none-any.whl |
Total release size: 350.8 kB
Release files / mcp_pystub-0.3.1.tar.gz
| Download URL | mcp_pystub-0.3.1.tar.gz |
|---|---|
| Size | 217.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ba6bd8087040e4fd5c48bbb059d4316e331e7bdd91bafbf706ddd8914588bd1
|
|
BLAKE2b-256 checksum How to use checksums |
475660525291b4d8aca7cd7afbe5f2b792a29f39e62c24ae1e09ed4a430d0e4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.23
|
Release files / mcp_pystub-0.3.1-py3-none-any.whl
| Download URL | mcp_pystub-0.3.1-py3-none-any.whl |
|---|---|
| Size | 132.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21b17548fa06e3e26f6a7c5f7b98fc5c41c7c3c4b26f9f4b1c67d628d82c3cf9
|
|
BLAKE2b-256 checksum How to use checksums |
d5ed33439b5db57756ea613e5751c1654879c17f90e6a383d1a52dab86bf809b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.23
|
Security for mcp-pystub 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.