create-server-function

Creates TanStack Start server functions with separated database logic and createServerFn wrappers.

Updated May 23, 2026
One-click install
npx skills add https://github.com/kveperedo/website --skill create-server-function-kveperedo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: create-server-function
Source: https://github.com/kveperedo/website/tree/main/.agents/skills/create-server-function
Command: npx skills add https://github.com/kveperedo/website --skill create-server-function-kveperedo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Mixing raw database logic with client-callable server function wrappers in one file causes import errors, security leaks, and inconsistent patterns. This Skill enforces a two-file convention so server-side code in a TanStack Start project stays organized and safe. ## Core Features & Use Cases - Two-File Convention: Generates a server.ts file for raw Prisma/auth logic and a functions.ts file for createServerFn wrappers under the owning domain in src/app/. - Auth & Validation Patterns: Applies authMiddleware for protected functions and zod schemas via .validator() for typed input handling. - Method & Naming Rules: Enforces { method: "POST" } for mutations, GET defaults for reads, Fn suffixes on exports, and .toNumber() conversion for Prisma Decimal fields. - Use Case: When adding a new transaction creation endpoint to a finance dashboard, use this Skill to scaffold both the database function and its validated, auth-protected server function wrapper following project conventions. ## Quick Start Create a server function for adding a new transaction with description and amount fields, protected by auth middleware.

Frequently Asked Questions about create-server-function

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a server function in TanStack Start?▼

Use createServerFn from @tanstack/react-start to define a wrapper, then attach .handler() with your logic. Add .validator() with a zod schema for input and .middleware([authMiddleware]) for protected endpoints.

How do I validate input for TanStack Start server functions?▼

Attach a zod schema via .validator(schema) on the createServerFn chain. Inside the handler, destructure the validated input from { data }, giving you type-safe arguments without manual parsing.

Should database logic and createServerFn wrappers be in the same file?▼

No. Keep raw Prisma or auth logic in a server.ts file that the client never imports, and place createServerFn wrappers in a separate functions.ts file. This prevents server-only code from leaking into client bundles.

When should I use POST versus GET for server functions?▼

GET is the default and suits read or query operations, so no method option is needed. Always specify { method: "POST" } for mutations such as create, update, or delete operations.

Why do Prisma Decimal fields cause errors in server functions?▼

Prisma returns Decimal objects that are not safely serializable to the client. Convert them with .toNumber() in the server.ts layer before returning data from your functions.