
Pystub
If you're building Python executables with PyInstaller, Nuitka, or cx_Freeze and fighting bloated file sizes, this is worth knowing about. It analyzes your import graph with AST parsing to identify dependencies that get bundled but never actually run, then generates minimal stub replacements. The analyze tool detects stubbable packages and flags try-except protected imports for nofollow treatment. The generate and generate_submodule tools create stub code and build instructions with backup commands. One verified case stripped PySide6 from an asammdf build by stubbing the gui submodule, dropping the exe from 431MB to 259MB with zero runtime breakage. It won't catch dynamic imports or handle pip-to-import name mismatches, but the algorithm errs toward safety, marking ambiguous cases as required rather than risking a broken build.
- tools
- 5
- transport
- STDIO
- last updated
- Mar 31, 2026
Tools
5 toolsPublic tool metadata for what this MCP can expose to an agent.
analyzeAuto-detect stubbable packages + submodule stub hints for C-extension elimination
Auto-detect stubbable packages + submodule stub hints for C-extension elimination
No parameter schema in public metadata yet.
graphVisualize import graph as nodes and edges
Visualize import graph as nodes and edges
No parameter schema in public metadata yet.
checkDeep analysis of a specific package's usage
Deep analysis of a specific package's usage
No parameter schema in public metadata yet.
generateGenerate minimal stub code + build instructions
Generate minimal stub code + build instructions
No parameter schema in public metadata yet.
generate_submoduleGenerate submodule stubs to indirectly eliminate C-extension packages
Generate submodule stubs to indirectly eliminate C-extension packages
No parameter schema in public metadata yet.
Sponsors
Readme
mcp-pystub
Python exe ビルド(PyInstaller / Nuitka / cx_Freeze)時にスタブ置換可能なパッケージを自動検出し、最小スタブコードを生成する MCP サーバー。
An MCP server that auto-detects stubbable packages for Python exe builds (PyInstaller / Nuitka / cx_Freeze) and generates minimal stub code to reduce executable size.
背景 / Background
Python アプリを exe 化すると、依存ライブラリがモジュールレベルで import する重量パッケージが丸ごと同梱され、exe サイズが膨張する。実際のコードパスで使わないパッケージは最小ダミー(スタブ)で置換すれば大幅なサイズ削減が可能。
When building Python apps into executables, heavy packages imported at module level by dependencies get bundled entirely, bloating the exe size. Replacing unused packages with minimal stubs can significantly reduce size.
実証データ / Verified Results
asammdf プロジェクト — PyInstaller exe ビルド(E2E 動作確認済み):
| exe サイズ | 動作 | PySide6 | |
|---|---|---|---|
| スタブなし | 431 MB | OK | ロード済み |
| asammdf.gui スタブ適用 | 259 MB | OK | 排除 |
| 削減 | -40%(172 MB) | 影響なし |
asammdf 変換ツール(analyze 結果):
stubbable: pandas (59.7 MB), canmatrix (4.0 MB) — 合計 63.7 MB
submodule hints: asammdf.gui → PySide6 (523 MB) 排除可能 — 50 hints 検出
手動でスタブ化していた 3 パッケージ(pandas, canmatrix, asammdf.gui)を全て自動検出
Details
- Repository
- github.com/koyoyeager/mcp-pystub
- Package
mcp-pystub- Transport
- STDIO
- Registry
- MCP registry, active