Expertise·API Development

tRPC Server Setup

Initialize tRPC with initTRPC.create(), define routers with t.router(), create procedures with .query()/.mutation()/.subscription()…

You say
Buy it · $89 Read it before you buy $89 Written by trpc · unverified publisher
Context cost
2.3k tokensestimated from the bundle, loaded when it triggers
Bundle
1 file · 9.2 kBtext throughout, nothing executable
Licence
MITpaid listing
Last change
no release on file
Servers it uses
Noneruns standalone

What it does

Initialize tRPC with initTRPC.create(), define routers with t.router(), create procedures with .query()/.mutation()/.subscription(), configure context with createContext(), export AppRouter type, merge routers with t.mergeRouters(), lazy-load routers with lazy().

Installed, it changes the agent in these ways.

What this skill changes about the agent is not written down here yet. The listing was collected from its source, and the description is in its own SKILL.md.

Expertise

Domain judgement the base model does not have.

trpctypescriptbackendapi
Filed under

API Development

The skill itself

This is the whole product. A skill is instructions the model reads, so there is nothing behind the listing you cannot see first — the front matter loads with every session, and the body below it loads when the skill triggers.

SKILL.md9.2 kB · 379 lines
--- name: server-setup description: > Initialize tRPC with initTRPC.create(), define routers with t.router(), create procedures with .query()/.mutation()/.subscription(), configure context with createContext(), export AppRouter type, merge routers with t.mergeRouters(), lazy-load routers with lazy(). type: core library: trpc library_version: '11.16.0' requires: [] sources: - 'trpc/trpc:www/docs/server/overview.md' - 'trpc/trpc:www/docs/server/routers.md' - 'trpc/trpc:www/docs/server/procedures.md' - 'trpc/trpc:www/docs/server/context.md' - 'trpc/trpc:www/docs/server/merging-routers.md' - 'trpc/trpc:www/docs/main/quickstart.mdx' - 'trpc/trpc:packages/server/src/unstable-core-do-not-import/initTRPC.ts' - 'trpc/trpc:packages/server/src/unstable-core-do-not-import/router.ts' ---
23# tRPC -- Server Setup
24
25## Setup
26
27```ts
28// server/trpc.ts
29import { initTRPC } from '@trpc/server';
30
31const t = initTRPC.create();
32
33export const router = t.router;
34export const publicProcedure = t.procedure;
35```
36
37```ts
38// server/appRouter.ts
39import { z } from 'zod';
40import { publicProcedure, router } from './trpc';
41
42type User = { id: string; name: string };
43
44export const appRouter = router({
45 userList: publicProcedure.query(async (): Promise<User[]> => {
46 return [{ id: '1', name: 'Katt' }];
47 }),
48 userById: publicProcedure
49 .input(z.string())
50 .query(async ({ input }): Promise<User> => {
51 return { id: input, name: 'Katt' };
52 }),
53 userCreate: publicProcedure
54 .input(z.object({ name: z.string() }))
55 .mutation(async ({ input }): Promise<User> => {
56 return { id: '1', ...input };
57 }),
58});
59
60export type AppRouter = typeof appRouter;
61```
62
63```ts
64// server/index.ts
65import { createHTTPServer } from '@trpc/server/adapters/standalone';
66import { appRouter } from './appRouter';
67
68const server = createHTTPServer({ router: appRouter });
69server.listen(3000);
70```
71
72## Core Patterns
73
74### Context with typed session
75
76```ts
77// server/context.ts
78import type { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
79
80export async function createContext(opts: CreateHTTPContextOptions) {
81 const token = opts.req.headers['authorization'];
82 return { token };
83}
84
85export type Context = Awaited<ReturnType<typeof createContext>>;
86```
87
88```ts
89// server/trpc.ts
90import { initTRPC } from '@trpc/server';
91import type { Context } from './context';
92
93const t = initTRPC.context<Context>().create();
94
95export const router = t.router;
96export const publicProcedure = t.procedure;
97```
98
99```ts
100// server/index.ts
101import { createHTTPServer } from '@trpc/server/adapters/standalone';
102import { appRouter } from './appRouter';
103import { createContext } from './context';
104
105const server = createHTTPServer({
106 router: appRouter,
107 createContext,
108});
109server.listen(3000);
110```
111
112### Inner/outer context split for testability
113
114```ts
115// server/context.ts
116import type { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
117import { db } from './db';
118
119interface CreateInnerContextOptions {
120 session: { user: { email: string } } | null;
121}
122
123export async function createContextInner(opts?: CreateInnerContextOptions) {
124 return {
125 db,
126 session: opts?.session ?? null,
127 };
128}
129
130export async function createContext(opts: CreateHTTPContextOptions) {
131 const session = getSessionFromCookie(opts.req);
132 const contextInner = await createContextInner({ session });
133 return {
134 ...contextInner,
135 req: opts.req,
136 res: opts.res,
137 };
138}
139
140export type Context = Awaited<ReturnType<typeof createContextInner>>;
141```
142
143Infer Context from createContextInner so server-side callers and tests never need HTTP request objects.
144
145### Merging child routers
146
147```ts
148// server/routers/user.ts
149import { publicProcedure, router } from '../trpc';
150
151export const userRouter = router({
152 list: publicProcedure.query(() => []),
153});
154```
155
156```ts
157// server/routers/post.ts
158import { z } from 'zod';
159import { publicProcedure, router } from '../trpc';
160
161export const postRouter = router({
162 create: publicProcedure
163 .input(z.object({ title: z.string() }))
164 .mutation(({ input }) => ({ id: '1', ...input })),
165 list: publicProcedure.query(() => []),
166});
167```
168
169```ts
170// server/routers/_app.ts
171import { router } from '../trpc';
172import { postRouter } from './post';
173import { userRouter } from './user';
174
175export const appRouter = router({
176 user: userRouter,
177 post: postRouter,
178});
179
180export type AppRouter = typeof appRouter;
181```
182
183### Lazy-loaded routers for serverless cold starts
184
185```ts
186// server/routers/_app.ts
187import { lazy } from '@trpc/server';
188import { router } from '../trpc';
189
190export const appRouter = router({
191 // Short-hand when the module has exactly one router exported
192 greeting: lazy(() => import('./greeting.js')),
193 // Use .then() to pick a named export when the module exports multiple routers
194 user: lazy(() => import('./user.js').then((m) => m.userRouter)),
195});
196
197export type AppRouter = typeof appRouter;
198```
199
200## Common Mistakes
201
202### [CRITICAL] Calling initTRPC.create() more than once
203
204Wrong:
205
206```ts
207// file: userRouter.ts
208import { initTRPC } from '@trpc/server';
209const t = initTRPC.create();
210export const userRouter = t.router({});
211
212// file: postRouter.ts
213import { initTRPC } from '@trpc/server';
214const t2 = initTRPC.create();
215export const postRouter = t2.router({});
216```
217
218Correct:
219
220```ts
221// file: trpc.ts (single file, created once)
222import { initTRPC } from '@trpc/server';
223import type { Context } from './context';
224
225const t = initTRPC.context<Context>().create();
226
227export const router = t.router;
228export const publicProcedure = t.procedure;
229```
230
231Multiple tRPC instances cause type mismatches and runtime errors when routers from different instances are merged.
232
233Source: www/docs/server/routers.md
234
235### [HIGH] Using reserved words as procedure names
236
237Wrong:
238
239```ts
240import { publicProcedure, router } from './trpc';
241
242const appRouter = router({
243 then: publicProcedure.query(() => 'hello'),
244});
245```
246
247Correct:
248
249```ts
250import { publicProcedure, router } from './trpc';
251
252const appRouter = router({
253 next: publicProcedure.query(() => 'hello'),
254});
255```
256
257Router creation throws if procedure names are "then", "call", or "apply" because these conflict with JavaScript Proxy internals.
258
259Source: packages/server/src/unstable-core-do-not-import/router.ts
260
261### [CRITICAL] Importing AppRouter as a value import
262
263Wrong:
264
265```ts
266// client.ts
267import { AppRouter } from '../server/router';
268```
269
270Correct:
271
272```ts
273// client.ts
274import type { AppRouter } from '../server/router';
275```
276
277A non-type import pulls the entire server bundle into the client; use import type so it is stripped at build time.
278
279Source: www/docs/server/routers.md
280
281### [MEDIUM] Creating context without inner/outer split
282
283Wrong:
284
285```ts
286import type { CreateExpressContextOptions } from '@trpc/server/adapters/express';
287
288export function createContext({ req }: CreateExpressContextOptions) {
289 return { db: prisma, user: getUserFromReq(req) };
290}
291```
292
293Correct:
294
295```ts
296import type { CreateExpressContextOptions } from '@trpc/server/adapters/express';
297
298export function createContextInner(opts: { user?: User }) {
299 return { db: prisma, user: opts.user ?? null };
300}
301
302export function createContext({ req }: CreateExpressContextOptions) {
303 return createContextInner({ user: getUserFromReq(req) });
304}
305```
306
307Without an inner context factory, server-side callers and tests must construct HTTP request objects to get context.
308
309Source: www/docs/server/context.md
310
311### [HIGH] Merging routers with different transformers
312
313Wrong:
314
315```ts
316import { initTRPC } from '@trpc/server';
317import superjson from 'superjson';
318
319const t1 = initTRPC.create({ transformer: superjson });
320const t2 = initTRPC.create();
321
322const router1 = t1.router({ a: t1.procedure.query(() => 'a') });
323const router2 = t2.router({ b: t2.procedure.query(() => 'b') });
324
325t1.mergeRouters(router1, router2);
326```
327
328Correct:
329
330```ts
331import { initTRPC } from '@trpc/server';
332import superjson from 'superjson';
333
334const t = initTRPC.create({ transformer: superjson });
335
336const router1 = t.router({ a: t.procedure.query(() => 'a') });
337const router2 = t.router({ b: t.procedure.query(() => 'b') });
338
339t.mergeRouters(router1, router2);
340```
341
342t.mergeRouters() throws at runtime if the routers were created with different transformer or errorFormatter configurations.
343
344Source: packages/server/src/unstable-core-do-not-import/router.ts
345
346### [CRITICAL] Importing appRouter value into client code
347
348Wrong:
349
350```ts
351// client.ts
352import { appRouter } from '../server/router';
353
354type AppRouter = typeof appRouter;
355```
356
357Correct:
358
359```ts
360// client.ts
361import type { AppRouter } from '../server/router';
362
363// server/router.ts
364export type AppRouter = typeof appRouter;
365```
366
367Importing the appRouter value bundles the entire server into the client, even if you only use typeof.
368
369Source: www/docs/server/routers.md
370
371## See Also
372
373- middlewares -- add auth, logging, context extension to procedures
374- validators -- add input/output validation with Zod
375- error-handling -- throw and format typed errors
376- server-side-calls -- call procedures from server code
377- adapter-standalone -- mount on Node.js HTTP server
378- adapter-fetch -- mount on edge runtimes
379
In the file
SKILL.md1,116 words
Files1
LicenceMIT
Why you can read it

Nothing in a skill executes. The client loads the text and the model follows it, so a skill can be audited the way a runbook is — by reading it.

What it costs in context

Skills are not billed by the call. They are paid for in context: every token the instructions occupy is a token your code, your diff and your conversation cannot use. Here is what this one takes and when it takes it.

≈200
always loaded
The name and description, so the model knows the skill exists and when to reach for it.
2,100
on trigger
The instruction body, read only when the skill fires.
1.1%
of a 200k window
Ten skills this size would take about 12% of the window before you open a file.
050k100k150k200k context window

2.3k tokens, estimated from the bundle at four bytes to the token, held for the rest of the session once it triggers. Middling. Fine to keep on in a project where you use it weekly, worth unloading in one where you never do.

Servers bill, skills cost

A server charges by the month. A skill charges once per session, in context, and then keeps charging it for as long as the session lives.

Before and after

The same question, put to the same model twice: once as it comes, and once with these instructions loaded.

No worked example has been published for this skill yet.

Adoption
Installsnone yet
Ratingno reviews yet

The procedure it runs

The procedure has not been published here. It is in the skill’s own SKILL.md, which its author has not sent to the marketplace yet.

Prose, not code

These steps are written for a model to follow, not executed by a runtime. It can still be told to skip one, and it will say so when it does.

Servers it uses

None. This skill calls no MCP servers at all.

Everything it needs is in the instructions, so it works in a project with nothing connected — the model reads the file and changes how it works with what it can already reach.

It writes no files and reaches no network. All it changes is how the model reasons and writes.

What it asks for
Writes filesno
Network accessno

Read from the allowed-tools line of this skill’s own SKILL.md. A skill grants no permissions of its own — it can only ask for tools your client already has.

What it will not do

Every skill is narrow, and the useful ones say where they stop. These are the jobs this one is the wrong tool for.

What this skill is not for has not been published here. Nothing is implied by that: it is a section the author has not filled in.

What is in the bundle

1 file, 9.2 kB on disk. A bundle is text throughout: the instructions the model reads, plus the templates it fills in.

  • SKILL.md9.2 kB
What is not in it

No dependencies and nothing executable: a skill is text the agent reads, so the bundle is 1 file you can review in full before installing. The MIT licence covers the templates and examples as well as the instructions.

Install

Installing copies the bundle into your project. Nothing runs at install time — the files sit on disk until the model reads them.

$89 once
tRPC Server Setup · MIT · trpc
one-time
Price$89 once
LicenceMIT — the author’s, unchanged by this purchase
Paid throughStripe, once, on the card you add at the checkout
Keeps workingfor good — the files are yours once they are on disk
Updatesevery update its author ships, delivered through this account

You can read the whole bundle before paying — the SKILL.md above is the product, not a preview of it. What the money buys is the delivery: the folder packaged and handed to your machine by key, every update its author ships, and our support if it does not do what this listing says. The terms of use are MIT, set by the author and unchanged by buying it here.

Payment runs through Stripe, on a page like this one rather than a redirect. Once there is an account it joins the same mcprush invoice as everything else you run, so there is never a second card to enter.

Which clients pick it up on their own

A skill is a folder of text. A client with a skills folder reads it without being told; everywhere else the same text works, it is just handed to the model rather than found.

Claude Code.claude/skills/
Claude Desktop
ChatGPT
Cursor.cursor/skills/
VS Code.github/skills/
Codex CLI.agents/skills/
Gemini CLI.gemini/skills/
Grok.grok/skills/
Zed.agents/skills/
Windsurf.windsurf/skills/
Agent SDK.claude/skills/
HTTP / API
This release
Versionnot versioned
Publishedno release date on file
Price$89
Referencetrpc/trpc-server-setup

Versions

Its author publishes no version number, so there is nothing here to pin to: what you install is the folder as it stands today. Instructions change more often than APIs do — a skill can be rewritten entirely without anything it depends on moving.

v
  • No earlier releases have been published to the marketplace.
Pinning

Nothing to pin to: this skill carries no version number of its own. What you install is what the folder holds on the day you install it.

Reviews

no reviews yet · no installs yet

Nobody has reviewed this skill yet. The rating is the mean of the reviews written here, so there is none until somebody writes the first.

Who can post

Only accounts that have had the skill installed for fourteen days, so a review is written after living with it rather than after reading it. Publishers may reply once.

Publisher
Servers0