Unit E4: Stateless MCP Server (:8095), Chatbot OpenAPI 3.1.0 REST Adapter, .png+.json Cards & IPLD CIDv1

Cartridge E4 • Non-Sequentially Revertible via hs-eng-docs --disable mcp-chatbot-rest-and-ipld • v2.8.1

Prerequisite Track for Novices • Required Expertise: Level 4: Network Protocols, OpenAPI 3.1 & Content-Addressed Storage (15-20 hrs study)

If any concepts on this page are unfamiliar, occupy your study time with these free foundational resources first:

Core Concepts Required:
  • HTTP/1.1 request/response lifecycles, status codes (200, 404, 422, 500, 502), and reverse proxies
  • JSON-RPC 2.0, OpenAPI 3.1.0 schema generation, and Model Context Protocol (MCP)
  • Canonical JSON serialization, SHA-256 multihashes, and IPLD dag-json (0x0129) CIDv1
Curated Free Public Study Resources:
λ Polyglot Foil (E4): JSON-RPC 2.0 Tool Dispatch & 'envideea' = 137 (33rd Prime)
1. Formal Specification & Python:Dispatch(name, args) → ToolTable[name](args)
res = call_mcp_tool(target_tool, t_args)
λ Guile Scheme (Z-Combinator):
(list 'jsonrpc-2.0 'tool "hs_evaluate_aq_and_ingglish" (aq-base36 "envideea"))
=> [Select Lens to evaluate]
TS TypeScript (Strict AST):
aqBase36("envideea")
=> [Select Lens to evaluate]
Rs Rust (Option/Iterator AST):
mcp_dispatch_aq("envideea")
=> [Select Lens to evaluate]
Guided Micro-Challenge (4-Ring Zero-Escape Sandbox): Evaluate "envideea" => 137 across Guile, TypeScript, and Rust.

1. Unified Stateless MCP (/mcp) & Chatbot OpenAPI 3.1.0 REST Adapter (/api/v1/*)

mcp/server.py and mcp/rest.py expose all 15 tools in MCP_TOOLS_SCHEMA over stdio, Streamable HTTP POST/GET /mcp, and /api/v1/tools/{tool_name} on 127.0.0.1:8095. Top-level exception guards in _MCPHTTPHandler and record_api_telemetry() ensure sqlite3.OperationalError or read-only filesystem states never drop connections or trigger 502 Bad Gateway.

2. One-Shot .png + .json Ticker Stats Cards (quant/cards.py) & Canonical IPLD dag-json (0x0129)

hs_generate_ticker_stats_card compiles a 5-zone 900x1260 Group 3 Stealth Basalt PNG card and companion JSON payload in one shot (with draw_fitted_text() width clamping and ink-bbox midpoint centering). ipld/__init__.py serializes canonical UTF-8 dag-json and prefixes SHA-256 digests with [0x01, 0xA9, 0x02, 0x12, 0x20] to form Base32 CIDv1 ('baguqeera...').

← Prev: E3: Quant, Macro & Bayesian Next: E5: CI/CD, VPS & Regression →