Back to main

The Soul OS Middleware: Building an MCP-Compliant Reality Gate

[ AUTHORIAL INTENT & AI DISCLOSURE ]

This post was synthesized from the Soul OS architectural registry and technical design documents. Strategic framing and system invariants were drafted by Teddy (Distributed Systems Architect) in collaboration with Sir.

Forensic Hygiene Active
View Policy Standard →

In the evolution of sovereign agentic systems, we eventually hit the Babel Problem.

I have been using Gemini-CLI as my primary developer tool good part of last year. I have honed it a lot. The reason being, it lacked most of the things I wanted when I started using it, and I had to roll my own. I have created a SOUL ecosystem around it. I call them SOUL kernels. While these kernels are the engine of my personal workflow, their DNA is rooted in the collective wisdom of the industry—patterns of agency and forensic auditing that I have meticulously tuned for high-fidelity production. I am trying to make this kernel decoupled from gemini-cli now so I can also use it in places like pi-agent.

When logic is duplicated across kernels, Architectural Drift is inevitable. You end up with two different versions of “The Truth,” two different auditing protocols, and a system that is twice as hard to harden.

To solve this, I am looking into different ways of pivoting. One idea is to build the Soul OS Middleware Hub: a kernel-agnostic, MCP-compliant “Reality Gate” that centralizes the Socratic Audit logic into a stateless, high-fidelity logic engine.

🏗️ Why MCP? (The Universal Translator)

I am not a MCP fan when it comes to using it as a replacement for API. I am looking at you Google Workspace MCP. It’s a blackbox and not useful. However that same standard protocol might be a good idea when we are sharing logic across different harnesses. Think of it as “USB-C” of agentic communication. By adopting an MCP-compliant JSON-RPC 2.0 layer, we can decouple the reasoning logic from the execution kernel.

  • Pi Agent (TS): Connects via a native bridge to the middleware.
  • Gemini CLI (Python): Wraps tool calls in the same RPC schema.
  • The Result: A single source of truth for all “Interception Engineering.”

This reduces “Hook Latency” by nearly 80% by maintaining persistent connections rather than spawning fresh shell hooks for every interception turn.


🛑 The Socratic Gate: soul_audit_turn

I have started to use a very strict layer 1 gate. The heart of the middleware is the Audit Turn. This is the physical “Reality Gate” that every agent—regardless of its language—must pass through before it can touch the filesystem.

When an agent proposes a tool execution, the middleware receives an AuditRequest:

{
  "kernel": "pi" | "gemini",
  "project": "soul",
  "event": "BeforeTool",
  "context": {
    "active_task": "task-ID",
    "tool_name": "run_shell_command",
    "tool_args": { "command": "rm -rf /dist" },
    "llm_reasoning": "Cleaning up the build artifacts to ensure a fresh state."
  }
}

The Middleware doesn’t just check syntax. It checks Mission Intent. It looks at the active_task in the Sovereign Registry and asks: “Does this command align with the current strategic mandate?”

The AuditResponse determines the next 500ms of the agent’s life:

  • allow: Proceed to execution.
  • deny: Block with a policy violation.
  • ask_user: Trigger a Socratic Bridge (TUI confirmation). (For some reason I couldn’t find a way to make ask_user to work with hooks in gemini-cli yet)

🛠️ The Architecture of Control

I’ve restructured the soul/ directory to reflect this centralization. Logic is no longer buried in kernel-specific hooks; it lives in the shared middleware/ layer.

soul/
├── core/
│   └── middleware/             # <-- SHARED LOGIC (Stateless)
│       ├── auditor.py          # Socratic Critique Logic
│       └── steerer.py          # Mission Context Enforcement
├── kernel/
│   ├── mcp/                    # <-- MCP SERVER LAYER
│   │   ├── server.py           # FastAPI/MCP-SDK Hub
│   │   └── schema.py           # RPC Communication Models
│   └── harnesses/              # <-- KERNEL ADAPTERS
│       ├── gemini_cli/         # Python Wrapper
│       └── pi_agent/           # TS Extension Relay

This shift represents a fundamental transition in how we build AI-native infrastructure:

  1. Technical Multiplier: By centralizing the “Reality Gate,” we can harden the entire ecosystem (CLI, UI, and Pi) simultaneously.
  2. Architectural Depth: We eliminate the “Signal Black Hole” by forcing all agent events through a traceable, JSON-RPC-logged pipe.
  3. Sovereign Control: We move from reactive prompt engineering to proactive Interception Engineering.

The Soul OS Middleware Hub is how we ensure that as our agentic swarm grows, its reasoning remains unified, traceable, and above all, Sovereign.


Lead Architect: Ilteris Kaplan
Date: March 28, 2026
Trace ID: MCP-HUB-V8


Back to main