api-mcp

v0.1.11
@yichus/api-mcp Checked 12 hours ago Published 20 days ago

MCP server that runs the Yichus API engine (Yichus/Mcp Bosatsu config) over stdio

MCP server that guides an agent to write a Bosatsu API the Yichus engine can prove safe, then deploy as JavaScript. This package is a stdio transport built on the official MCP SDK (@modelcontextprotocol/sdk). The MCP itself is a Yichus engine with Bosatsu configuration: 1. A non-expert asks a cheap LLM for an API. The agent calls api_guide, then api_scaffold, edits the Bosatsu, and api_verify after every change. It cannot honestly say the API is safe unless the verdict is proven. 2. The agent edits generated code. Rails-like templates are a starting point.

Summary extracted from the README.

@yichus/api-mcp

MCP server that guides an agent to write a Bosatsu API the Yichus engine can prove safe, then deploy as JavaScript.

This package is a stdio transport built on the official MCP SDK (@modelcontextprotocol/sdk). The MCP itself is a Yichus engine with Bosatsu configuration:

  • Yichus/Mcp declares the tool catalog and the agent guide.
  • Yichus/Access is the canonical authoring layer for Principal, Policy, AccessRule, and AccessSpec.
  • Yichus/Data and Yichus/Service stay Yichus-owned (effect meaning and analysis-visible route markers).
  • ApiMcp / ApiSafety / ApiScaffold are deterministic Scala. There is no model-generated advice in the loop.

User stories

  1. A non-expert asks a cheap LLM for an API. The agent calls api_guide, then api_scaffold, edits the Bosatsu, and api_verify after every change. It cannot honestly say the API is safe unless the verdict is proven.
  2. The agent edits generated code. Rails-like templates are a starting point. After a leaky db_read(..., "other-user"), verify reports access:notes violated and leaves compiling / coverage proven. Safety is re-proven from the IR, not assumed from the template.
  3. The user deploys. api_deploy refuses unless every property is proven under the declared topology, then emits a Node engine that injects Principal and interprets Yichus/Data IO (pure / flat_map). HTTP listening is a refuse-by-default trichotomy: YICHUS_AUTH=jwt verifies Authorization: Bearer against a JWKS; YICHUS_AUTH=clerk-api-key checks each Authorization: Bearer API key with Clerk (CLERK_SECRET_KEY) and acts as the key's user or organization, for scripts and servers (a route declared publishable_route also takes the account's publishable key, made with POST /publishable_keys/create, for pages its own users load, and limited(route, requests, seconds) caps how often each account may call a route, answering 429 past it); YICHUS_AUTH=proxy-header plus YICHUS_TRUST_PROXY_AUTH=1 is the X-User-Id path; YICHUS_AUTH=public serves an API whose every route is a public_route, and refuses to start when any route needs a caller; YICHUS_AUTH=dev plus YICHUS_DEV_AUTH=1 is a demo user-switcher. Unset or unknown modes refuse to listen. The listening engine also serves its routes as MCP tools at /mcp (Streamable HTTP, stateless): the endpoint needs the caller's credential in every mode but public (even for a public_route tool), and each call runs as the route's own POST with that credential, so an agent can call the deployed API directly. Under clerk-api-key, setting YICHUS_MCP_AUTHORIZATION_SERVER (the Clerk Frontend API URL) and YICHUS_MCP_OAUTH_SCOPE (a custom Clerk scope for this service) lets an MCP client sign in with Clerk OAuth instead of holding a key; only a token granted that scope acts as the user. yichusApiEngine.handle stays available in-process. Handler code never constructs Principal. Do not wrap db_* in thunks; they already return IO. api_frontend generates screens over the same proven routes (in-process or HTTP; Dev / Clerk / Auth0 adapters).
  4. Topology is a declared input. Owner-scoped keys are the caller’s user_id. Read-modify-write handlers are violated under the default (multi-instance) topology; pass instances: 1 for a genuinely single-instance deploy to accept them as warnings, or run them in a transaction (or a single writer) when more than one engine instance is live. lost-edits (a save that drops an edit saved since its caller read the row) is the same under every topology: fix it with a version the save compares and raises, as each of its lines says.

Install and connect

The package includes the Scala.js compiler, so Node 20+ is enough. It needs no Java, Nix, or browser. Configure your MCP client to start it:

{
  "mcpServers": {
    "yichus-api": {
      "command": "npx",
      "args": ["-y", "-p", "@yichus/api-mcp@0.1.11", "yichus-api-mcp"]
    }
  }
}

The package has two commands (yichus-api-mcp and yichus-lean-wasm-install), so npx must be told which one to run. Tool requests compile and analyze the supplied sources locally. The optional api_tlc_check tool checks a protocol-case-1.0 case with pinned TLC 1.7.4. It needs Java 17, the JVM Yichus CLI as a host, and the pinned tla2tools.jar (sha256 936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88; nixpkgs tlaplus 1.7.4 ships this exact file). Start this server with both --tlc-host /absolute/path/to/yichus.jar and --tlc-jar /absolute/path/to/tla2tools.jar (these flags arrive in the first release after 0.1.1). Without them the tool answers errorKind: host-not-configured. The host runs yichus tlc --request, and a counterexample is reported only after the native scheduler replays it to the same violation.

The optional api_lean_check tool has two local backends. The native backend needs Java 17, a separate trusted JVM Yichus CLI, and the pinned Lean installation. Start this server with both --proof-host /absolute/path/to/yichus.jar and --lean-toolchain /private/read-only/lean. For a Node-only Wasm backend, install the pinned public slim runtime once, then pass its absolute root:

npx -p @yichus/api-mcp yichus-lean-wasm-install --output /absolute/private/lean-wasm
npx -p @yichus/api-mcp yichus-api-mcp --lean-wasm-root /absolute/private/lean-wasm

The installer downloads and verifies a 290 MB release archive, then installs the 67 MB Wasm binary and its 81 MB Lean library. It refuses to replace an existing runtime. Node 20+ runs this WebAssembly build; Java is unnecessary on that route. Select one backend per server. Without one, the tool reports unsupported-host guidance. The isolated browser Lean page provides the Wasm route through WebMCP; the general browser workbench reports unsupported-host guidance. Point JAVA_HOME at an absolute Java 17 installation when --proof-host is a JAR; the host does not resolve java through PATH. Keep the toolchain private and read-only while a proof runs. Its hashes are checked before and after execution, but a concurrent writer can defeat that check. The Wasm receipt records Lean kernel elaboration and an axiom audit, and says independentKernelReplay: false: it does not claim the separate native leanchecker replay. It pins the Wasm, glue, and library hashes, and still depends on trusting the local runtime installation during the check. Current Lean translation covers direct Obligation[Bool] laws and the documented structural Obligation[List[Bool]] law and witness. The list translator permits only a self-call on the bound tail of a Nil/Cons match; other recursive shapes are inconclusive. On the native host, Int and declared products of Int fields also have an assisted proof path: export literal lean_proof and lean_witness scripts and install the optional pinned Mathlib library beside the native toolchain (its installer is not distributed yet). The generator translates the actual selected predicates and helpers; Lean checks termination and both the universal law and existential witness. Scripts may cite existing theorems such as ZMod.pow_card_sub_one_eq_one. See the worked modular inverse. The CLI's --emit-lean Proof.lean saves the generated module before verification so authors can inspect definitions and goals; source output alone is not evidence. Mathlib is a separate, large native library; the Node and browser Wasm routes do not load it. The default response is a compact view with every obligation's status, exact source identity, and a fullReceiptSha256 digest. Call api_lean_check again with only receipt_sha256 to fetch the exact full receipt from this live server; the bounded cache can evict it, in which case rerun the source check. Pass view: "full" with sources to receive the complete receipt immediately. The digest identifies this server's exact JSON output bytes, including its final newline; a separate CLI --result file has its own byte digest. Use the digest with the server that produced it. The full receipt carries diagnostic reasons omitted from the compact view. The receipt is bound to the supplied source bytes and is a local-run result, not an importable proof certificate. The stdio transport runs the engine in a child process with a 120-second request deadline. A timeout or worker crash returns a JSON-RPC error; a cancelled request (notifications/cancelled) stops the engine and gets no response, as MCP requires. Either way the next request starts a fresh engine. Input lines and worker responses are capped at 16 MiB; an oversized or malformed line is reported on stderr and dropped. A transport error is never evidence that a property holds.

Call api_guide first, then discover the current catalog with tools/list. The list starts with the core tools: api_tools, api_guide, api_scaffold, api_compile, api_verify, api_report, api_add_artifact, api_why and api_law_check. The rest are in specialist families (ship, access, concurrency, proofs, orientation, changes). api_tools with no arguments names each family and its tools; api_tools with family returns that family's tools with their schemas, and the server adds them to tools/list and sends notifications/tools/list_changed. Any tool runs by name whether or not it is listed. Start the server with --all-tools, or pass {allTools:true} to createApiMcpServer, to list every tool from the start. This is the browser API workbench's core catalog; live browser editors, visible feedback, and yichus_app_* sessions are provided separately by @yichus/mcp, the browser relay.

Experiment with diagram presentation guidance

The default server advertises tools, and its only instructions say how to open a tool family. To review locally available diagram experiments, explicitly start it with yichus-api-mcp --experimental-diagram-views. Programmatic hosts can pass {experimentalDiagramViews:true} as createApiMcpServer's fourth argument. This opt-in does not install or deploy the experiment renderers.

The opted-in server advertises yichus_choose_diagram_view through prompts/list. Retrieve it with prompts/get, passing family, the person's concrete question, and optional viewport (wide, narrow, or unknown). For example:

{"name":"yichus_choose_diagram_view","arguments":{"family":"system-context","question":"Which database operation does each route perform?","viewport":"wide"}}

The prompt explains the strengths, costs and evidence requirements of each experimental view using generic question-based examples, including when the original map, delivery list or calculator is preferable. It covers system-context, composition, causal-trace, visible-values and abstraction-contracts. The agent chooses; runtime code does not classify the program by its name, size, or source text.

Consumers that support this experimental contract accept an optional presentation field in their existing snapshot-bound annotation:

{"view":"map","reason":"The compact route map directly answers this question.","authorship":"agent-authored"}

Its supported views come from one registry shared by the prompt and validators. The reason remains labelled agent-authored in the page and saved evidence. The existing compiler/checker snapshot and reference checks still run first; selection cannot add a relationship or guarantee. If neither view answers the question, the agent should name the missing evidence rather than invent it.

This is guidance for unpromoted browser experiments, not a new engine tool or an api_organize view format. It does not install the experiment renderers, publish them, or extend the browser relay's tool catalog. MCP clients expose prompts differently; some require a user-invoked command. This experiment does not assume the model can fetch a prompt autonomously. No engine tool takes a view argument yet. A view family stays behind this opt-in until its renderer ships and a rendering tool accepts the choice.

For terminal use and CI, yichus shares this packaged engine:

yichus tools
yichus verify notes-api.bosatsu --instances 1 --output verdict.json
yichus call api_abstraction_map --source notes-api.bosatsu --output map.json

verify fails unless verdict.proven is exactly true. Other catalog checks are available through call and explicit --expect assertions.

Tools (from Yichus/Mcp::catalog)

Tool Kind
api_guide Pre-written workflow and access rules
api_scaffold Generate a Yichus-first Bosatsu module
api_add_rule AccessRule("table", OwnerScoped) snippet
api_compile In-memory parse + typecheck (CompileKernel)
api_audit IO composition findings
api_permissions Declared vs inferred route permissions
api_access_check Per-user access proof (holds / violated / inconclusive)
api_integrity_check Complete typed causal consistency plus bounded races, stale reads and declared models; optional view: "compact" retains all decisions with a retrievable witness hash
api_dist_check DistEngine multi-instance schedules
api_escrow_check AdmissionSolver bounded-balance check
api_verify Composite api-safety-1.0 verdict
api_deploy JS engine, gated on proven; HTTP listen requires YICHUS_AUTH
api_report program-report-2.0 program map (CRUD, flow, dist, escrow, unrouted IO)
api_frontend Verified HTML app from Yichus/Frontend::FrontendSpec
api_add_artifact Paste-ready snippet for a missing report declaration