Metadata-Version: 2.5
Name: fachwerk-mcp
Version: 0.1.0
Summary: MCP server for Python projects: coding agents can only write code that passed syntax, structure, black, isort, ruff and mypy
Project-URL: Homepage, https://github.com/manfred-kaiser/fachwerk-mcp
Project-URL: Documentation, https://fachwerk-mcp.readthedocs.io
Project-URL: Changelog, https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/CHANGELOG.md
Project-URL: Source, https://github.com/manfred-kaiser/fachwerk-mcp
Project-URL: Tracker, https://github.com/manfred-kaiser/fachwerk-mcp/issues
Author-email: Manfred Kaiser <manfred.kaiser@ssh-mitm.at>
Maintainer-email: Manfred Kaiser <manfred.kaiser@ssh-mitm.at>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,language-server,lsp,mcp,model-context-protocol,python
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: bandit<2,>=1.9
Requires-Dist: black<27,>=26.10
Requires-Dist: flake8<8,>=7.3
Requires-Dist: isort<10,>=9.0
Requires-Dist: mcp<3,>=2.3
Requires-Dist: mypy<3,>=2.4
Requires-Dist: pylint<5,>=4.0
Requires-Dist: ruff<0.18,>=0.17
Requires-Dist: ty<2,>=1.0
Provides-Extra: docs
Requires-Dist: myst-parser; extra == 'docs'
Requires-Dist: sphinx; extra == 'docs'
Requires-Dist: sphinx-copybutton; extra == 'docs'
Requires-Dist: sphinx-rtd-theme; extra == 'docs'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/manfred-kaiser/fachwerk-mcp/main/docs/_static/icon.svg" width="96" height="96" alt="fachwerk-mcp">
</p>

<h1 align="center">fachwerk-mcp</h1>

<p align="center">
  <strong>An MCP server for Python projects. What a coding agent writes is checked before it reaches your files.</strong><br>
  Every edit passes your strict checks first: black, isort, ruff, flake8, pylint, bandit, mypy and ty. A failed check writes nothing.
</p>

<p align="center">
  <a href="https://pypi.org/project/fachwerk-mcp"><img src="https://img.shields.io/pypi/v/fachwerk-mcp" alt="PyPI"></a>
  <a href="https://pypi.org/project/fachwerk-mcp"><img src="https://img.shields.io/pypi/pyversions/fachwerk-mcp" alt="Python versions"></a>
  <a href="https://github.com/manfred-kaiser/fachwerk-mcp/actions/workflows/ci.yml"><img src="https://github.com/manfred-kaiser/fachwerk-mcp/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
  <a href="https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/LICENSE"><img src="https://img.shields.io/github/license/manfred-kaiser/fachwerk-mcp" alt="License"></a>
</p>

<p align="center">
  <img src="https://raw.githubusercontent.com/manfred-kaiser/fachwerk-mcp/main/docs/_static/demo.svg" width="760" alt="An edit with a forgotten import and an unhandled None is rejected with every finding and nothing is written; the corrected edit is written, with the places that use it and the tests to run.">
</p>

---

## Why

A coding agent writes code that looks right and sometimes is not: an invented API, a forgotten import, an unhandled `None`, a shell command built from input. Reading every diff is the
only safeguard most setups have, and it does not scale. fachwerk-mcp moves the checks in front of the write. The strict chain you would run in CI runs on every edit, the agent gets the
findings back at once and fixes them, and what reaches your files has already passed.

<p align="center">
  <img src="https://raw.githubusercontent.com/manfred-kaiser/fachwerk-mcp/main/docs/_static/write-gate.svg" width="760" alt="One call: an edit passes syntax, structure, format, lint (ruff, flake8, pylint, bandit) and types (ty, mypy). Only then is it written; a failed check writes nothing and returns every finding to the agent.">
</p>

## How it keeps the code safe

<p align="center">
  <img src="https://raw.githubusercontent.com/manfred-kaiser/fachwerk-mcp/main/docs/_static/chain.svg" width="760" alt="The recommended policy drives black, isort, ruff, flake8, pylint, bandit, mypy and ty. The settings of the project are ignored in the default profile. An edit that adds a finding is rejected; findings that existed before the agent's work are counted and do not block.">
</p>

- **Checked before it is written.** An edit goes through the write gate in the same call: syntax, structure, safe fixes, format, lint (ruff, flake8, pylint, bandit) and types (ty, mypy).
  All or nothing: if one check fails, nothing is written and the agent gets every finding. It catches what models get wrong, including `# ... rest unchanged` placeholders.
- **Strict by default, and your project cannot quietly weaken it.** The default profile `recommended` runs the chain with a strict policy that ships with the server and ignores the rule
  selections and ignore lists of the project. If your project checks with other linters, results can differ, and the server says so. You choose once per project, with a question in
  your client or `fachwerk-mcp gate set`: `recommended`, `project` (your tools with your settings; the server can then no longer ensure that its strict rules are kept) or `custom`.
  A tool of the chain that cannot run blocks the write and is named; nothing passes unchecked by accident.
- **Only what the agent causes.** Existing code is not clean, and an agent should not drown in findings it did not write. Findings a file had before the work (git HEAD) are counted, not
  listed; only new ones block. The strict rules apply to new code, so a project can move toward them without a clean-up first.
- **Least privilege.** Three levels: `read`, `write`, `run` (default). Tests and commands run only inside a sandbox (bubblewrap, no network, `.git` and credential files protected); if the
  sandbox cannot start, commands are refused. A model cannot change its own rights: it may *propose* a few settings (interpreter, test command, ...), and only you confirm them. Anything
  that widens its access or weakens the checks can never be proposed.
- **You can see what happened.** Settings live outside your project, every change is in an audit log, `server_info` says what is active and what is degraded, and the call log shows what
  the agent did.

## What it does not do

- It is not a proof of security. Linters find known patterns; they do not replace a review of what matters.
- New suppression comments (`# nosec`, `# noqa`, `# type: ignore`) are not checked yet. This is a known, accepted gap of 0.1.0 (see the [changelog](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/CHANGELOG.md)).
- Only the recommended chain is tested and measured. Other combinations work, but are not verified.
- Commands and tests need bubblewrap, so they run on Linux only; reading and editing do not depend on the sandbox.

## Why this approach should work

The idea, putting the findings of static analysis back in front of the model until the code is clean, is not new, and it has been measured:

- **Security and quality improve with a feedback loop.** Blyth, Licorish, Treude and Wagner fed the findings of Bandit (security) and Pylint (quality) back to GPT-4o and asked it to fix them. Within ten iterations the share of generated code with security issues fell from over 40% to 13%, and the share with reliability warnings from over 50% to 11%. ([Static Analysis as a Feedback Loop: Enhancing LLM-Generated Code Beyond Correctness](https://arxiv.org/abs/2508.14419), 2025)
- **But an agent can clear a finding the wrong way.** Wynter found that external checker feedback lets cheaper coding agents repair many more rule violations, and also that agents often cleared a defect by deleting the newly added files. fachwerk-mcp shows every removal in its report ("Removed, not just changed") for that reason. ([Fixed or Deleted? External Feedback Lets Cheaper AI Coding Agents Repair Rule Violations](https://arxiv.org/abs/2611.29162), 2026)

These studies support the approach. They do not measure fachwerk-mcp itself.

## How well does it agree with your own checks?

The conformance harness (`python -m tests.conformance`) changes a project through the real tools and compares the verdict of the gate with the same chain run as plain commands. On five
Python projects, 10 changes each, the verdicts agreed in all but one case (a false block after a rename, fixed since and covered by a test). That is a small sample, and the harness is
there so you can run more on your own project.

## More

- **Made for Python.** Works on symbols, not lines; uses your virtual environment and your `pyproject.toml`; runs your tests with pytest.
- **Read little, write once.** Symbol index and reference search instead of whole files; one call per change.
- **One server for all your projects and clients.** OpenCode, Claude Code, Codex, Cursor, VS Code, Zed, ...
- **Little setup.** One command, no configuration file, all checking tools included. Nothing is written into your projects.

<p align="center">
  <img src="https://raw.githubusercontent.com/manfred-kaiser/fachwerk-mcp/main/docs/_static/architecture.svg" width="760" alt="OpenCode, Claude Code and other MCP clients connect over stdio or HTTP to one fachwerk-mcp server, which serves several Python projects with a symbol index, language servers, the write gate and a sandbox.">
</p>

## Quick start

Run this inside your Python project.

**OpenCode:** put this into `opencode.jsonc` in the project:

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "fachwerk": { "type": "local", "command": ["uvx", "fachwerk-mcp", "stdio"] }
    }
  }
}
```

**Claude Code:**

```sh
claude mcp add fachwerk -- uvx fachwerk-mcp stdio
```

That is all. The project you are in is the root; nothing else to install or configure.
Other clients: `fachwerk-mcp print-config <client>` prints the entry for OpenCode, Claude Code,
Codex, Cursor, VS Code and Zed. Prefer `pip`? `pip install fachwerk-mcp`, then use
`fachwerk-mcp stdio` as the command.

**Several projects or several clients?** Run one shared server instead; it prints the line that
connects your client:

```sh
fachwerk-mcp serve --root ~/projects/app --root ~/projects/lib --level write
```

Requires Python 3.12 or newer.

## Connect your agent

`fachwerk-mcp print-config <client>` prints the exact entry for each client
(`opencode`, `claude-code`, `codex`, `cursor`, `vscode`, `zed`); add `--level read|write` to
write a lower access level into it. The two agents below in detail.

### OpenCode

Put the entry into `opencode.jsonc` in your project, or into your global OpenCode config. OpenCode's
current configuration keeps servers under `mcp.servers`:

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "fachwerk": {
        "type": "local",
        "command": ["uvx", "fachwerk-mcp", "stdio"]
      }
    }
  }
}
```

| You want | Change |
| --- | --- |
| Edits but no commands, or read-only | append `"--level", "write"` (or `"read"`) to `command` |
| A fixed project, whatever folder you start in | append `"--root", "/home/you/projects/app"` to `command` |
| The shared server (`fachwerk-mcp serve`) | use `{"type": "remote", "url": "http://127.0.0.1:8808/mcp", "oauth": false, "headers": {"Authorization": "Bearer <token>"}}` instead of the `local` entry |
| To switch it off for a while | add `"disabled": true` to the server entry |
| The server in every project | `opencode mcp add --global`; without `--global` it writes to the project configuration |

OpenCode names the tools `fachwerk_code_*` (server name, underscore, tool name). To make the
write gate the only way to change files, deny OpenCode's own `edit` and `write` tools in its
permission settings; the [OpenCode MCP documentation](https://opencode.ai/docs/mcp-servers/)
has the current rules.

### Claude Code

Run this inside your project; it registers the server for you (user scope, stored in `~/.claude.json`):

```sh
claude mcp add fachwerk -- uvx fachwerk-mcp stdio
```

| You want | Command |
| --- | --- |
| The server only for this project, shared with your team through `.mcp.json` | `claude mcp add --scope project fachwerk -- uvx fachwerk-mcp stdio` |
| Edits but no commands | `claude mcp add fachwerk -- uvx fachwerk-mcp stdio --level write` |
| Read-only | `claude mcp add fachwerk -- uvx fachwerk-mcp stdio --level read` |
| A fixed project, whatever folder you start in | `claude mcp add fachwerk -- uvx fachwerk-mcp stdio --root ~/projects/app` |
| The shared server (`fachwerk-mcp serve`) | `claude mcp add --transport http fachwerk http://127.0.0.1:8808/mcp --header "Authorization: Bearer <token>"` |

Check with `claude mcp list`, or `/mcp` inside Claude Code. The tools show up as
`mcp__fachwerk__code_*`. Claude Code keeps its own `Edit` and `Write` tools next to them; to make
the write gate the only way to change files, deny those two in your permission settings
(`"permissions": {"deny": ["Edit", "Write"]}` in `.claude/settings.json`), so every edit has to
pass the checks. Run `/mcp` to reconnect after you update `fachwerk-mcp`.

## Learn more

[Quick start in detail](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/quickstart.md) ·
[The write gate](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/write-gate.md) ·
[How the gate checks](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/gate.md) ·
[Made for Python](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/python.md) ·
[Tools and access levels](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/tools.md) ·
[Projects, caches, language servers](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/projects.md) ·
[Architecture](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/architecture.md) ·
[Security](https://github.com/manfred-kaiser/fachwerk-mcp/blob/main/docs/security.md)

Built on the official [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk). MIT licensed.
