MCard: Local-first Content Addressable Storage with Content Type Detection
Project description
MCard
MCard is a local-first, content-addressable storage platform with cryptographic integrity, temporal ordering, and a Polynomial Type Runtime (PTR) that orchestrates polyglot execution. It gives teams a verifiable data backbone without sacrificing developer ergonomics or observability.
Highlights
- 🔐 Hash-verifiable storage: Unified network of relationships via SHA-256 hashing across content, handles, and history.
- ♾️ Universal Substrate: Emulates the Turing Machine "Infinitely Long Tape" via relational queries for computable DSLs.
- ♻️ Deterministic execution: PTR mediates 8 polyglot runtimes (Python, JavaScript, Rust, C, WASM, Lean, R, Julia).
- 📊 Enterprise ready: Structured logging, CI/CD pipeline, security auditing, 99%+ automated test coverage.
- 🧠 AI-native extensions: GraphRAG engine, optional LLM runtime, and optimized multimodal vision (
moondream). - ⚛️ Quantum NLP: Optional
lambeq+ PyTorch integration for pregroup grammar and quantum circuit compilation. - 🧰 Developer friendly: Rich Python API, TypeScript SDK, BMAD-driven TDD workflow, numerous examples.
- 📐 Algorithm Benchmarks: Sine comparison (Taylor vs Chebyshev) across Python, C, and Rust.
- ⚡ High Performance: Optimized test suite (~37s) with runtime caching and session-scoped fixtures.
For the long-form narrative and chapter roadmap, see docs/Narrative_Roadmap.md. Architectural philosophy is captured in docs/architecture/Monadic_Duality.md.
Quick Start (Python)
git clone https://github.com/xlp0/MCard_TDD.git
cd MCard_TDD
./activate_venv.sh # installs uv & dependencies
uv run pytest -q -m "not slow" # run the fast Python test suite
uv run python -m mcard.ptr.cli run chapters/chapter_01_arithmetic/addition.yaml
Create and retrieve a card:
from mcard import MCard, default_collection
card = MCard("Hello MCard")
hash_value = default_collection.add(card)
retrieved = default_collection.get(hash_value)
print(retrieved.get_content(as_text=True))
Quick Start (JavaScript / WASM)
See mcard-js/README.md for build, testing, and npm publishing instructions for the TypeScript implementation.
- mcard-browser: A standalone browser application using
mcard-js(depends onmcard-jspackage).
Quick Start (Quantum NLP)
MCard optionally integrates with lambeq for quantum natural language processing using pregroup grammar:
# Install with Quantum NLP support (requires Python 3.10+)
uv pip install -e ".[qnlp]"
# Parse a sentence into a pregroup grammar diagram
uv run python scripts/lambeq_web.py "John gave Mary a flower"
Example output (pregroup types):
John: n gave: n.r @ s @ n.l @ n.l Mary: n a flower: n
Result: s (grammatically valid sentence)
The pregroup diagrams can be compiled to quantum circuits for QNLP experiments.
Polyglot Runtime Matrix
| Runtime | Status | Notes |
|---|---|---|
| Python | ✅ | Reference implementation, CLM runner |
| JavaScript | ✅ | Node + browser (WASM) + Full RAG Support + Pyodide |
| Rust | ✅ | High-performance adapter & WASM target |
| C | ✅ | Low-level runtime integration |
| WASM | ✅ | Edge and sandbox execution |
| Lean | ⚙️ | Formal verification pipeline (requires lean-toolchain) |
| R | ✅ | Statistical computing runtime |
| Julia | ✅ | High-performance scientific computing |
⚠️ Lean Configuration: A
lean-toolchainfile in the project root is critical. Without it,elanwill attempt to resolve/download toolchain metadata on every invocation, causing CLM execution to hang or become unbearably slow.
Project Structure (abridged)
MCard_TDD/
├── mcard/ # Python package (engines, models, PTR)
├── mcard-js/ # TypeScript implementation & npm package
├── chapters/ # CLM specifications (polyglot demos)
├── docs/ # Architecture, PRD, guides, reports
├── scripts/ # Automation & demo scripts
├── tests/ # >450 automated tests
└── requirements.txt / pyproject.toml
Documentation
- Product requirements: docs/prd.md
- Architecture overview: docs/architecture.md
- Schema principles: schema/README.md — Stable Seeding Meta-Language, Turing Tape Analogy, and the Unification Thesis.
- DOTS vocabulary: docs/WorkingNotes/Hub/Theory/Integration/DOTS Vocabulary as Efficient Representation for ABC Curriculum.md
- Monad–Polynomial philosophy: docs/architecture/Monadic_Duality.md
- Narrative roadmap & chapters: docs/Narrative_Roadmap.md
- Logging system: docs/LOGGING_GUIDE.md
- PTR & CLM reference: docs/CLM_Language_Specification.md, docs/PCard%20Architecture.md
- Reports & execution summaries: docs/reports/
- Publishing guide: docs/PUBLISHING_GUIDE.md
Platform Vision (December 2025): The Function Economy
Recent theoretical advancements have crystallized the MCard platform into a universal substrate for the Function Economy.
1. Vau Calculi Foundation: The MVP Card Database as Function Catalog
Using insights from John Shutt's Vau Calculi, PCard treats functions as first-class operatives cataloged in the MVP Card database.
- Identity: Unique SHA-256 hash
- Naming: Mutable handles in
handle_registry - Versioning: Immutable history in
handle_history
2. Symmetric Monoidal Category: Universal Tooling
All DSL runtimes are isomorphic to Petri Nets and Symmetric Monoidal Categories (SMC). The Symmetry Axiom ($A \otimes B \cong B \otimes A$) guarantees that one set of tools works for all applications:
- O(1) Toolchain: One debugger, one profiler, one verifier for all domains (Finance, Law, Code).
- Universal Interoperability: Any CLM can call any other CLM regardless of the underlying runtime (Python, JS, Rust, etc.).
3. PKC as Function Engineering Platform
MCard hashes act as Internet-native URLs for executable functions.
- Publish: Alice (Singapore) creates a function →
sha256:abc... - Resolve: Bob (New York) resolves
sha256:abc...→ Guaranteed identical function - Verify: Charlie (London) executes with VCard authorization
- Result: $\text{PKC} = \text{GitHub for Executable Functions}$
See Also:
- CLM_Language_Specification.md — Comprehensive theory
- Cubical Logic Model.md — Mathematical foundations
- PCard.md — Operative/Applicative duality
Recent Updates
Full changelog: CHANGELOG.md
Latest Version: 0.1.48 / 2.1.29 — January 17, 2026
Please refer to the changelog for details on recent updates including:
- Directory Alignment:
mcard-jsstructure now mirrors Python (src/model/hash,src/model/validators, root utils). - Store Refactoring:
MCardStorealigns strictly with SQL schema (v8). - Refactoring: Extracted server operations to
services.pyand reorganized CLMs intosystem/services/. - Configuration: Parameterized CLM ports using environment variables (
.env). - Fixes: CSV detection, CLM Loader imports, and WebSocket Server builtins.
Testing
Note: All commands below should be run from the project root (
MCard_TDD/).
Unit Tests
# Python
uv run pytest -q # Run all tests
uv run pytest -q -m "not slow" # Fast tests only
uv run pytest -m "not network" # Skip LLM/Ollama tests
# JavaScript
npm --prefix mcard-js test -- --run
CLM Verification
Both Python and JavaScript CLM runners support three modes: all, directory, and single file.
Python
# Run all CLMs
uv run python scripts/run_clms.py
# Run by directory
uv run python scripts/run_clms.py chapters/chapter_01_arithmetic
uv run python scripts/run_clms.py chapters/chapter_08_P2P
# Run single file
uv run python scripts/run_clms.py chapters/chapter_01_arithmetic/addition.yaml
# Run with custom context
uv run python scripts/run_clms.py chapters/chapter_08_P2P/generic_session.yaml \
--context '{"sessionId": "my-session"}'
JavaScript
# Run all CLMs
npm --prefix mcard-js run clm:all
# Run by directory/filter
npm --prefix mcard-js run clm:all -- chapter_01_arithmetic
npm --prefix mcard-js run clm:all -- chapters/chapter_08_P2P
# Run single file
npm --prefix mcard-js run demo:clm -- chapters/chapter_01_arithmetic/addition_js.yaml
Chapter Directories
| Directory | Description |
|---|---|
chapter_00_prologue |
Hello World, Lambda calculus, and Church encoding — 11 CLMs |
chapter_01_arithmetic |
Arithmetic operations (Python, JS, Lean) — 27 CLMs |
chapter_03_llm |
LLM integration (requires Ollama) |
chapter_04_load_dir |
Filesystem and collection loading |
chapter_05_reflection |
Meta-programming and recursive CLMs |
chapter_06_lambda |
Lambda calculus runtime |
chapter_07_network |
HTTP requests, MCard sync, network I/O — 5 CLMs |
chapter_08_P2P |
P2P networking and WebRTC — 16 CLMs (3 VCard) |
chapter_09_DSL |
Meta-circular language definition and combinators — 10 CLMs |
chapter_10_service |
Static server builtin and service management — 3 CLMs |
Contributing
- Fork the repository and create a feature branch.
- Run the tests (
uv run pytest,npm testinmcard-js). - Submit a pull request describing your change and tests.
We follow the BMAD (Red/Green/Refactor) loop – see BMAD_GUIDE.md.
Future Roadmap
Road to VCard (Design & Implementation)
Based on the MVP Cards Design Rationale, a VCard (Value Card) represents a boundary-enforced value exchange unit that often contains sensitive privacy data (identities, private keys, financial claims). Unlike standard MCards which are designed for public distribution and reproducibility, VCards require strict confidentiality.
Design Requirements & Rationale:
- Privacy & Encryption: VCards cannot be stored in the standard
mcard.db(which is often shared or public) without encryption. They must be stored in a "physically separate" container or be encrypted at rest. - Authentication Primitive: A VCard serves as a specialized "Certificate of Authority" — a precondition for executing sensitive PTR actions.
- Audit Certificates: Execution of a VCard-authorized action must produce a VerificationVCard (Certificate of Execution), which proves the action occurred under authorization. This certificate is also sensitive.
- Unified Schema: While the storage location differs, the data schema should remain identical to MCard (content addressable, hash-linked) to reuse the rigorous polynomial logic.
Proposed Architecture:
- Dual-Database Storage:
mcard.db(Public/Shared): Stores standard MCards, Logic (PCards), and Public Keys.vcard.db(Private/Local): Stores VCards, Encrypted Private Keys, and Verification Certificates.
- Execution Flow:
execute(pcard_hash, input, vcard_authorization_hash)- Gatekeeper: PTR checks if
vcard_authorization_hashexists in the Private Store (vcard.db). - Zero-Trust Verify: Runtime validates the VCard's cryptographic integrity and permissions (Security Polynomial).
- Execute: If valid, the PCard logic runs.
- Certify: A new
VerificationVCardis generated, signed, and stored invcard.db, linking the Input, Output, and Authority.
- Gatekeeper: PTR checks if
TODOs:
- Infrastructure: Implement
PrivateCollection(wrapper aroundvcard.db) in Python and JavaScript factories. - Encryption Middleware: Add a transparent encryption layer (e.g., AES-GCM) for the Private Collection to ensure Encryption-at-Rest.
- CLI Auth: Update
run_clms.pyto accept--auth <vcard_hash>and mount the private keystore. - Certificate Generation: Implement the
VerificationVCardschema and generation logic inCLMRunner.
Logical Model Certification & Functional Deployment
Use of the Cubical Logic Model (CLM) as a "Qualified Logical Model" is strictly governed by principles derived from Eelco Dolstra's The Purely Functional Software Deployment Model (the theoretical basis of Nix).
A CLM is not merely source code; it is a candidate for certification. It only becomes a Qualified Logical Model when it possesses a valid Certification, which is a cryptographic proof of successful execution by a specific version of the Polynomial Type Runtime (PTR).
The Functional Certification Equation: $$ Observation = PTR_{vX.Y.Z}(CLM_{Source}) $$ $$ Certification = Sign_{Authority}(Hash(CLM_{Source}) + Hash(PTR_{vX.Y.Z}) + Hash(Observation)) $$
Parallels to the Nix Model:
- Hermetic Inputs: Just as a Nix derivation hashes all inputs (compiler, libs, source), a CLM Certification depends on the exact PTR Runtime Version and CLM Content Hash. Changing the runtime version invalidates the certificate, requiring re-qualification (re-execution).
- Deterministic Derivation: The "build" step is the execution of the CLM's verification logic. If the PTR (the builder) is deterministic, the output (VerificationVCard) is reproducible.
- The "Store": The
mcard.dbacts as the Nix Store, holding immutable, content-addressed CLMs. Thevcard.dbacts as the binary cache, holding signed Certifications (outputs) that prove a CLM works for a given runtime configuration.
This ensures that a "Qualified CLM" is not just "code that looks right," but "code that has logically proven itself" within a specific, physically identifiable execution environment.
License
This project is licensed under the MIT License – see LICENSE.
For release notes, check CHANGELOG.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcard-0.1.48.tar.gz.
File metadata
- Download URL: mcard-0.1.48.tar.gz
- Upload date:
- Size: 262.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37f82af861b6b52b7e07b3bf398c9f1dc981821f7eea297a2956a979abdb8f03
|
|
| MD5 |
89b3f7109d28a084a0b3d191b8c36c2a
|
|
| BLAKE2b-256 |
a385b8d6ec6102290e790c38c98cf297371c5728291c271fb104b513d9d694d6
|
File details
Details for the file mcard-0.1.48-py3-none-any.whl.
File metadata
- Download URL: mcard-0.1.48-py3-none-any.whl
- Upload date:
- Size: 313.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab2b23ea7b9530f16862074968734133b224a8ca5b98e4eeca484e69d568e424
|
|
| MD5 |
dab5b75914a1a1f3a546d1379b403d9d
|
|
| BLAKE2b-256 |
65332e07a750b64f4098b466f6adbea084d1f6af8994fe9810619ed3a406ddbc
|