# @cubicecho/server-kit > The server code every cubicecho GraphQL backend shares: database boot, id columns and the checks that keep a schema to the standard. Agent-facing docs for @cubicecho/server-kit: one task or concept per page, then what each package.json "exports" entry exports. Generated from _agents/docs/ and the doc comments in src/ by @cubicecho/agent-docs; edit those, not this file. Requires Node >=22. Peer dependencies: `@better-auth/sso` >=1.7.28 <1.8.0 (optional), `@cubicecho/better-auth-oidc-pairing` ^1.1.0 (optional), `@cubicecho/graphql-mcp` ^3.1.0 (optional), `@electric-sql/pglite` ^0.5.0 (optional), `better-auth` >=1.7.28 <1.8.0 (optional), `drizzle-orm` 1.0.0-rc.5, `express` ^5.0.0, `graphql` ^16.0.0, `graphql-yoga` ^6.0.0, `postgres` ^3.4.0 || ^4.0.0 (optional), `vitest` ^5.0.0 (optional). ## Docs - [Database boot](_agents/docs/01-database.md): `@cubicecho/server-kit/db` makes a Postgres database ready to migrate: it waits for the server, creates the database when it is missing, and refuses a server the app cannot run on. It needs `postgres`, an optional peer: 4, or 3.4 in an app not yet moved. 3.4 ends the process when a connection drops while a transaction is running a query. - [Columns](_agents/docs/02-columns.md): `@cubicecho/server-kit/columns` has the Drizzle columns that keep a table to the conventions: a UUIDv7 id, moments with a time zone, and a table limited to one row. - [Test checks](_agents/docs/03-testing.md): `@cubicecho/server-kit/testing` registers Vitest tests that hold an app to the backend standard: its tables, and the Postgres it runs. - [Auth preset](_agents/docs/04-auth.md): `@cubicecho/server-kit/auth` has the better-auth options and sign-in plugins every server shares: sessions in Postgres, bearer tokens, emailed links, and OIDC with pairing. The app still calls `betterAuth`, so it adds its own plugins and hooks and keeps exact types. - [GraphQL](_agents/docs/05-graphql.md): `@cubicecho/server-kit/graphql` has what every Yoga 6 server shares: operation limits, coded errors, input validation and a logger that never prints a request's variables. - [HTTP](_agents/docs/06-http.md): `@cubicecho/server-kit/http` has what surrounds an Express app: a clean stop, the health check, serving the built app, and the two OIDC redirects. - [MCP](_agents/docs/07-mcp.md): `@cubicecho/server-kit/mcp` has what every MCP door over a drizzle-graphql schema shares: how the caller is read, and the options that keep the listing small. It needs `@cubicecho/graphql-mcp`, an optional peer. - [Common mistakes](_agents/docs/common-mistakes.md): What goes wrong when the kit is wired up slightly differently, and the fix for each. ## Exports: @cubicecho/server-kit/auth - `AUTH_DEFAULTS`: What `authPreset` and `signInPlugins` use when the app overrides nothing. - `AUTH_PATHS`: Where those pages are when the app overrides nothing. - `AuthPaths` (type): The app's pages a sign-in passes through, as paths under `appUrl`. - `AuthSettings` (type): Session and link lifetimes. - `RATE_LIMIT_DEFAULTS`: What `createRateLimiter` uses when the app overrides nothing. - `RateLimitSettings` (type): The sign-in throttle. - `SETUP_DEFAULTS`: What `createSetupGate`, `setupProblem` and `setupPlugin` use when the app overrides nothing. - `SetupSettings` (type): Setting up an instance that has no account. - `MagicLink` (type): What delivering one sign-in link is given. - `OidcOptions` (type): OIDC sign-in and pairing, without the two URLs, which follow from `appUrl`. - `SignInOptions` (type): What an app gives `signInPlugins`, besides OIDC. - `sendsMagicLinks`: Whether an instance emails sign-in links. - `signInPlugins`: How people sign in: bearer sessions, emailed links, and OIDC with pairing. - `AuthPresetOptions` (type): What an app gives the preset. - `AuthTables` (type): The tables better-auth keeps, by its own model names. - `authPreset`: The better-auth options every server shares. - `createRateLimiter`: Builds a limiter that holds its counts in this process. - `RateLimiter` (type): Sliding-window counter, in process. - `ThrottleContext` (type): What throttling needs of a request's context. - `throttle`: Counts one sign-in attempt, by the caller's address and by the account when the step names one. - `AuthInstance` (type): The part of an auth instance that setup and sign-in links use, whatever its plugins. - `asSetupRefusal`: Turns better-auth's error for a refusal into the GraphQL one. - `Claim` (type): What a claim is made with. - `claimInstance`: Makes an instance's first account and signs it in. - `createSetupGate`: Builds the door an instance with no account is set up through. - `isSetUp`: Whether an instance has been set up. - `SetupEnvironment` (type): What `setupProblem` looks at. - `SetupGate` (type): The door an instance with no account is set up through. - `SetupGateOptions` (type): Who may set up an instance that has no account. - `SetupRefusal`: Why setting an instance up was refused: `extensions.reason`, or the code of better-auth's error. - `SignedIn` (type): A signed-in session. - `setupNotice`: What to log at boot while an instance has no account. - `setupProblem`: What is wrong with the setup variables, for an app's preflight to refuse to boot on. - `setupRefused`: The GraphQL error for a refusal. - `createSignInLink`: Makes a link that signs its holder in as a user, once. - `SignInLink` (type): A link that signs one person in, once. - `signInLinkUrl`: The address a link is opened at. - `spendSignInLink`: Signs in with a link, and uses it up. ## Exports: @cubicecho/server-kit/columns - `id`: The primary key of an entity: a UUIDv7, made by the database. - `moment`: A moment, with its time zone. - `timestamps`: When a row was made, and when it last changed. - `singleton`: The column that keeps a table to one row. - `singletonRules`: The unique index and the check that make `singleton` work. ## Exports: @cubicecho/server-kit/db - `MIN_POSTGRES_MAJOR`: The first Postgres with `uuidv7()`, which ids default to. - `TESTED_POSTGRES_MAJOR`: The newest Postgres this package is tested on. - `ConnectionOptions` (type): What a postgres-js client is given besides its URL. - `connectionOptions`: The postgres-js options a server connects with. - `AdminClient` (type): The least boot needs of a connection to the maintenance database. - `OpenAdmin` (type): Opens a connection to the maintenance database. - `DATABASE_DEFAULTS`: What boot uses when the app overrides nothing. - `DatabaseSettings` (type): Settings for reaching Postgres at boot. - `DatabaseBootError`: Thrown when boot cannot use the database. - `errorCode`: Reads the driver or errno code of an error, or of whatever caused it. - `PrepareOptions` (type): How a database is made ready. - `prepareDatabase`: Makes the database ready to migrate: waits for it, creates it when it is missing, and checks its version. - `isPrivateHost`: Whether a host is this machine or on a private network. - `requiresSsl`: Whether to insist on TLS for a connection string. - `PostgresNeeds` (type): What the app needs of its Postgres. - `requirePostgres`: Refuses a Postgres the app cannot run on, before anything is migrated. - `Queryable` (type): Anything that can run a query: the Drizzle client on postgres-js, pg or PGlite. - `waitForDatabase`: Waits until Postgres answers a query. ## Exports: @cubicecho/server-kit/graphql - `OPERATION_LIMIT_DEFAULTS`: What `useOperationLimits` and an app's `buildSchema` use when the app overrides nothing. - `OperationLimitSettings` (type): Bounds on one GraphQL operation. - `badInput`: Arguments the caller can fix. - `conflict`: The request is fine, but the instance is in a state that refuses it. - `ErrorCode`: The `extensions.code` values clients branch on. - `errorMessage`: Reads the message of any caught value. - `forbidden`: This kind of caller may never do this. - `notFound`: Missing, or someone else's. - `rateLimited`: Builds the rate-limit refusal. - `requireAuth`: Reads the signed-in user's id. - `tooComplex`: Builds the refusal of an operation that asks for more than one may. - `unauthenticated`: Builds the signed-out refusal. - `graphqlLogger`: Yoga's logger with the `[graphql]` tag: warnings and errors, each with its request's id. - `REQUEST_ID`: Yoga's `requestId` option: each request gets an id of ours, never one the caller chose. - `assertWithinLimits`: Holds an operation to the limits. - `Operation` (type): One request's operation, as pricing needs it. - `useOperationLimits`: The Yoga plugin that holds every operation, subscriptions included, to the limits before it runs. - `Parser` (type): A zod schema, by the one method used here. - `parseOrThrow`: Parses with zod, turning a failure into BAD_USER_INPUT. ## Exports: @cubicecho/server-kit/http - `AuthRedirectOptions` (type): What the two legs of an OIDC sign-in need. - `mountAuthRedirects`: Mounts the two legs of an OIDC sign-in, the only better-auth routes a browser has to be redirected through. - `oidcRedirectUri`: Names the redirect URI a provider has to have registered. - `oidcSignInUrl`: Names where a login button sends the browser. - `HTTP_DEFAULTS`: What the HTTP helpers use when the app overrides nothing. - `HttpSettings` (type): Settings for the HTTP doors and the process behind them. - `toHeaders`: Copies Node's headers into fetch `Headers`, which better-auth reads the caller from. - `checkHealth`: Round-trips to Postgres. - `Health` (type): What `/healthz` answers. - `drain`: Stops accepting connections, and waits for every request to finish. - `ShutdownSteps` (type): What runs around the drain. - `stopOnSignals`: On SIGTERM or SIGINT: stops accepting, lets in-flight requests finish, closes, exits. - `createStaticHandler`: Serves a built single-page app, whose `index.html` answers every path that is not a file. - `StaticHandler` (type): A request handler, for Express or plain `node:http`. - `HttpStatus`: The HTTP statuses a server sends, and its tests expect. ## Exports: @cubicecho/server-kit/mcp - `MCP_DEFAULTS`: What the MCP helpers and `checkMcpBudget` use when the app overrides nothing. - `McpSettings` (type): Bounds on the MCP door. - `contextFromRequest`: Reads an MCP request's caller the way /graphql reads its own, so a credential means the same on both doors. - `SharedToolOptions` (type): The part of graphql-mcp's options that is the same for every schema drizzle-graphql generates. - `ToolOptions` (type): What an app says about its tools. - `toolOptions`: Builds the options that keep a generated schema's tools small enough to list. ## Exports: @cubicecho/server-kit/testing - `ListedTool` (type): A tool as `tools/list` answers it. - `mcpProblems`: Measures a tool listing against the size budgets. - `PostgresFiles` (type): Where a repo says which Postgres it runs. - `PostgresFindings` (type): What a comparison found. - `postgresProblems`: Compares the Postgres majors a repo names with each other and with the one its tests run on. - `SchemaExceptions` (type): Tables the id rule does not apply to. - `schemaProblems`: Finds what breaks the table conventions. - `checkSchemaConventions`: Registers the tests that hold a schema to the table conventions: ids, join tables, time zones and foreign-key indexes. - `checkPostgresVersion`: Registers the test that a repo's compose files, CI and tests agree on a Postgres major. - `checkMcpBudget`: Registers the test that an MCP listing fits the size budgets.