MainSDK
Search⌘K
Docs

Install MainSDK

Install the mainsdk package, CLI and testing kit in a Node.js 22+ TypeScript project and wire it into Next.js, Hono, Express or a worker.

Building for 0.2

Status Status is where the work is: Planned (in a milestone, not started), Building (tickets in progress), Preview (usable, may change), then the stability it ships at.

Stability The promise an interface ships with.

  • Stable Follows semantic versioning; breaking changes need a new major, 12 months of overlap and a codemod.
  • Beta Usable in production; may change before it becomes stable.
  • Experimental May change or go away; needs an explicit opt-in in main.yaml.
Stability levels
Updated 2026-10-28

MainSDK is a library, a CLI and an MCP server that live in your repo. There is nothing to host and no sidecar to run: you import it like any other package.

Nothing is published yet: MainSDK is pre-release, and these steps are the planned design. What runs from the repository today, and how to run it, is in the README. The Next.js, Hono, Express, worker, Prisma and Drizzle adapters are planned for milestone 0.2.

Starting from an empty folder? Skip to the quickstart; it creates a Next.js app and runs init for you. Read on to add MainSDK to a project you already have, or to wire in a framework other than Next.js.

Requirements

You needVersion
Node.js22 or later, with ESM ("type": "module")
LanguageTypeScript (phases 1 to 4 are TypeScript only)
Operating systemLinux x64 or arm64 (glibc and musl), macOS (arm64, x64) or Windows x64
AccountNone. Everything runs locally until you choose to run mainsdk login

MainSDK is pure TypeScript with zero runtime dependencies: no native binary, no WebAssembly core and no install scripts.

Install

Run init in the root of your project. It installs the packages, writes a minimal main.yaml, adds .mainsdk/ to .gitignore and connects your coding agent. It needs no account and no network.

npx mainsdk init

To add the packages by hand instead:

npm install mainsdk
npm install --save-dev @mainsdk/cli @mainsdk/testing
PackageWhat it holds
mainsdkThe SDK: every interface, one subpath per adapter (mainsdk/next, mainsdk/hono …)
@mainsdk/cliThe mainsdk command: init, sync, check, info, logs, dev and more
@mainsdk/testingIn-memory fakes, assertions, time control and chaos drills for your tests

The packages are ES modules only (ADR-0045) and ship built files with source maps. import them, or require() them on Node.js 22.12 or later.

Wire in your framework

One import puts every request and job behind MainSDK: each gets a trace, its user and market context, the lifecycle hooks, and errors returned as problem details.

// proxy.ts (middleware.ts on Next.js 15)
import { mainsdk } from "mainsdk/next";
export const proxy = mainsdk.proxy();

// app/api/orders/route.ts
import { withMainSDK } from "mainsdk/next";
import { auth, db } from "mainsdk";

export const GET = withMainSDK(async (req) => {
  const session = await auth.require(req);
  return Response.json(await db.orders.for(session.user).list({ limit: 20 }));
});

Next.js support covers the App Router (route handlers, server actions and proxy.ts or middleware.ts). The Pages Router is not supported.

Prisma and Drizzle

Wrap your existing client so every query goes through the policy engine and the audit log. mainsdk check reports any query made with the unwrapped client (MAIN-DATA-0001).

lib/db.ts
import { PrismaClient } from "@prisma/client";
import { withPrisma } from "mainsdk/prisma";

export const prisma = withPrisma(new PrismaClient());
lib/db.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { withDrizzle } from "mainsdk/drizzle";
import { pool } from "./pool";

export const db = withDrizzle(drizzle(pool));

Check the install

bash
npx mainsdk info

info reads main.yaml and prints the app, its interfaces and drivers, network destinations, data labels and regions, and open exceptions. Add --json for a versioned document. If it prints your app, you're set.

What runs when

Nothing is published yet. Milestone 0.2: init, check, sync, info, logs, dev and local config, secrets, policy and log. Milestone 0.3: init --preset, add, doctor, check --json --agent and local auth, db and ai. Milestone 0.4: the testing kit. Milestone 0.5: public beta, the migration skill and adopt.

Next

Was this page helpful?

↑↓ moveEnter openEsc close

Not decided yet