Skip to content

Middleware

lynq ships with 17 built-in middleware, each available from its own entry point.

Built-in

MiddlewareHookDescriptionImport
guard()onRegister + onCallSession key visibility gate@lynq/lynq/guard
credentials()onRegister + onCallForm-based auth via elicitation@lynq/lynq/credentials
logger()onCallTool call logging with timing@lynq/lynq/logger
rateLimit()onCallRate limiting (session or Store-based)@lynq/lynq/rate-limit
cache()onCall + onResultStore-backed response caching@lynq/lynq/cache
retry()onCallAutomatic retry with backoff@lynq/lynq/retry
truncate()onResultResponse text truncation@lynq/lynq/truncate
some() / every() / except()allMiddleware combinators@lynq/lynq/combine

Auth Providers

MiddlewareDescriptionImport
bearer()Bearer token verification@lynq/lynq/bearer
jwt()JWT verification (requires jose)@lynq/lynq/jwt
github()GitHub OAuth flow@lynq/github
google()Google OAuth flow@lynq/google
oauth()Generic URL-based OAuth@lynq/lynq/oauth

Payment Providers

MiddlewareDescriptionImport
payment()URL-based payment flow@lynq/lynq/payment

Low-level

MiddlewareDescriptionImport
urlAction()Base for URL elicitation flows@lynq/lynq/url-action

urlAction() is the foundation for oauth() and payment(). Use it directly only when building custom URL-based flows.

All URL-based middleware (oauth, payment, stripe, crypto, github, google) support skipIf and onComplete callbacks for custom persistence logic. See Store — Without Store.

Quick Example

ts
import { guard } from "@lynq/lynq/guard";
import { logger } from "@lynq/lynq/logger";
import { rateLimit } from "@lynq/lynq/rate-limit";
import { cache } from "@lynq/lynq/cache";

server.use(logger());
server.tool("search", guard(), rateLimit({ max: 10 }), cache({ ttl: 60 }), config, handler);

What's Next