Install
Setup
Get your API key
Copy your API key from the Foldset dashboard.
Set the environment variable
The SDK reads your API key from the Production: set it in your hosting provider’s environment variable settings (e.g. Railway, Render, AWS). Never commit API keys to your repository.
FOLDSET_API_KEY environment variable.Local development: add it to a .env file and load it with dotenv (or your preferred env loader). Make sure .env is in your .gitignore:Add the middleware
Configure routes
Head to the rules page to choose which paths to protect and set prices.
How it works
The Foldset middleware runs on every incoming request:- Checks the request path against your configured rules
- If no payment is required, calls
next()and your route handler runs normally - If payment is required and no valid x402 payment header is present, returns a
402 Payment Requiredresponse with payment instructions - If a valid payment is attached, calls
next()and settles the payment after your route handler responds
MCP server protection
If your Express app hosts an MCP server (Streamable HTTP), Foldset can gate individual tool calls and resource reads. Configure MCP rules in the dashboard by specifying the endpoint path, method, and tool or resource name. Discovery methods liketools/list pass through for free with payment metadata attached.
Update your robots.txt
Once Foldset is active, you want AI agents visiting your site so they can pay for access. If yourrobots.txt blocks AI crawlers, remove those rules. Foldset handles gating at the payment layer.