get_python_codeLABSCO SUMMARY
Import graph in, token budget respected.
The useful part is the budget: extraction stops rather than handing a model more than it can hold, and the response reports the count so you can raise the limit deliberately. Always including the README is a small decision that pays off — a model reading extracted code usually has no idea what the project is for. One tool, Python only.
What it is
An MCP server that extracts a Python file together with the code it actually depends on. It analyses the target file's imports, pulls the definitions of the referenced classes and functions from other files, adds context from the same directory, and stops before it blows the token budget.
What you get
- A target file's complete code plus the code of every referenced object from other files, with the file path, docstring and object type for each —
get_python_code - Additional files from the same directory included for context
- README.md and its variants always included, so project documentation travels with the code
- A running token count reported against the limit, so you can see how close the extraction came
- Output formatted with metadata for language models rather than as raw file dumps
Requirements
No account and no key — it runs locally with no agent system behind it. Clone the repository, create a virtual environment, and install the checkout with pip install -e . — its dependencies are declared in pyproject.toml (the requirements.txt the README mentions is not in the repository). Configure the client to run python <YOUR_PATH_TO_PYTHON_MCP>/server.py with TOKEN_LIMIT in its environment; the default is 8000. The root_repo_path argument is optional and defaults to the target file's directory. Package name python-mcp 0.1.0.
Setup effort
Build from source — git clone https://github.com/hesiod-au/python-mcp
USE CASES
Explaining a file that leans on the rest of the project
Extract it together with the definitions of everything it imports, so the model is not inferring signatures.
Onboarding into an unfamiliar module
Pull the target file plus its directory neighbours and the README in one call.
Keeping a large extraction inside the context you have
Set the token limit to what your model can take and read back the reported count to see whether anything was trimmed.
1 tool
Listed in project docs. Your client may show a different list.
BEFORE YOU INSTALL
What to know first
Tools you get
1 tool named in the project's documentation.
Requires
Python 3.10+
INSTALLATION
Connect your client
Server setup
git clone https://github.com/hesiod-au/python-mcp
cd python-mcp
python -m venv venv
source venv/bin/activate
pip install -e .
pip install "mcp[cli]"
cp .env.example .envMCP Clients
Windsurf, Any MCP client
{
"mcpServers": {
"python-code-explorer": {
"command": "python",
"args": [
"<YOUR_PATH_TO_PYTHON_MCP>/server.py"
],
"env": {
"TOKEN_LIMIT": "8000"
}
}
}
}<YOUR_PATH_TO_PYTHON_MCP>/server.py is the absolute path of server.py in your clone, and use the python inside its venv (<YOUR_PATH_TO_PYTHON_MCP>/venv/bin/python) as the command so the installed dependencies are found.
Claude Desktop
mcp install server.py --name "Python Code Explorer" -f .env