A dual-mode, zero-token-cost local engineering engine built on the Model Context Protocol (MCP). It dynamically switches between Production Code Auditor (enforcing 10 strict engineering pillars) and System Architect & Strategist (generating topologies and execution plans) via local models in LM Studio, backed by a fast AST security filter, dual data sinks (SQLite & DPO-ready JSON logs), and a real-time Discord notification daemon.
| 🧩 The MCP Dual-Role Pipeline | ⚙️ Engineering Autonomous Reliability |
|---|---|
| A framework for synchronized, context-aware AI workflows | Pairs an Executor with a Critic in a localized environment |
| Feature | Description |
|---|---|
| Zero-Cost Local Critic | Offloads exhaustive validation loops to local GPUs via LM Studio without spending cloud tokens. |
| Sub-Millisecond AST Sentinel | Rejects Python syntax errors and blocks high-risk calls (eval, exec, os.system, subprocess) before hitting the LLM. |
| Dynamic Dual Modes | Automatically detects whether input is raw code or high-level architecture/specs, executing context-specific validation prompts. |
| Dual Data Persistence | Records execution metrics into SQLite (audit_history.db) and exports atomic JSON telemetry (audit_logs/) suitable for DPO fine-tuning datasets. |
| Live Discord Telemetry | Background daemon monitors audit output files in real time and pushes structured embeds directly to Discord. |
| Dynamic Model Discovery | Automatically queries LM Studio's active model endpoint, bypassing embedding engines dynamically. |
| 🌉 The Standardized Context Bridge | ⚖️ Separation of Concerns: Dual-Role Dynamic |
|---|---|
| Decoupled Read/Write operations via universal MCP layer | Executor (generation) vs Reviewer (zero-temperature validation) |
[ User Submission / Agent Request via MCP ]
│
▼
[ Stage 1: Fast AST Sentinel ] ─────────────────────────┐
(Syntax Parse & Danger Call Interception) │
│ (Valid Code or Specs) │ (Syntax / Security
▼ │ Violation)
[ Stage 2: Hybrid Dual-Role LLM ] │
(LM Studio Local Inference Server) │
├── Role 1: 10-Pillar Code Audit │
└── Role 2: Architecture & Master Plan │
│ │
▼ │
[ Stage 3: Multi-Sink Logger ] <───────────────────────┘
├── SQLite DB (Metrics & Analytics)
└── Atomic JSON Logs (DPO Datasets)
│
▼ (File Write Event)
[ Daemon: Discord Watcher Loop ]
(Rich Embed Notifications pushed to Webhook)
The engine routes tasks automatically based on the payload structure passed to audit_submission:
Audits incoming implementations against 10 strict defensive engineering rules:
- Logic & Edge Conditions: Null checks, division by zero, empty collections.
- Resource Leaks & Performance: Unclosed context managers, algorithmic bottlenecks.
- Defensive Boundaries: Type hints, data contracts via dataclasses, bounded loop guards.
- Deterministic Contract: Enforces a rigid feedback schema (
STATUS: APPROVEDorSTATUS: REJECTED).
| 🗺️ Pipeline Architecture Mapping | ⏱️ Chronological Execution Workflow |
|---|---|
| Orchestrator routing across MCP server and dual agents | Ingest → Query → Synthesize → Audit → Output pipeline |
Generates system designs for technical prompts without code:
- Component Topologies: Data flow patterns, directory structures, modular interconnects.
- Preemptive Risk Modeling: Concurrency bottlenecks, race conditions, failure points.
- Master Execution Plans: Step-by-step phased roadmaps ready for direct implementation.
watch_audit_logs.py runs as an asynchronous observer over the audit_logs/ directory, dispatching notifications whenever new audit artifacts are produced:
python watch_audit_logs.py
- Automated Polling: Tracks
.jsonadditions with debounce guards. - Markdown Formatting: Renders status tags (
APPROVED,REJECTED), duration metrics, summaries, and issue breakdowns. - Zero Configuration Fallback: Operates headlessly in the background without halting the core MCP pipeline.
| 🔄 The Autonomous Refinement Engine | 📦 Data Routing & State Management Payload |
|---|---|
| Continuous feedback loop eliminating hallucination drift | Strict turn-based JSON schema preventing infinite loops |
- Python 3.10+
- LM Studio running an OpenAI-compatible Local Server at
http://localhost:1234/v1 - Any MCP-compatible host client
# Clone the repository
git clone [https://github.com/xTanThaix/mcp-local-auditor.git](https://github.com/xTanThaix/mcp-local-auditor.git)
cd mcp-local-auditor
# Set up virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
Add the server definition into your client's mcpServers configuration (e.g., mcp_config.json):
{
"mcpServers": {
"lmstudio-auditor": {
"command": "python",
"args": ["/path/to/mcp-local-auditor/auditor_bridge.py"]
}
}
}
- Launch LM Studio and load an instruction-tuned model (e.g.,
Qwen-2.5-Coder,DeepSeek-Coder). - Open the Local Server tab.
- Set the port (default:
1234) and click Start Server.
To make your coding assistant iteratively fix its own mistakes, inject this instruction rule into your agent configuration:
# Mandatory MCP Code Audit Protocol
Every time code is generated or refactored, you MUST invoke the `audit_submission` tool:
- Arguments: `task_goal`, `output_content`, `strict_rules`
- If STATUS == "REJECTED": Inspect `ACTIONABLE_FEEDBACK`, remediate reported issues, and re-submit.
- If STATUS == "APPROVED": Deliver final verified code to the user.
- Cap recovery loops at a maximum of 5 attempts.
Run the full pytest suite to validate AST guards, SQLite migrations, and mocked inference pipelines without needing a live LM Studio instance:
pytest test_auditor.py -v
If this project helps streamline your local AI engineering workflow, consider supporting development:
- Ko-fi: https://ko-fi.com/xtanthaix
- GitHub Sponsors: Available directly via repository profile
Distributed under the MIT License. Free for personal, commercial, and open-source implementation.