run402-mcp
Version:
MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.
137 lines • 5.22 kB
TypeScript
/**
* `r.init()` — set up this machine for Run402, owned by the Node SDK: the
* config directory, the active profile's wallet on its payment rail, testnet
* funding, an optional promo voucher, the Lightning wallet, the tier read,
* the local project count, the vault git remote, the organization, and the
* one next action. Idempotent when re-run on the same rail; switching rails
* needs `switchRail`.
*
* `r.init({ apiBase })` instead configures the active profile to talk to a
* Run402 Core (or another) API base and returns without touching a wallet.
*
* Progress lines (Config / Wallet / Balance / Tier / Next …) go to `onLine`,
* never to stdout; the returned summary is the structured answer.
* `run402 init` is a shim over this.
*/
import { type NextAction } from "../errors.js";
import type { Client } from "../kernel.js";
import type { Run402 } from "../index.js";
import { type FundingRecovery } from "./funding-recovery.js";
export type InitRail = "x402" | "mpp" | "lightning";
export interface InitOptions {
/** Payment rail. Default `x402`. */
rail?: InitRail;
/** Confirm switching the persisted rail when a wallet already exists on another. */
switchRail?: boolean;
/** Redeem this promo code into the organization's allowance; never fails init. */
voucher?: string | null;
/** Also `git init` the working directory when it is not a repository yet. */
gitRemote?: boolean;
/** Set this principal's display name. */
name?: string;
/**
* Configure the active profile to use this API base (a self-hosted Run402
* Core Gateway, say) and return; no wallet is touched.
*/
apiBase?: string | null;
/** Directory the vault remote is scaffolded in. Default `process.cwd()`. */
cwd?: string;
/** Environment `RUN402_PROJECT_ID` is read from. Default `process.env`. */
env?: Record<string, string | undefined>;
/** Receives each human progress line. */
onLine?: (line: string) => void;
}
export interface InitWalletSummary {
local_label: string;
server_label: string | null;
address: string;
}
/** The summary `run402 init` prints. Fields appear exactly as the CLI has always emitted them. */
export interface InitSummary {
config_dir: string;
wallet: InitWalletSummary | null;
rail: InitRail | null;
network: string | null;
balances: {
on_chain_usd_micros: number;
on_chain_token: "USDC" | "pathUSD";
allowance_usd_micros: number | null;
held_usd_micros: number | null;
} | null;
voucher?: {
voucher_id: string;
amount_usd_micros: number;
already_redeemed: boolean;
next_actions: Array<Record<string, unknown>>;
} | null;
voucher_error?: {
code: string;
message: string;
};
tier: {
name: string;
expires: string | null;
} | null;
projects_saved: number;
active_project_id: string | null;
next_actions: NextAction[];
next_step: string | null;
lightning?: Record<string, unknown> | null;
vault?: Record<string, unknown> | null;
vault_skipped?: string;
vault_error?: {
code: string;
message: string;
};
orgs?: Array<{
org_id: string;
display_name: string | null;
role: string | null;
}> | null;
funding?: FundingRecovery | null;
display_name?: string | null;
display_name_error?: {
code: string;
message: string;
};
[key: string]: unknown;
}
/** The summary of `r.init({ apiBase })`. */
export interface InitTargetSummary {
config_dir: string;
api_base: string;
api_base_source: "profile";
target: {
kind: string;
health_status?: string;
health_error?: string;
};
payment_required: boolean;
next_actions: NextAction[];
next_step: string;
}
/** Builds a client for an API base other than the configured one (the target health probe). */
export type InitClientFactory = (opts: {
apiBase: string;
disablePaidFetch: true;
authMode: "none";
}) => Pick<Run402, "service">;
/** The slice of the Node client init drives. */
export type InitSdk = Pick<Run402, "wallets" | "vouchers" | "billing" | "agent" | "tier" | "repos"> & {
orgs: Pick<Run402["orgs"], "list" | "setDisplayName"> & {
owningOrgOf(projectId: string): Promise<string | null>;
};
};
/**
* Which project the vault scaffold acts on: `RUN402_PROJECT_ID`, then the
* active project — and, when neither, why nothing was done, stated.
*/
export declare function resolveScaffoldProject(env?: Record<string, string | undefined>, activeProjectId?: string | undefined | null): {
projectId: string | null;
skipped: string | null;
};
/** Configure an API target for the active profile. */
export declare function initApiTarget(clientFor: InitClientFactory, apiBase: string, onLine?: (line: string) => void): Promise<InitTargetSummary>;
/** Set up the active profile: wallet, rail, funding, voucher, Lightning, tier, projects, vault remote, orgs, next step. */
export declare function runInit(r: InitSdk, client: Client, opts?: InitOptions): Promise<InitSummary>;
//# sourceMappingURL=init.d.ts.map