# eqtylab/mcp-guardian architecture

> Architecture diagram of the GitHub repository eqtylab/mcp-guardian, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eqtylab/mcp-guardian
- Repository: https://github.com/eqtylab/mcp-guardian

## Overview

##### Project Type and Purpose
- MCP Guardian is a multi-component Rust/TypeScript application for intercepting and controlling LLM “tool call” messages to external MCP servers.
- It consists of:
- A core library (`mcp-guardian-core`) that implements guard logic, profiles, caching, and a proxy engine.
- A CLI (`mcp-guardian-cli`) to manage profiles, servers, and collections.
- A background proxy service (`mcp-guardian-proxy`) that intercepts LLM traffic.
- A desktop GUI (`mcp-guardian`, built with Tauri + React/TypeScript) for real-time logging and manual approvals.

##### File Structure
- Top-level crates/directories:
- `mcp-guardian-core`: core logic and data structures
- `mcp-guardian-cli`: command-line interface
- `mcp-guardian-proxy`: daemon that delegates to the core proxy engine
- `mcp-guardian`: Tauri desktop app (Rust backend + React front-end)
- Shared configuration is read/written via the core library (`config.rs`, `dirs.rs`).
- Bindings under each crate connect the core structures to TypeScript or to CLI modules.
- The `docs` folder contains user guides but is not part of runtime architecture.

##### Extract Insights from README
- The system sits “in-line” between your LLM and MCP server endpoints.
- Features include:
- Message Logging
- Manual Approvals
- (Future) Automated Scanning
- The GUI communicates with the running proxy to display logs and send approval/deny commands.

##### Main Components & Interactions
a. Components:
1. LLM Client (e.g., ChatGPT, local LLM)—generates tool-call HTTP/TCP requests.
2. Proxy Service (`mcp-guardian-proxy` CLI or built-in in Tauri backend)—listens on localhost, forwards requests.
3. Core Library (`mcp-guardian-core` crate)—implements guard profiles, message interceptor pipeline, caching, and proxy engine.
4. Configuration Store (local filesystem via `dirs.rs`)—persists guard profiles, server collections.
5. CLI Application (`mcp-guardian-cli`)—CRUD on profiles, servers, and collections via core library APIs.
6. Desktop GUI (`mcp-guardian`):
- Front-end (React/TypeScript) — renders pages, dialogs, logs, pending messages.
- Tauri Backend (Rust) — invokes core library functions, starts/stops proxy, exposes a local HTTP/WS API to the front-end.
7. External MCP Server(s)—actual Minecraft-like or other tool-host servers.

b. Relationships & Data Flows:
- LLM Client → Proxy Service (request)
- Proxy Service → Core Library (intercept & apply guard logic)
- Core Library → Configuration Store (load profiles, record logs/cache)
- Core Library → External MCP Server (forward allowed messages)
- Proxy Service ←→ GUI (HTTP/WS API):
– GUI pulls logs, pending message lists
– GUI issues Approve/Deny commands
- CLI → Core Library → Configuration Store (manage profiles, servers, collections)

c. Architectural Patterns & Principles:
- Layered separation: Core library independent of presentation (CLI/GUI) and transport (proxy).
- Single source of truth for guard logic in the `core` crate.
- Reuse of core across three front-ends (CLI, proxy daemon, Tauri backend).
- Event-driven intercept pipeline for messages (chain of interceptors, filters, manual approval hooks).
- Configuration-as-code: JSON profiles under `src/guard_profile/profiles`.

d. Key Technologies:
- Rust (all back-end logic, CLI, proxy, Tauri backend)
- TypeScript + React (desktop UI)
- Tauri (bridging Rust & web UI into desktop app)
- nix + flakes, Justfile (build & dev environments)
- JSON files for default profiles and server definitions

##### Essential Details
- The interceptor pipeline in the core: filters, chain guards, manual approval hook, message logging.
- The core’s config directory layout (guard_profiles, mcp_servers, server_collections).
- How Tauri Backend spawns or integrates with the proxy engine versus the standalone `mcp-guardian-proxy`.
- Data flow of a tool-call request from client → proxy → core → server, and back with logs sent to GUI.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend UI"
        ReactApp["React Front-End"]:::frontend
        CLIApp["CLI Application"]:::frontend
    end

    subgraph "Tauri Backend"
        Tauri["Tauri Backend (Rust)"]:::frontend
    end

    subgraph "Core Library & Proxy Engine"
        Core["Core Library"]:::core
        Interceptor["Interceptor Pipeline"]:::core
        Cache["Request Cache"]:::core
        ConfigStore["Configuration Store"]:::config
        Proxy["Proxy Service Daemon"]:::proxy
    end

    subgraph "External Systems"
        LLM["LLM Client"]:::external
        MCP["External MCP Server"]:::external
    end

    LLM -->|HTTP/TCP Request| Proxy
    Proxy -->|Intercepts & Forwards| Core
    Core -->|Load/Save Profiles & Logs| ConfigStore
    Core -->|Cache Requests| Cache
    Core -->|Forward Allowed Messages| MCP

    CLIApp -->|CRUD Profiles/Servers| Core
    Tauri -->|Invoke Core APIs| Core
    Tauri -->|Start/Stop Proxy| Proxy
    ReactApp -->|HTTP/WS API| Tauri
    ReactApp -->|Approve/Deny Commands| Tauri

    click ReactApp "https://github.com/eqtylab/mcp-guardian/blob/main/mcp-guardian/src/App.tsx"
    click CLIApp "https://github.com/eqtylab/mcp-guardian/blob/main/mcp-guardian-cli/src/main.rs"
    click Tauri "https://github.com/eqtylab/mcp-guardian/blob/main/mcp-guardian/src-tauri/src/main.rs"
    click Core "https://github.com/eqtylab/mcp-guardian/blob/main/mcp-guardian-core/src/lib.rs"
    click ConfigStore "https://github.com/eqtylab/mcp-guardian/blob/main/mcp-guardian-core/src/config.rs"
    click Proxy "https://github.com/eqtylab/mcp-guardian/blob/main/mcp-guardian-proxy/src/main.rs"

    classDef frontend fill:#a3d5ff,stroke:#333,stroke-width:1px
    classDef core fill:#a8f0c6,stroke:#333,stroke-width:1px
    classDef proxy fill:#ffcc99,stroke:#333,stroke-width:1px
    classDef config fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef external fill:#d3d3f0,stroke:#333,stroke-width:1px
```
