Metadata-Version: 2.4
Name: mfabric
Version: 0.3.0
Summary: Zero-config mutual-TLS 1.3 OpenAI mesh router for every computer you own.
Author: Sfiniti AI Inc.
License: MIT License
        
        Copyright (c) 2026 Sfiniti AI Inc.
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://sfiniti.ai
Project-URL: Repository, https://github.com/sfiniti-ai/mfabric
Project-URL: Issues, https://github.com/sfiniti-ai/mfabric/issues
Project-URL: Changelog, https://github.com/sfiniti-ai/mfabric/blob/main/CHANGELOG.md
Project-URL: Security, https://github.com/sfiniti-ai/mfabric/blob/main/SECURITY.md
Keywords: openai,llm,router,mtls,ollama,vllm,lm-studio,llama-cpp,local-ai,mesh
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security :: Cryptography
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: cryptography>=42.0
Requires-Dist: psutil>=5.9
Requires-Dist: zeroconf>=0.132
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Dynamic: license-file

# MFabric

[![License: MIT](https://img.shields.io/badge/License-MIT-amber.svg)](LICENSE)
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)

**Zero-config mutual-TLS 1.3 OpenAI mesh router for every computer you own.**

Expose one local OpenAI-compatible endpoint (`http://127.0.0.1:8788/v1`) on your laptop or workstation that securely routes across **Ollama**, **LM Studio**, **vLLM**, and **llama.cpp (`llama-server`)** running on your other macOS, Linux, and Windows machines—with **no cloud account, no mandatory VPN install, no static YAML, and no manual API key files**.

---

## Why MFabric?

- **60-Second Zero-Keyfile Pairing $\to$ Mutual TLS 1.3:** Compare a 6-word Short Authentication String (HKDF-bound to both the Fabric Root CA and the helper's ECDSA P-256 + Ed25519 public keys) and approve once. MFabric issues pinned X.509 leaf certificates automatically, encrypting every prompt and streamed token over Wi-Fi/LAN with TLS 1.3 mutual authentication.
- **Keep Model Servers Safely on `127.0.0.1`:** Leave Ollama (`:11434`), LM Studio (`:1234`), vLLM (`:8000`), and `llama-server` bound strictly to loopback so unauthenticated model ports are never exposed on `0.0.0.0`.
- **Drop-In OpenAI `/v1` Compatibility:** Works out of the box with **Cursor**, **Continue**, **Cline**, **Open WebUI**, and the official **`openai` Python/TypeScript SDKs**—including multi-turn `messages[]`, real-time SSE `stream: true`, `tools` / `tool_choice`, `reasoning_content`, `/v1/embeddings`, and instant TCP disconnect cancellation.
- **Presence, Battery & VRAM-Aware Routing:** Virtual models (`auto`, `fast`), canonical model names, and pinned `@peer/model` targets automatically steer away from unplugged laptops on battery or desktops under heavy foreground GPU load, with seamless pre-first-token failover.
- **Dual-Signed Content-Free Execution Receipts:** Every routed response records a `mfabric.receipt.v3` signed by **both** the executing helper's Ed25519 key and your host's Ed25519 key (with zero prompt or output text stored), verifiable offline via `mfab receipts verify`.

---

## Install (macOS, Linux, Windows)

Requires **Python 3.11 or newer**:

```bash
pip install mfabric
mfab doctor
```

*(Both `mfab` and `mfabric` CLI commands are installed; you can also isolate it with `pipx install mfabric` or `uv tool install mfabric`.)*

---

## Quickstart (Two Machines, Under 60 Seconds)

### 1. Start the router on your primary computer (Host)

```bash
mfab up -d
```

This starts your local OpenAI `/v1` router and web dashboard on `http://127.0.0.1:8788` plus the LAN pairing listener on port `8935`.

### 2. Join any GPU desktop, workstation, or Mac on your network (Helper)

If **Ollama**, **LM Studio**, or **vLLM** is already running on `127.0.0.1` on that machine, MFabric discovers its models automatically. Need a standalone GGUF runtime? Run `mfab install-llama` first to fetch an official SHA-256-verified `llama-server` build for CUDA, Metal, Vulkan, or CPU.

```bash
# Auto-discovers your host over mDNS, or pass the Join URL explicitly:
mfab join -d
# Explicit URL fallback (or when mDNS is blocked / disabled):
# mfab join http://<host-lan-ip>:8935 --no-discovery -d
```

Verify that the **6-word pairing phrase** shown on the helper matches `mfab pending` (or `http://127.0.0.1:8788`) on your host, then approve that exact phrase:

```bash
mfab approve "<6-word-phrase>"
# (or bare `mfab approve` when only a single request is pending)
```

### 3. Point any OpenAI client at `http://127.0.0.1:8788/v1`

```bash
mfab peers
mfab models
mfab chat "Write a lock-free ring buffer in C++20."
```

#### Python (`openai` SDK)
```python
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8788/v1", api_key="local")
stream = client.chat.completions.create(
    model="auto",  # or "fast", "qwen2.5-coder:32b", or "@workstation/qwen2.5-coder:32b"
    messages=[{"role": "user", "content": "Explain mutual TLS 1.3 in three sentences."}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
```

#### Cursor / Continue / Cline / Open WebUI
- **OpenAI Base URL:** `http://127.0.0.1:8788/v1`
- **API Key:** `local` *(or set `MFABRIC_API_KEY` before `mfab up` to enforce a custom Bearer token)*
- **Model:** `auto`, `fast`, any discovered model ID, or `@<peer_id>/<model_id>` to pin a specific machine.

---

## What Can I Do Next?

| Goal | Command |
|---|---|
| Inspect live nodes, GPUs, battery state & models | `mfab status` or `mfab peers` |
| Pin a prompt to one exact machine (fail-closed, no failover) | `mfab chat -m "@studio-mac/qwen2.5-coder:32b" "Refactor this module"` |
| Serve a local `.gguf` file directly without Ollama/LM Studio | `mfab install-llama && mfab join --model ~/Models/qwen2.5-7b-instruct-q4_k_m.gguf -d` |
| Verify cryptographic proof of which machine ran a request | `mfab receipts list` $\to$ `mfab receipts verify <receipt_id>` |
| Revoke a helper immediately (pushes signed mTLS shutdown) | `mfab revoke <peer_id>` |
| Run automatically at login (LaunchAgent / systemd / Startup) | `mfab service install --role helper` (or `--role host`) |
| Require a Bearer API key on `/v1/*` and `/api/*` | Set `MFABRIC_API_KEY="<secret>"` in your environment before `mfab up` |
| Stop background host/helper processes | `mfab down` |

---

## Operating-System & Firewall Notes

- **macOS:** The first time you run `mfab up` or `mfab join`, allow your terminal or IDE under **System Settings $\to$ Privacy & Security $\to$ Local Network**. To keep a Mac helper awake while serving with the display off, run `caffeinate -dimsu` in a separate tab.
- **Windows:** Windows Defender Firewall prompts on first LAN bind (or blocks inbound connections on Public network profiles). Set your trusted home/office Wi-Fi or Ethernet to **Private network**, or run the exact `New-NetFirewallRule` command printed by `mfab join` if reachback fails.
- **Linux:** If `ufw` or `firewalld` is active, allow inbound TCP `8935` on the host (for pairing) and TCP `8789` on helpers from your private LAN subnet (e.g., `sudo ufw allow from 192.168.0.0/16 to any port 8789 proto tcp`).

---

## Security Model & Beta Caveats

- **Mutual TLS 1.3 Inference Transport:** All `/v1/*` model traffic and `/mesh/v1/*` health checks between Host and Helpers run over TLS 1.3 with mutual certificate verification (`CERT_REQUIRED`), SHA-256 leaf fingerprint pinning, and X.509 URI SAN role checks (`urn:mfabric:host:<id>` vs. `urn:mfabric:peer:<id>`). Compromising one helper certificate does **not** grant lateral access to other helpers.
- **Explicit Pairing Approval:** LAN mDNS discovery (`_mfabric-v3._tcp.local.`) only locates candidate host addresses and can be disabled with `--no-discovery`. No machine can join or receive a certificate until you verify the 6-word SAS phrase and approve on the host.
- **Loopback Protection:** The host console (`127.0.0.1:8788`) enforces `Host`-header allowlisting (blocking DNS rebinding), `Origin` validation, and `Content-Type: application/json` checks against cross-origin browser CSRF.
- **What MFabric v0.3 Does *Not* Do:** MFabric v0.3 routes whole OpenAI requests across independent runtimes and fails over *before* the first output token; it does not shard a single model's weights across multiple machines over Wi-Fi, and revoking a peer blocks new MFabric dispatches without altering your local Ollama/vLLM installation. Do **not** port-forward `:8788` or `:8935` to the public Internet.

---

## License

MIT License. Copyright (c) 2026 Sfiniti AI Inc. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
