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:
- Source (
mcp/): github.com/karany97/destiny/tree/main/mcp - Entrypoint (
destiny_mcp_server.py): raw.githubusercontent.com/…/destiny_mcp_server.py - Containerfile (
Dockerfile): raw.githubusercontent.com/…/Dockerfile - Machine Discovery (
/.well-known/mcp.json): nandai.org/.well-known/mcp.json
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/ssingle-stream (93.37 tok/s8-stream batch). - Destiny Pro Thinker (
Inkling-2-Mini, 16.0B MoE, 22% active, 1M ctx):54.54 tok/sspeculative decode. - Destiny Analyst (
Qwen3.8-27B, 27.0B dense, 262K native ctx):29.37 tok/sdecode.
- Destiny Swift (
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/c2pachunks and re-computeszlib.crc32(CRC-32 PASSvsCORRUPTED_C2PA_PROVENANCE_CRC_FAIL), pluseXIf/tEXt/iTXt. - JPEG (ISO/IEC 10918-1): scans markers for
APP11(0xFFEB) carryingc2pa/jumd/jumb/c2maboxes, alongsideAPP1Exif/XMP. - WebP (RIFF): walks
VP8X,EXIF,XMP, andc2pa/jumbchunks. - MP4 / MOV (ISOBMFF): traverses 32-bit and 64-bit box headers after
ftyplooking for ISO 19566-5 C2PA JUMBFuuid(d8fec3d6-1b0e-483c-9297-5828877ec481),jumb, andc2paboxes.
Binary provenance deep dive: nandai.org/guides/c2pa-jpeg-png-binary-provenance-internals
Live Discovery & Developer Endpoints
.well-known/mcp.json: nandai.org/.well-known/mcp.json- Official MCP Registry (
io.github.karany97/destiny@2.0.0): registry.modelcontextprotocol.io - TensorBlock Directory (
PR #7302merged): tensorblock.co - Browser Tools & Guides: nandai.org/tools/ · nandai.org/guides/
- Global Localized Hubs: nandai.org/global
- Open Model Manifest: models.nandai.org/v1/models-manifest.json
- Verification Suite (
test_mcp_stdio.py): raw.githubusercontent.com/…/test_mcp_stdio.py
Published by Nandai Jewels (BN 777578568BC0001 · Victoria, BC, Canada · Apple Team ID J5BH67967P).
- Reference: https://github.com/karany97/destiny/tree/main/mcp
- Reference: https://nandai.org/.well-known/mcp.json
- Reference: https://nandai.org/tools/
- Reference: https://nandai.org/guides/
- Reference: https://nandai.org/global
Write a comment