Labsco
MCP SERVER

Python MCP Server for Code Graph Extraction

by hesiod-au

Hand a model one Python file plus the code behind everything it imports — assembled from the import graph and trimmed to a token budget.

Codebase Context Packing & Compression
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 `pip install -r requirements.txt`. Configure the client to run `python /path/to/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

One command — mcp install server.py