### Install Next Supa MCP
Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt
Instructions for installing the MCP server globally via npm or building it from the source repository.
```bash
npm install -g next-supa-mcp
git clone https://github.com/aryaintarann/next-supa-mcp.git
cd next-supa-mcp
npm install
npm run build
```
--------------------------------
### Install next-supa-mcp CLI
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
Installs the next-supa-mcp command-line interface globally using npm. This allows you to run the MCP server from your terminal.
```bash
npm install -g next-supa-mcp
```
--------------------------------
### Clone and Build next-supa-mcp Project
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/README.md
This snippet outlines the steps to clone the next-supa-mcp repository from GitHub, navigate into the project directory, install dependencies, and build the project. It's a standard procedure for setting up a project from a Git repository.
```bash
git clone https://github.com/aryaintarann/next-supa-mcp.git
cd next-supa-mcp
npm install
npm run build
```
--------------------------------
### Example Input for scaffold_auth_middleware
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
Demonstrates the input schema and an example JSON payload for the scaffold_auth_middleware tool. This defines which routes to protect and the roles required for access.
```json
{
"routes": [
{ "path": "/dashboard" },
{ "path": "/admin/:path*", "allowedRoles": ["admin"] }
],
"redirectTo": "/login"
}
```
--------------------------------
### Generate Next.js Auth Middleware with scaffold_auth_middleware
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
Example of generating a Next.js middleware.ts file using the scaffold_auth_middleware tool. This tool leverages withSupaAuth to protect routes based on user roles and redirects unauthenticated users.
```typescript
// middleware.ts
import { withSupaAuth } from 'next-supa-utils/server';
export default withSupaAuth({
routes: [
{ path: '/dashboard' },
{ path: '/admin/:path*', allowedRoles: ['admin'] },
],
redirectTo: '/login',
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};
```
--------------------------------
### Generate CRUD Server Action with next-supa-utils
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/README.md
Shows how to generate a Server Action for CRUD operations using `createAction` from `next-supa-utils`. The example illustrates an 'insert' operation for a 'posts' table, including input validation and error handling.
```typescript
'use server';
import { createAction } from 'next-supa-utils/server';
export const createPosts = createAction(
async (supabase, input: CreatePostsInput) => {
const { data, error } = await supabase
.from('posts')
.insert(input)
.select()
.single();
if (error) throw error;
return data;
}
);
```
--------------------------------
### Configure MCP Server for Claude Desktop
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
Configuration for Claude Desktop to use next-supa-mcp as its Model Context Protocol (MCP) server. It specifies the command to run and its arguments.
```json
{
"mcpServers": {
"next-supa-mcp": {
"command": "npx",
"args": ["-y", "next-supa-mcp"]
}
}
}
```
--------------------------------
### Configure MCP Client for next-supa-mcp
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/README.md
This section provides JSON configurations for integrating the next-supa-mcp server with various AI clients like Claude Desktop, Cursor, VS Code (Copilot), and Windsurf. It specifies the command to run the Node.js server and its arguments, requiring users to replace a placeholder path with their actual project location.
```json
{
"mcpServers": {
"next-supa-mcp": {
"command": "node",
"args": ["/absolute/path/to/next-supa-mcp/dist/index.js"]
}
}
}
```
```json
{
"servers": {
"next-supa-mcp": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/next-supa-mcp/dist/index.js"]
}
}
}
```
--------------------------------
### Configure MCP Server for VS Code (Copilot)
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
Configuration for VS Code with Copilot to integrate next-supa-mcp. This enables Copilot to generate code using the specified MCP server, ensuring consistency with next-supa-utils.
```json
{
"servers": {
"next-supa-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "next-supa-mcp"]
}
}
}
```
--------------------------------
### Import Server-Side Helpers from next-supa-utils
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
Imports key server-side utilities from the next-supa-utils library. These include middleware for authentication, wrappers for Server Actions, and helpers for Route Handlers.
```typescript
import {
withSupaAuth,
createAction,
routeWrapper,
} from 'next-supa-utils/server';
```
--------------------------------
### Configure MCP Clients
Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt
Configuration snippets for integrating the Next Supa MCP server into various AI development environments including Claude Desktop, Cursor, VS Code, and Windsurf.
```json
// Claude Desktop Configuration
{
"mcpServers": {
"next-supa-mcp": {
"command": "npx",
"args": ["-y", "next-supa-mcp"]
}
}
}
```
```json
// Cursor Configuration
{
"mcpServers": {
"next-supa-mcp": {
"command": "node",
"args": ["/absolute/path/to/next-supa-mcp/dist/index.js"]
}
}
}
```
```json
// VS Code (Copilot) Configuration
{
"servers": {
"next-supa-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "next-supa-mcp"]
}
}
}
```
```json
// Windsurf Configuration
{
"mcpServers": {
"next-supa-mcp": {
"command": "npx",
"args": ["-y", "next-supa-mcp"]
}
}
}
```
--------------------------------
### Configure SupaProvider for Client-Side
Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt
The SupaProvider component is used to wrap the application layout for custom or multi-tenant Supabase instances. It requires the supabaseUrl and supabaseAnonKey as props to initialize the client context.
```typescript
'use client';
import { SupaProvider } from 'next-supa-utils/client';
export default function Layout({ children }) {
return (
Loading...
; returnWelcome, {user?.email}
; } ``` -------------------------------- ### Import Client-Side Hooks from next-supa-utils Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt Imports essential client-side hooks from the next-supa-utils library. These hooks facilitate authentication, data fetching, file uploads, and real-time subscriptions with Supabase in Next.js applications. ```typescript import { SupaProvider, useSupaUser, useSupaSession, useSupaUpload, useSupaRealtime, } from 'next-supa-utils/client'; ``` -------------------------------- ### Protect Routes with withSupaAuth Middleware Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt Configures server-side route protection using withSupaAuth. Supports path-based access control, role-based access (RBAC), and custom redirection logic. ```typescript import { withSupaAuth } from 'next-supa-utils/server'; export default withSupaAuth({ routes: [ { path: '/dashboard' }, { path: '/admin/:path*', allowedRoles: ['admin'] }, ], redirectTo: '/login', }); ``` -------------------------------- ### Generate Auth Middleware with next-supa-utils Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/README.md Demonstrates the input JSON structure and the resulting TypeScript code for generating an authentication middleware using `withSupaAuth` from `next-supa-utils`. This tool supports route protection and role-based access control (RBAC). ```typescript import { withSupaAuth } from 'next-supa-utils/server'; export default withSupaAuth({ routes: [ { path: '/dashboard' }, { path: '/admin/:path*', allowedRoles: ['admin'] }, ], redirectTo: '/login', }); export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'], }; ``` -------------------------------- ### Implement API Route Handlers with routeWrapper Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt The routeWrapper utility simplifies the creation of API route handlers by automatically injecting a pre-configured Supabase client. It handles the request and context, allowing for clean data fetching and error handling. ```typescript import { routeWrapper } from 'next-supa-utils/server'; export const GET = routeWrapper(async (supabase, request, context) => { const { data, error } = await supabase .from('posts') .select(); if (error) throw error; return data; }); ``` -------------------------------- ### Generate CRUD Server Actions with createAction Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt Uses the createAction wrapper to generate type-safe Next.js Server Actions. It automatically injects the Supabase client as the first argument and returns a standardized { data, error } response. ```typescript 'use server'; import { createAction } from 'next-supa-utils/server'; interface CreatePostsInput { title: string; content?: string; } export const createPosts = createAction( async (supabase, input: CreatePostsInput) => { const { data, error } = await supabase .from('posts') .insert(input) .select() .single(); if (error) throw error; return data; } ); ``` -------------------------------- ### Manage Auth State with Client Hooks Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt Provides React hooks for accessing the current user and session data on the client side. These hooks handle loading states automatically. ```typescript 'use client'; import { useSupaUser, useSupaSession } from 'next-supa-utils/client'; export default function AuthInfo() { const { user, isLoading: userLoading } = useSupaUser(); const { session, isLoading: sessionLoading } = useSupaSession(); if (userLoading || sessionLoading) returnLoading...
; returnUser: {user?.email}
; } ``` -------------------------------- ### POST /generate_crud_action Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt Generates a Next.js Server Action function using the createAction wrapper, which automatically handles Supabase client injection and error formatting. ```APIDOC ## POST /generate_crud_action ### Description Generates a Next.js Server Action for database operations. The generated function uses `createAction` to inject the Supabase client and return a standardized `{ data, error }` object. ### Method POST ### Endpoint /generate_crud_action ### Parameters #### Request Body - **tableName** (string) - Required - The name of the database table (e.g., "posts"). - **operation** (string) - Required - The CRUD operation to perform: "insert", "update", or "delete". ### Request Example { "tableName": "posts", "operation": "insert" } ### Response #### Success Response (200) - **code** (string) - The generated TypeScript code for the Server Action. #### Response Example { "code": "'use server';\nimport { createAction } from 'next-supa-utils/server';\n..." } ``` -------------------------------- ### Configure Authentication Middleware with withSupaAuth Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt The withSupaAuth function creates Next.js middleware for authentication and role-based access control. It supports route protection, public route bypassing, and custom role extraction logic. ```typescript import { withSupaAuth } from 'next-supa-utils/server'; export default withSupaAuth({ routes: [ { path: '/dashboard' }, { path: '/admin/:path*', allowedRoles: ['admin'] }, ], redirectTo: '/login', publicRoutes: ['/about', '/pricing'], }); export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'], }; ``` -------------------------------- ### Scaffold Authentication Middleware Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt The scaffold_auth_middleware tool generates a standardized middleware.ts file using withSupaAuth, supporting route-based access control and custom redirects. ```typescript import { withSupaAuth } from 'next-supa-utils/server'; export default withSupaAuth({ routes: [ { path: '/dashboard' }, { path: '/admin/:path*', allowedRoles: ['admin'] }, { path: '/editor/:path*', allowedRoles: ['admin', 'editor'] }, ], redirectTo: '/login', }); export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'], }; ``` -------------------------------- ### POST /read_supabase_schema Source: https://github.com/aryaintarann/next-supa-mcp/blob/main/llms.txt Reads the TypeScript schema file from a Supabase project to provide context for CRUD generation. ```APIDOC ## POST /read_supabase_schema ### Description Retrieves the contents of the Supabase TypeScript schema file. This should be called before generating CRUD actions to ensure accurate table and column mapping. ### Method POST ### Endpoint /read_supabase_schema ### Parameters #### Request Body - **filePath** (string) - Optional - Path to the schema file. Defaults to "types/database.types.ts". ### Request Example { "filePath": "types/database.types.ts" } ### Response #### Success Response (200) - **content** (string) - The raw content of the schema file. ``` -------------------------------- ### Handle API Routes with routeWrapper Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt The routeWrapper function wraps Next.js API route handlers to provide an injected Supabase client instance. This eliminates the need for manual client initialization within individual route files. ```typescript import { routeWrapper } from 'next-supa-utils/server'; export const GET = routeWrapper(async (supabase, request, context) => { const { data, error } = await supabase .from('posts') .select('*') .order('created_at', { ascending: false }); if (error) throw error; return data; }); ``` -------------------------------- ### Wrap Server Actions with createAction Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt The createAction function simplifies Server Actions by automatically injecting a Supabase client and providing standardized error handling. It returns a structured response containing either the data or a SupaError. ```typescript 'use server'; import { createAction } from 'next-supa-utils/server'; export const getProfile = createAction( async (supabase, userId: string) => { const { data, error } = await supabase .from('profiles') .select('*') .eq('id', userId) .single(); if (error) throw error; return data; } ); ``` -------------------------------- ### Access Auth State with Client Hooks Source: https://context7.com/aryaintarann/next-supa-mcp/llms.txt Client-side hooks provide access to the current user profile and session information. The SupaProvider component allows for custom configuration of the Supabase client in multi-tenant or specific environments. ```typescript 'use client'; import { useSupaUser, useSupaSession } from 'next-supa-utils/client'; function UserProfile() { const { user, isLoading } = useSupaUser(); if (isLoading) returnLoading...
; return