Zero-Dependency Python 3.10+ MCP Server for Apple Silicon Sizing & Local C2PA Provenance

How io.github.karany97/destiny@2.0.0 implements dual 2025-03-26 / 2024-11-05 stdio JSON-RPC 2.0 framing using only Python stdlib, M1-M4 Ultra Unified Memory + KV-cache math, and zero-upload C2PA JUMBF binary inspection — discoverable at https://nandai.org/.well-known/mcp.json
Zero-Dependency Python 3.10+ MCP Server for Apple Silicon Sizing & Local C2PA Provenance

Zero-Dependency Python 3.10+ MCP Server for Apple Silicon Sizing & Local C2PA Provenance

Most Model Context Protocol (MCP) servers bundle dozens of transitive dependencies just to speak JSON-RPC 2.0 over stdin/stdout. For local developer tooling — especially security, release-verification, and hardware-sizing helpers — every extra dependency is audit surface.

In Destiny 2.0.0 (io.github.karany97/destiny@2.0.0), we shipped a single-file, MIT-licensed MCP server in pure Python >=3.10 standard library (json, sys, urllib.request, hashlib, math, struct, zlib, re, subprocess, pathlib) — zero pip installs, published at:


1. Dual stdio JSON-RPC 2.0 Framing (2025-03-26 + 2024-11-05)

MCP clients disagree on wire framing over stdio. Newer 2025-03-26 hosts send newline-delimited JSON ({...}\n), while 2024-11-05 / LSP-derived hosts send Content-Length: N\r\n\r\n MIME headers.

destiny_mcp_server.py detects framing per message directly on sys.stdin.buffer:

line = raw_line.decode("utf-8", errors="replace").strip()
if line.lower().startswith("content-length:"):
    # Parse MIME headers until empty line, then stream.read(content_length)
    return json.loads(body.decode("utf-8")), True
return json.loads(line), False

_write_message echoes the exact use_content_length boolean back on sys.stdout.buffer, allowing one binary to interoperate with every MCP client cleanly. initialize negotiates protocolVersion across ("2025-03-26", "2024-11-05"), notifications (id is None) emit no response, and tools/call emits both content text blocks and structuredContent.


2. Exact Apple Silicon Unified Memory + KV-Cache Quantization Math (apple_silicon_vram_calc)

Apple Silicon uses Unified Memory Architecture (UMA), where macOS caps wired Metal GPU allocations at roughly 71.875% (11.5 GiB on 16 GB), 75% (18.0 GiB on 24 GB), and 79% on >=36 GB systems (0.45 GiB runtime reserve).

apple_silicon_vram_calc computes exact GGUF weight and KV-cache footprints across M1/M2/M3/M4 (Base/Pro/Max/Ultra, 16 GB–512 GB, 4K–256K+ context):

  • GGUF Quant Bit-Widths (QUANT_BPW): Q3_K_S (3.50 bpw), Q4_K_M (4.85 bpw), Q6_K (6.56 bpw), Q8_0 (8.50 bpw), FP16 (16.00 bpw).
  • KV-Cache Quant Scaling (KV_QUANT_FACTORS): FP16 (1.0x), Q8_0 (0.5x), Q4_0 (0.25x).
  • Memory Bandwidth Table (GB/s): from M1 Base (68.25 GB/s), M4 Base (120 GB/s), and M4 Pro (273 GB/s) up to M4 Max (546 GB/s) and M3/M4 Ultra (819 GB/s).
  • Verified M4 Pro (24 GB, 273 GB/s) Reference Presets (live weights at huggingface.co/nandai-org):
    • Destiny Swift (LFM2-8B-A1B, 8.3B MoE, 24% active, 128K ctx): 78.62 tok/s single-stream (93.37 tok/s 8-stream batch).
    • Destiny Pro Thinker (Inkling-2-Mini, 16.0B MoE, 22% active, 1M ctx): 54.54 tok/s speculative decode.
    • Destiny Analyst (Qwen3.8-27B, 27.0B dense, 262K native ctx): 29.37 tok/s decode.

Full math reference: nandai.org/guides/apple-silicon-unified-memory-kv-cache-math


3. Zero-Upload SHA-256 & C2PA JUMBF Binary Box Inspection (inspect_c2pa_or_sha256)

Instead of uploading media files to third-party servers, inspect_c2pa_or_sha256 streams files locally in 1 MiB blocks (bytes_uploaded: 0) for SHA-256 verification and inspects container metadata directly with Python struct + zlib:

  • PNG (ISO/IEC 15948): parses caBX / c2pa chunks and re-computes zlib.crc32 (CRC-32 PASS vs CORRUPTED_C2PA_PROVENANCE_CRC_FAIL), plus eXIf / tEXt / iTXt.
  • JPEG (ISO/IEC 10918-1): scans markers for APP11 (0xFFEB) carrying c2pa/jumd/jumb/c2ma boxes, alongside APP1 Exif/XMP.
  • WebP (RIFF): walks VP8X, EXIF, XMP , and c2pa/jumb chunks.
  • MP4 / MOV (ISOBMFF): traverses 32-bit and 64-bit box headers after ftyp looking for ISO 19566-5 C2PA JUMBF uuid (d8fec3d6-1b0e-483c-9297-5828877ec481), jumb, and c2pa boxes.

Binary provenance deep dive: nandai.org/guides/c2pa-jpeg-png-binary-provenance-internals


Live Discovery & Developer Endpoints

Published by Nandai Jewels (BN 777578568BC0001 · Victoria, BC, Canada · Apple Team ID J5BH67967P).


Write a comment