🎯
One primitive
Capability — a typed, validated, guardable function. REST, GraphQL, WebSocket, queue, and MCP all invoke the same thing.
Write what your server can do. The framework handles how it's exposed.
// This bug is silent, common, and hard to debug
app.get('/user/:id', async (req, res) => {
const user = await db.find(req.params.id); // throws if db is down
res.json(user); // never reached — client hangs
});const getUser = capability(
z.object({ id: z.string() }),
async ({ id }) => {
const user = await db.find(id); // throws → client gets a clean 500
if (!user) throw errors.NotFound({ resource: 'user', id }); // → 404
return user; // returning is responding
},
'query',
).guard(mustBeUser); // guards run before the resolver, every time