middlewares

Create and compose tRPC middleware with TypeScript and @trpc/server.

Updated Jun 26, 2025
One-click install
npx skills add https://github.com/flaviogragnolati/coco --skill middlewares-flaviogragnolati
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middlewares
Source: https://github.com/flaviogragnolati/coco/tree/main/.agents/skills/middlewares
Command: npx skills add https://github.com/flaviogragnolati/coco --skill middlewares-flaviogragnolati

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @trpc/server, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps in creating and composing tRPC middleware for server-side requests, allowing users to build reusable middleware, extend context, and define base procedures.

Core Features & Use Cases

  • Middleware Creation: Develop custom middleware using t.procedure.use() and t.middleware() for tasks like logging, timing, and tracing.
  • Context Extension: Extend the context with additional information through opts.next({ ctx }) and build reusable middleware.
  • Procedure Definition: Define base procedures like publicProcedure and authedProcedure, and access raw input with getRawInput() for logging and tracing.
  • Use Case: Enhance your tRPC server with custom authentication, logging, and error handling middleware to improve server performance and security.

Quick Start

Initialize the middleware system in your server and define your custom middleware using the provided examples in the SKILL.md file.

Frequently Asked Questions about middlewares

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

FAQPage Schema
How do I create custom tRPC middleware for server-side logging and tracing?

Define custom tRPC middleware using t.procedure.use() and t.middleware() for server-side logging and tracing. You can access raw input with getRawInput() to capture request details and execution timing for procedure calls.

What is context extension in tRPC and how does it work with middleware?

Context extension in tRPC middleware passes additional information downstream using opts.next({ ctx }). This mechanism builds reusable middleware layers that enrich the base server context with custom data for subsequent procedures.

How do I define base procedures like publicProcedure and authedProcedure in tRPC?

Define base procedures like publicProcedure and authedProcedure by composing tRPC middleware. This establishes reusable procedure definitions that enforce specific context requirements, such as verifying user authentication, across your server routes.

Do I need TypeScript and @trpc/server installed to use tRPC middleware?

Yes, you need TypeScript and the @trpc/server library installed. This Skill develops server-side middleware specifically within the tRPC environment, requiring both dependencies to define custom procedures and extend the request context.

Can I access raw input inside tRPC middleware for logging requests?

Yes, you can access raw input inside tRPC middleware using the getRawInput() method. This allows you to intercept and log incoming request payloads before they are processed by the main procedure handler.