Server Functions

createServerFn creates functions that run on the server but can be called from both server and client components. On the server they execute directly. On the client, Catmint transforms the call into an RPC fetch() request.

Called from a Server Component

The server function was called directly during SSR — no HTTP request, just a function call:

time: 2026-03-01T21:47:07.700Z
pid: 4
node: v22.22.0

Called from a Client Component

The same server functions can be called from a client component. The Vite plugin rewrites the .fn.ts import into a fetch() stub pointing to /__catmint/fn/....

getServerTime() — via RPC

greetUser({ name }) — via RPC

How It Works

  • Define server functions in *.fn.ts files using createServerFn()
  • Server components call them directly — zero overhead
  • Client components import the same function — Vite rewrites it to an RPC fetch stub
  • Input validation is supported via Standard Schema (Zod, Valibot, etc.) or plain functions
  • Methods: GET, POST, PUT, DELETE (default: GET)