
Django Chainsaw
io.github.syrian963Published by GitHub account syrian963v0.1.5Updated Oct 24, 2026
Finds what will hurt in a Django project: cascades, N+1, unsafe migrations, tenant leaks.
Overview
Analyzes a Django project's code and models to surface risky cascades, N+1 queries, unsafe migrations, and tenant leaks.
- What you can do
- Django Chainsaw statically inspects a Django project using the AST and Django's app registry, without running the application. It offers around 37 tools covering delete impact, N+1 detection, migration and deploy safety, unscoped queries, signal side effects, missing indexes, serializer exposure, race conditions, and money precision. A check command merges all applicable findings into one severity-sorted list with a single exit code, and a report command produces a self-contained HTML file. It also includes a few checks for non-Django Python projects such as FastAPI and SQLAlchemy.
- When to use it
- Use it when reviewing or maintaining a Django codebase and you want to know what a delete cascades to, which migration is unsafe to ship, which query may read another tenant's data, or where N+1 queries live. It is also useful in CI to gate pull requests on new findings via baseline and SARIF output.
- Requirements
- Runs as a local process via the PyPI package django-chainsaw-mcp, installed into an interpreter that can import the target project. Requires the environment variables DJANGO_CHAINSAW_PROJECT_PATH and DJANGO_CHAINSAW_SETTINGS_MODULE. No authentication or network access is declared.
Installation
In SourceWeft
- Open Django Chainsaw in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
django-chainsaw-mcp
[release] [checks] [MCP tools] [CLI commands] [prompts]
[tests] [coverage] [python] [django] [license]
An MCP server and CLI that analyses a Django project rather than describing
it. Not what is in here — what will hurt: what a delete takes with it,
which migration breaks the pods still running, which query returns another
tenant's row, what a save() sets off three hops away.
There is no model in the loop. Every answer comes from the AST and Django's own app registry, so the same input gives the same output, and nothing leaves the machine. It is an MCP server so an assistant can ask it questions, and a CLI so CI can gate on the answers.
22 checks: 19 need the app registry (16 Django, three of those DRF as well), one needs only Python, one reads FastAPI, one reads SQLAlchemy. Why this exists →
Install
It has to run in an interpreter that can import your project. Everything
here reads the app registry, which means django.setup(), your settings and
your apps:
A plain uvx django-chainsaw-mcp starts and then fails every check, because
uvx gives it an isolated environment with no trace of your project. To avoid
installing, hand uv the dependencies instead:
Two environment variables point it at the project:
django-chainsaw project-info proves the setup before anything else, and says
which half is missing. Five minutes end to end →
mcp-name: io.github.syrian963/django-chainsaw-mcp
One command
Every analysis, merged, worst first, one exit code.
On a pull request
This is the part that decides whether a tool like this survives. Point tenancy
at a five year old project and it returns two hundred candidates; nobody reads
two hundred candidates, somebody adds continue-on-error, and it runs forever
with nobody looking.
--since compares at the merge base, so a branch that is behind main is not
blamed for other people's work. --baseline keeps existing findings in the
report and stops them blocking; anything new fails the build, and fixing an old
one is reported so the number only ever goes down. Findings are fingerprinted on
file plus identity, never the line, so adding an import does not resurrect
twenty findings nobody touched.
--sarif writes the format GitHub and GitLab annotate a pull request with, so
findings land on the line instead of in a log nobody opens.
As an MCP server
Ask it project_info first: the smallest call that proves both the transport
and the Django boot. Five prompts carry the ordering the tools do not —
before_deploy, why_is_this_slow, what_breaks_if_i_delete, triage,
review_this_branch.
Claude Desktop, Cursor, VS Code, Windsurf, Zed, Docker →
Or as one HTML file
[The HTML report, grouped by endpoint]
Grouped by endpoint is the view that matters: which pages carry this, and through what call path. No server, no network, no build step — the CSS, the script and the data are all in the file, so it works from a CI artifact or an email attachment. report.md
The checks
Django projects — these read the app registry, so they need DJANGO_CHAINSAW_SETTINGS_MODULE as well as the project path
Any Python project — no Django, no settings module
Plus the resource django://models. check profiles the project first and runs
what applies, and says "does not apply, and here is why" for the rest —
silence would read exactly like a clean result. Nothing about the FastAPI
support imports the project, so those checks run on a checkout with no
dependencies installed at all.
36 of the 37 tools declare readOnlyHint, so a client can stop asking
permission for each call; the exception is api_contract_check with
update=True, which writes the snapshot and says so.
Every tool, argument and output shape →
What it will not tell you
Nothing here executes the target project or reads its data, which buys safety and speed and costs certainty. Every tool states its own blind spots in its own output:
delete_impactdoes not run signals or customdelete()overrides.find_n_plus_onereports candidates; it reads the template and the model graph, not the queryset in the view.migration_riskdoes not know row counts, PostgreSQL version, or deploy strategy.deploy_safetycannot seegetattr(obj, name), runtime SQL, or another repository.CLEARmeans nothing was found here.
A confident wrong answer is worse than an incomplete one. In this kind of tooling the failure mode is not a crash, it is a plausible sentence that sends someone in the wrong direction. limitations.md
What it does to your code
It imports the target project. django.setup() imports your settings and
every app in INSTALLED_APPS, and the checks additionally import the modules
that declare serializers, views and URLs — so anything those do at import time
happens. Do not point this at code you would not run.
It does not run your application: no view, no task, no management command.
One check reads the database, read-only — MigrationLoader reads
django_migrations, and nothing is written.
It writes files only when you ask: fix --write applies the mechanical
class of fix only, and a baseline, a contract snapshot or --sarif write where
you tell them to. Nothing leaves the machine — no network calls, no
telemetry, no uploads.
Documentation
docs/ is the index.
Contributing
A proposal for a new check answers four questions, which the issue template asks directly: what the defect looks like as code, how it fails in production, what already finds it, and what it must stay silent on. Two finished features were deleted from this repository after measurement showed they could not tell a real finding from a correct one.
MIT. One process stays bound to the first project it loads, because
django.setup() cannot be undone — run a second instance for a second project.
Source: README.md at commit dec9d15
Tools
0Version history
1- v0.1.5LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts