← Back to directory
C

Cloudflare Workers Next.js SaaS Template

Community
A complete Next.js SaaS template for Cloudflare Workers, featuring authentication, subscription billing, and an AI agent platform (including MCP)
GitHub source repository ↗
★ 782 Stars Category · Dev Tools Very popular Source revision a7c106a3e01d
43FMRS · D
Reliability
5/20
Security and permissions
8/20
Maintenance
10/20
Documentation
12/20
Setup experience
8/20

This template is feature-rich but complex, suitable for experienced developers. Its MCP server integration is well-designed, with tools auto-derived from OpenAPI and support for multiple client connection methods.

Read the FMRS scoring method →

This is an open-source SaaS template for running a Next.js app on Cloudflare Workers. It uses Vinext (Cloudflare's experimental Vite-based implementation of Next.js) as the build and dev toolchain, supporting App Router, React Server Components, and more. The template integrates user authentication (Lucia Auth), database (Drizzle + D1), email service, team subscription billing (Stripe), content management system, admin dashboard, and an AI agent platform including a public REST API, OAuth 2.1, and a remote MCP server. The MCP server derives its tools from an OpenAPI document and supports authentication via OAuth or API keys.

Tools

mcp_server
Exposes tools derived from the OpenAPI document, allowing AI agents to interact with the SaaS platform's public API.

Setup

This template requires self-deployment. After deployment, the MCP server endpoint is at /mcp. To connect, point an MCP client to that URL. For CLI and editor clients, you can use an Authorization: Bearer header (with an API key) or the OAuth flow.

Fit and risk

Best for

  • Developers who want to rapidly bootstrap a SaaS product with a built-in AI platform and MCP functionality
  • Teams that need comprehensive authentication and authorization for AI agents (OAuth, API keys)

Not for

  • Simple projects that do not need AI agent features or an MCP server
  • Deployments that require a Node.js server instead of Cloudflare Workers

Required permissions

  • Requires a Cloudflare account and relevant Worker bindings (D1, KV, R2, AI, etc.)
  • Requires a Stripe account and API keys to enable billing features
  • Requires configuring Turnstile keys for CAPTCHA

Risks and side effects

  • The template is experimental; Vinext and Cloudflare's MCP components may change
  • The MCP server allows AI agents to access your public API's power; if API keys or OAuth credentials leak, it could lead to unauthorized access
  • Deployment configuration is complex and requires careful setting of environment variables and bindings

Troubleshooting

  1. Ensure Cloudflare bindings (such as `OAUTH_KV`) in `wrangler.jsonc` are configured correctly
  2. Run `pnpm run typecheck` and `pnpm run lint` to check for code errors
  3. Use `pnpm run test:e2e` to test end-to-end flows
  4. Check API key prefixes in `src/constants.ts` to ensure they are rebranded for your project

Use cases

Provide AI agent integrations for your SaaS app, allowing them to perform API actions (like managing resources)
Use the MCP server as a remote MCP endpoint for clients like Claude Code, ChatGPT, Cursor, etc.

Supported clients

Claude CodeFull support
claude.aiFull support
ChatGPTFull support
CursorFull support
VS CodeFull support
CodexFull support
AntigravityFull support
Grok CLIFull support