---
name: "trpc-server-type-safe-procedures"
description: "Build 100% end-to-end type-safe APIs without schemas, code generation, or runtime bloat."
metadata:
  author: "tRPC"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "create trpc router"
  - "protectedprocedure trpc middleware"
  - "input validation trpc zod"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# tRPC Server Procedures, Routers & Middleware Context

Architects tRPC v10/v11 server routers: initTRPC.context<Context>().create(), publicProcedure vs protectedProcedure, Zod input validation (.input(schema)), output schema inference, and error formatting.

## When to Invoke
Invoke this skill whenever you need to:
- create trpc router
- protectedprocedure trpc middleware
- input validation trpc zod

## Execution SOP & Rules
1. Initialize: const t = initTRPC.context<Context>().create().
2. Create protected procedure middleware: t.middleware(async ({ ctx, next }) => { if (!ctx.user) throw new TRPCError(...); return next({ ctx }); }).
3. Define router: export const appRouter = t.router({ getPost: publicProcedure.input(z.string()).query(...) }).
4. Export router type: export type AppRouter = typeof appRouter for frontend client consumption.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
