xrpc-server

Build and register XRPC routes on AT Protocol services using @atproto/xrpc-server.

9.6k|915|Updated Dec 17, 2021
One-click install
npx skills add https://github.com/bluesky-social/atproto --skill xrpc-server
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: xrpc-server
Source: https://github.com/bluesky-social/atproto/tree/main/.agents/skills/xrpc-server
Command: npx skills add https://github.com/bluesky-social/atproto --skill xrpc-server

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @atproto/xrpc-server.

What problem does it solve?

Adding or changing endpoints on AT Protocol services like the PDS or bsky appview requires knowing the exact conventions of @atproto/xrpc-server — how to wire createServer into Express, register handlers with server.add(), read params and auth, return JSON or streamed responses, and throw protocol-correct errors. This Skill encodes those conventions so route work is done correctly the first time.

Core Features & Use Cases

  • Route Registration: Register query, procedure, and subscription handlers via server.add() with generated lexicon schemas, including auth verifiers, per-route rate limits, and body size limits.
  • Response Handling: Return JSON bodies, binary streams, empty responses, and custom headers, with guidance on TypeScript as const narrowing pitfalls and schema output validation.
  • Protocol Errors & Subscriptions: Throw the correct XRPCError subclass for each HTTP status, and implement WebSocket subscriptions as async generators with abort-signal handling.
  • Use Case: When adding a new endpoint like app.bsky.draft.createDraft to the bsky service, use this Skill to scaffold the handler file under src/api/, wire auth and rate limits, and return a schema-valid response.

Quick Start

Add a new XRPC endpoint to the PDS that resolves a handle to a DID using @atproto/xrpc-server conventions.

Frequently Asked Questions about xrpc-server

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

FAQPage Schema
How do I add a new XRPC endpoint to an AT Protocol service?

Create a file under src/api/ matching the NSID path, default-export a registrar function, and call server.add() with the generated lexicon schema and your handler. Then import and invoke the registrar in src/api/index.ts.

How do I return JSON from an xrpc-server handler?

Return an object with encoding set to 'application/json' and a body matching the schema's output. If the literal is built in an intermediate variable or the handler takes no parameters, add 'as const' to the encoding so TypeScript keeps the narrow type.

What is the difference between XRPCError and XrpcError in atproto?

XRPCError is the server-side class from @atproto/xrpc-server thrown inside handlers, with subclasses like InvalidRequestError (400) and AuthRequiredError (401). XrpcError is the client-side class from @atproto/lex-client used when calling out to other services.

Does @atproto/xrpc-server support WebSocket subscriptions?

Yes. Register a subscription schema with an async generator handler that yields $build()-ed messages; the server frames and validates each one. The handler context includes a signal that aborts when the client disconnects.

How do I apply rate limits to an XRPC route?

Pass a rateLimit option to server.add() with calcKey and calcPoints functions, referencing either a shared limiter declared in createServer's rateLimits.shared or a route-local limiter with durationMs and points. Handlers can call resetRouteRateLimits() to clear consumed points.

When should I use the lexification-server skill instead of xrpc-server?

Use lexification-server when migrating a service off the legacy generated server stack (server.xrpc.router) onto the schema-based server.add() pattern. Use xrpc-server for building or editing routes on services already using @atproto/xrpc-server directly.