Skip to main content
Glama
xTanTHaix

MCP Local Auditor & Architect

πŸ›‘οΈ MCP Local Auditor & System Architect V2

Python Version Protocol Runtime License: MIT

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


✨ Core Capabilities

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)


Related MCP server: Portable MCP Toolkit

πŸ”„ System Architecture

       [ 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)

🎭 Dynamic Dual-Role Modes

The engine routes tasks automatically based on the payload structure passed to audit_submission:

1. Code Auditor Mode (Activated on Code Submissions)

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: APPROVED or STATUS: REJECTED).


πŸ—ΊοΈ Pipeline Architecture Mapping

⏱️ Chronological Execution Workflow

Orchestrator routing across MCP server and dual agents

Ingest β†’ Query β†’ Synthesize β†’ Audit β†’ Output pipeline


2. System Architect & Strategist Mode (Activated on Specs/Plans)

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.


πŸ“‘ Real-Time Discord Watcher

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 .json additions 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


πŸš€ Quick Start

1. Prerequisites

  • Python 3.10+

  • LM Studio running an OpenAI-compatible Local Server at http://localhost:1234/v1

  • Any MCP-compatible host client

2. Installation

# 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

3. Register with MCP Client

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"]
    }
  }
}

4. Configure LM Studio

  1. Launch LM Studio and load an instruction-tuned model (e.g., Qwen-2.5-Coder, DeepSeek-Coder).

  2. Open the Local Server tab.

  3. Set the port (default: 1234) and click Start Server.


πŸ—οΈ Deployment Dependencies & Infrastructure

πŸš€ Pipeline Characteristics & Extensibility

Modular runtime stack connecting local MCP servers with LLMs

Guaranteed context alignment and drop-in extensibility


πŸ€– Agent Loop Protocol

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.

πŸ§ͺ Test Suite

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

πŸ’– Support & Donations

If this project helps streamline your local AI engineering workflow, consider supporting development:


πŸ“„ License

Distributed under the MIT License. Free for personal, commercial, and open-source implementation.

Related MCP Connectors

Related MCP Servers

  • F
    license
    C
    quality
    C
    maintenance
    Enterprise-grade code intelligence platform providing AI-powered code analysis, semantic search, security scanning, and automated refactoring capabilities. Integrates with local AI models for zero-cost operations while delivering comprehensive development workflow automation.
    2
    8
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides AI-powered code intelligence for any codebase using local LLMs and vector search, enabling semantic code search, pattern analysis, and context-optimized code generation with 90% token savings.
    2
    MIT
  • A
    license
    C
    quality
    D
    maintenance
    A privacy-first MCP server that provides local LLM-enhanced tools for code analysis, security scanning, and automated task execution using backends like Ollama and LM Studio. It enables symbol-aware code reviews and workspace exploration while ensuring that all code and analysis remain strictly on your local machine.
    36
    ISC
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to perform hybrid code search, get explanations, analyze relations and impacts, retrieve context packs, and generate documentation across ~45 languages via 17 MCP tools, all powered by a local vector database and LLM.
    2
    Apache 2.0