|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a monorepo containing MCP (Model Context Protocol) servers for Supabase integration. The project allows AI assistants like Claude to directly interact with Supabase projects through standardized tools. |
| 8 | + |
| 9 | +### Repository Structure |
| 10 | + |
| 11 | +- `packages/mcp-server-supabase/` - Main MCP server providing Supabase management tools |
| 12 | +- `packages/mcp-server-postgrest/` - PostgREST-specific MCP server for REST API interactions |
| 13 | +- `packages/mcp-utils/` - Shared utilities for building MCP servers |
| 14 | + |
| 15 | +## Development Commands |
| 16 | + |
| 17 | +### Installation |
| 18 | +```bash |
| 19 | +pnpm install |
| 20 | +``` |
| 21 | + |
| 22 | +### Building |
| 23 | +```bash |
| 24 | +# Build all packages |
| 25 | +pnpm build |
| 26 | + |
| 27 | +# Build specific package |
| 28 | +pnpm --filter @supabase/mcp-server-supabase build |
| 29 | +``` |
| 30 | + |
| 31 | +### Development |
| 32 | +```bash |
| 33 | +# Watch mode for main server |
| 34 | +cd packages/mcp-server-supabase |
| 35 | +pnpm dev |
| 36 | +``` |
| 37 | + |
| 38 | +### Testing |
| 39 | +```bash |
| 40 | +# Run all tests |
| 41 | +pnpm test |
| 42 | + |
| 43 | +# Run tests with coverage |
| 44 | +pnpm test:coverage |
| 45 | + |
| 46 | +# Run specific test types for main package |
| 47 | +pnpm --filter @supabase/mcp-server-supabase test:unit |
| 48 | +pnpm --filter @supabase/mcp-server-supabase test:e2e |
| 49 | +pnpm --filter @supabase/mcp-server-supabase test:integration |
| 50 | +``` |
| 51 | + |
| 52 | +### Linting & Formatting |
| 53 | +```bash |
| 54 | +# Format code (using Biome) |
| 55 | +pnpm format |
| 56 | + |
| 57 | +# Check formatting |
| 58 | +pnpm format:check |
| 59 | +``` |
| 60 | + |
| 61 | +### Type Checking |
| 62 | +```bash |
| 63 | +# Type check main server |
| 64 | +cd packages/mcp-server-supabase |
| 65 | +pnpm typecheck |
| 66 | +``` |
| 67 | + |
| 68 | +## Architecture |
| 69 | + |
| 70 | +### MCP Server Architecture |
| 71 | + |
| 72 | +The main server (`packages/mcp-server-supabase/`) follows a modular tool-based architecture: |
| 73 | + |
| 74 | +- **Platform Interface** (`src/platform/`): Defines operations interface that different platform implementations can fulfill |
| 75 | +- **Authentication System** (`src/auth.ts`, `src/config/`): Enhanced dual-mode authentication with automatic project detection |
| 76 | +- **Tool Groups** (`src/tools/`): Organized by feature area: |
| 77 | + - `account-tools.ts` - Project and organization management |
| 78 | + - `database-operation-tools.ts` - SQL execution and migrations |
| 79 | + - `development-tools.ts` - API keys, URLs, TypeScript type generation |
| 80 | + - `debugging-tools.ts` - Logs and performance advisors |
| 81 | + - `edge-function-tools.ts` - Edge Function deployment and management |
| 82 | + - `storage-tools.ts` - Storage bucket and config management |
| 83 | + - `branching-tools.ts` - Development branch operations |
| 84 | + - `docs-tools.ts` - Documentation search |
| 85 | + |
| 86 | +### Authentication Features (NEW) |
| 87 | + |
| 88 | +The server now includes comprehensive authentication enhancements: |
| 89 | + |
| 90 | +- **Automatic Project Detection** (`src/config/project-context.ts`): |
| 91 | + - Scans current working directory for Supabase configuration |
| 92 | + - Supports `.env`, `.env.local`, `.supabase/config.toml`, `.supabase/.env` |
| 93 | + - Framework-specific variable naming (Next.js, React, Vite) |
| 94 | + - Priority-based configuration resolution |
| 95 | + |
| 96 | +- **Enhanced Token Detection** (`src/config/supabase-config.ts`): |
| 97 | + - Automatic detection from `~/.supabase/access-token` (CLI integration) |
| 98 | + - Support for multiple token file formats and locations |
| 99 | + - Seamless integration with `supabase login` workflow |
| 100 | + |
| 101 | +- **Dual Authentication Modes** (`src/auth.ts`): |
| 102 | + - `personal-token`: Uses management API with personal access tokens |
| 103 | + - `project-keys`: Uses project-specific anon/service keys when available |
| 104 | + - Automatic switching based on available credentials |
| 105 | + |
| 106 | +- **Smart Fallback Chain**: |
| 107 | + 1. CLI flags (--project-ref) |
| 108 | + 2. Environment variables (SUPABASE_ACCESS_TOKEN) |
| 109 | + 3. Project context from working directory |
| 110 | + 4. Config files (~/.supabase/access-token) |
| 111 | + 5. None (graceful degradation) |
| 112 | + |
| 113 | +### Feature System |
| 114 | + |
| 115 | +The server uses a feature group system allowing selective tool enablement: |
| 116 | +- `--features=database,docs` enables only database and docs tools |
| 117 | +- Default groups: `account`, `database`, `debugging`, `development`, `docs`, `functions`, `branching` |
| 118 | +- Storage tools are disabled by default to reduce tool count |
| 119 | + |
| 120 | +### Platform Independence |
| 121 | + |
| 122 | +Core functionality is separated into platform-specific implementations through the `SupabasePlatform` interface, allowing different backends (API-based, local, etc.) while maintaining the same tool interface. |
| 123 | + |
| 124 | +## Key Dependencies |
| 125 | + |
| 126 | +- **pnpm** (v10.15.0) - Package manager |
| 127 | +- **Node.js** 22.18.0 (see `.nvmrc`) |
| 128 | +- **Vitest** - Testing framework with unit/e2e/integration test separation |
| 129 | +- **Biome** - Formatting and linting |
| 130 | +- **tsup** - TypeScript bundling |
| 131 | +- **Zod** - Runtime type validation and schema definition |
| 132 | + |
| 133 | +## Testing Strategy |
| 134 | + |
| 135 | +- **Unit tests**: `src/**/*.test.ts` - Component testing with 30s timeout for PGlite initialization |
| 136 | +- **E2E tests**: `test/e2e/**/*.e2e.ts` - End-to-end flows with 60s timeout |
| 137 | +- **Integration tests**: `test/**/*.integration.ts` - Integration testing |
| 138 | +- Uses Vitest workspace for parallel execution of different test types |
| 139 | +- Custom text loader plugin for SQL files |
| 140 | +- MSW for API mocking |
| 141 | + |
| 142 | +## Registry Publishing |
| 143 | + |
| 144 | +The main server is published to the official MCP registry: |
| 145 | + |
| 146 | +1. Update version in `packages/mcp-server-supabase/package.json` |
| 147 | +2. Run `pnpm registry:update` to update `server.json` |
| 148 | +3. Login with `pnpm registry:login` |
| 149 | +4. Publish with `pnpm registry:publish` |
| 150 | + |
| 151 | +## Development Configuration |
| 152 | + |
| 153 | +- Local development uses `file:` protocol for MCP client testing |
| 154 | +- Server exposes both ES modules and CommonJS builds |
| 155 | +- Multiple entry points for platform-specific usage |
| 156 | +- Uses TypeScript with `@total-typescript/tsconfig` for strict configuration |
0 commit comments