effect-rpc-api

Define type-safe RPC contracts with Effect's Rpc, RpcGroup, RpcSchema, and RpcMiddleware modules.

3|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-rpc-api-mpsuesser
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-rpc-api
Source: https://github.com/mpsuesser/opencode-effect-enforcer/tree/main/skills/effect-rpc-api
Command: npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-rpc-api-mpsuesser

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Defining RPC contracts that both client and server packages can share is error-prone: payload, success, error, and defect schemas drift apart, streaming endpoints are typed inconsistently, and middleware requirements surface only at runtime. This Skill guides an agent to declare shared, type-safe RPC contracts using effect/unstable/rpc so contract changes become compile errors on both sides. ## Core Features & Use Cases - Procedure definition with Rpc.make: Declare payload, success, error, and defect schemas per procedure, with struct-field or Schema.Class payloads, primaryKey identity, and custom defect serialization. - Streaming and composition: Model streaming endpoints with stream: true / RpcSchema.Stream, and compose contracts with RpcGroup combinators (add, merge, omit, prefix, annotate, middleware). - Middleware contracts: Define RpcMiddleware.Service classes with provides/requires/clientError type parameters, wire error schemas, and layerClient client-side implementations. - Use Case: Build a shared contract package where UsersGroup = RpcGroup.make(GetUser, CreateUser, WatchUsers).middleware(AuthMiddleware) is imported by both the server (which implements handlers via toLayer) and the client (which builds RpcClient.make(UsersGroup)), keeping both sides type-checked against one source of truth. ## Quick Start Ask the agent to define a shared Effect RPC contract with a GetUser procedure, a streaming WatchUsers endpoint, and an auth middleware using the effect-rpc-api skill.

Frequently Asked Questions about effect-rpc-api

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

FAQPage Schema
How do I define a type-safe RPC contract in Effect v4?

Use Rpc.make from effect/unstable/rpc with a tag and payload, success, error, and defect schemas, then group procedures with RpcGroup.make. Both const-style and class-extends declarations are supported, and the group is imported by client and server packages.

How do I add a streaming endpoint to an Effect RPC contract?

Set stream: true in Rpc.make so success becomes the stream element schema and error becomes the stream error schema. Handlers then return a Stream of elements and clients receive a Stream with the stream error union.

Does Effect v4 still use the @effect/rpc package?

No, @effect/rpc does not exist in v4. All RPC modules live under effect/unstable/rpc, and deep subpath imports like effect/unstable/rpc/RpcMessage also work.

How does RPC middleware work in Effect v4?

Define a class extending RpcMiddleware.Service with provides, requires, and clientError in the config type parameter, plus error and requiredForClient options. Attach it with rpc.middleware or group.middleware so its error joins the rpc error union and its provides services reach handlers.

Why is primaryKey rejected when I pass a schema payload to Rpc.make?

primaryKey is typed never unless the payload is given as inline struct fields, because Rpc.make builds a Schema.Class implementing PrimaryKey.symbol from those fields. Use inline fields or drop primaryKey for schema payloads.

What happens when RpcGroup.merge has duplicate tags?

Merge is last-wins on duplicate rpc tags and duplicate group annotation keys, with no error raised. Prefix groups before merging to make tag collisions impossible.