You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: automatic project detection and enhanced authentication
- Add automatic Supabase project detection from working directory
- Scan .env, .env.local, .supabase/config.toml, .supabase/.env files
- Support framework-specific variables (Next.js, React, Vite)
- Priority-based configuration resolution system
- Extract project credentials and auto-switch context
- Enhance personal access token detection
- Auto-detect from ~/.supabase/access-token (CLI integration)
- Support multiple token file formats and locations
- Seamless integration with `supabase login` workflow
- Smart fallback chain for token resolution
- Implement dual authentication modes
- personal-token: Management API with personal access tokens
- project-keys: Project-specific anon/service keys when available
- Automatic mode switching based on available credentials
- Update platform integration
- Enhanced API platform to use project context
- Project-specific URL and key resolution
- Improved fallback handling for missing credentials
- Add comprehensive test suite
- Unit tests for project context detection
- Enhanced authentication flow testing
- Config file parsing and validation tests
- Update documentation and examples
- README with automatic detection features
- CHANGELOG with detailed feature descriptions
- Enhanced Claude CLI integration guide
The pnpm workspace centers on `packages/mcp-server-supabase` (production MCP server) and `packages/mcp-utils` (shared schemas, validation, and helpers). An experimental `mcp-server-postgrest` lives alongside them for targeted pilots. Runtime code stays under each package’s `src/`; Vitest fixtures sit in sibling `test/` folders. Top-level `docs/` holds integration guides, `scripts/` provides registry and release automation, and `supabase/` contains migrations plus seed data consumed by integration suites.
5
+
6
+
## Build, Test, and Development Commands
7
+
-`pnpm install` — install workspace dependencies.
8
+
-`pnpm build` — run `tsup` builds for utils and the Supabase server.
9
+
-`pnpm --filter @supabase/mcp-server-supabase dev` — watch-and-rebuild while coding.
10
+
-`pnpm test` — execute all Vitest projects in parallel.
11
+
-`pnpm test:coverage` — collect coverage for the Supabase server.
Code is TypeScript-first, strict ESM, and two-space indented. Favor named exports; map filesystem names to camelCase exports (see `src/tools`). Generated OpenAPI artifacts belong under `src/management-api/`. Biome is the source of truth for formatting, linting, and import order—run it before committing. `tsup.config.ts` already targets both ESM and CJS outputs; keep new entrypoints consistent with existing build targets.
16
+
17
+
## Testing Guidelines
18
+
Vitest drives unit, integration, and e2e suites configured in `vitest.workspace.ts`. Use package-scoped scripts (`pnpm test:unit`, `test:integration`, `test:e2e`) for faster iteration. Integration flows expect the seeded Supabase instance; refresh with `supabase db reset` when fixtures drift. Place new tests beside the modules they cover, naming files `*.test.ts`, and assert on concrete Supabase responses where possible instead of broad snapshots.
19
+
20
+
## Commit & Pull Request Guidelines
21
+
Follow Conventional Commits (`feat:`, `fix:`, `chore:`) and collapse WIP history before raising a PR. Reference Supabase issues or MCP registry tickets when applicable. PR descriptions should outline behaviour changes, highlight tooling updates, and mention any Supabase config required for reviewers. Confirm `pnpm build`, `pnpm test`, and `pnpm format:check` pass locally, and attach CLI output for non-obvious failures or regressions.
22
+
23
+
## Security & Configuration Tips
24
+
Store `SUPABASE_ACCESS_TOKEN` outside the repo (environment managers or MCP client secrets). Prefer `--read-only` and `--project-ref` flags when sharing demos, and scrub captured payloads before committing fixtures or docs.
Copy file name to clipboardExpand all lines: README.md
+307-3Lines changed: 307 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,10 +126,293 @@ Make sure Node.js is available in your system `PATH` environment variable. If yo
126
126
127
127
3. Restart your MCP client.
128
128
129
-
### 3. Follow our security best practices
129
+
### 3. Automatic Project Detection (New)
130
+
131
+
The MCP server now supports automatic detection of your Supabase project configuration from your current working directory. This feature simplifies setup by automatically detecting project credentials and configuration.
132
+
133
+
#### How it works
134
+
135
+
When you start the MCP server, it will automatically scan your current working directory for Supabase configuration in the following priority order:
136
+
137
+
1.**`.env` file** - Checks for `SUPABASE_URL`, `SUPABASE_ANON_KEY`, `SUPABASE_SERVICE_ROLE_KEY`
138
+
2.**`.env.local` file** - Overrides `.env` values if present
2.**Supabase CLI directory**: `~/.supabase/access-token` (automatically created by `supabase login`)
153
+
3.**Alternative token files**: `~/.supabase/token`, `~/.supabase/config.toml`, etc.
154
+
155
+
#### Usage
156
+
157
+
With automatic detection, you can simply run:
158
+
159
+
```shell
160
+
npx -y @supabase/mcp-server-supabase@latest
161
+
```
162
+
163
+
The server will automatically:
164
+
- Detect your personal access token from `~/.supabase/access-token`
165
+
- Extract project credentials from your working directory
166
+
- Switch to the detected project context
167
+
- Use project-specific API keys when available
168
+
169
+
#### Benefits
170
+
171
+
-**Zero configuration** for projects with proper `.env` setup
172
+
-**Framework agnostic** - works with Next.js, React, Vite, and others
173
+
-**Secure** - Uses project-specific keys when available, falls back to personal tokens
174
+
-**CLI integration** - Works seamlessly with `supabase login` and existing workflows
175
+
176
+
### 4. Follow our security best practices
130
177
131
178
Before running the MCP server, we recommend you read our [security best practices](#security-risks) to understand the risks of connecting an LLM to your Supabase projects and how to mitigate them.
132
179
180
+
## Claude CLI Configuration
181
+
182
+
If you're using this MCP server with Claude CLI specifically, we **strongly recommend using the wrapper script approach** for reliable authentication.
183
+
184
+
### Recommended Setup (Wrapper Script Method)
185
+
186
+
This is the most reliable method for Claude CLI integration:
187
+
188
+
#### 1. Download the Authentication Wrapper Script
claude mcp add supabase npx @supabase/mcp-server-supabase --project-ref=your_project_ref
252
+
```
253
+
254
+
**Note**: This method may experience authentication issues due to how Claude CLI handles environment variables. If you encounter problems, switch to the wrapper script method.
255
+
256
+
### Troubleshooting Claude CLI Issues
257
+
258
+
If you experience authentication errors:
259
+
260
+
#### "Unauthorized. Please provide a valid access token" Error
261
+
262
+
This is the most common issue. Follow these steps:
263
+
264
+
1.**Verify Token Format**: Ensure your token starts with `sbp_`:
265
+
```bash
266
+
echo$SUPABASE_ACCESS_TOKEN| grep "^sbp_"
267
+
```
268
+
269
+
2.**Use Wrapper Script**: If using environment variables isn't working, switch to the wrapper script method (recommended).
270
+
271
+
3.**Check Token Validity**: Generate a new token at [Supabase Token Settings](https://supabase.com/dashboard/account/tokens).
272
+
273
+
4.**Restart Claude CLI**: After making changes, restart Claude CLI completely.
274
+
275
+
#### "Failed to reconnect to supabase" Error
276
+
277
+
1.**Check MCP Status**:
278
+
```bash
279
+
claude mcp list
280
+
```
281
+
282
+
2.**Remove and Re-add**:
283
+
```bash
284
+
claude mcp remove supabase
285
+
claude mcp add supabase /path/to/supabase-mcp-wrapper.sh
286
+
```
287
+
288
+
3.**Verify Script Permissions**:
289
+
```bash
290
+
chmod +x /path/to/supabase-mcp-wrapper.sh
291
+
```
292
+
293
+
#### Common Token Issues
294
+
295
+
**Wrong Token Type**: The most common mistake is using the wrong type of Supabase token:
296
+
297
+
- ❌ **API Keys** (`sb_publishable_...` or `sb_secret_...`) - These are for client applications
298
+
- ❌ **Environment Variables** (`SUPABASE_ACCESS_TOKEN=sbp_...`) - Don't put the variable name in config files
299
+
- ✅ **Personal Access Token** (`sbp_...`) - Required for Management API operations
300
+
301
+
**File Configuration Issues**:
302
+
303
+
1.**Check `~/.supabase/access-token`** should contain only the token:
304
+
```bash
305
+
# Correct - just the token
306
+
sbp_your_actual_token_here
307
+
308
+
# Wrong - contains variable syntax
309
+
SUPABASE_ACCESS_TOKEN=sbp_your_actual_token_here
310
+
```
311
+
312
+
2.**Verify Environment Variables**:
313
+
```bash
314
+
echo$SUPABASE_ACCESS_TOKEN
315
+
# Should output your sbp_ token, not empty or undefined
316
+
```
317
+
318
+
#### Environment Setup Issues
319
+
320
+
**PATH Problems**: If the wrapper script can't find `npx`:
-**Contextual Guidance**: Step-by-step instructions tailored for Claude CLI workflows
414
+
-**Security Warnings**: Automatic alerts for high-risk operations
415
+
133
416
### Project scoped mode
134
417
135
418
Without project scoping, the MCP server will have access to all organizations and projects in your Supabase account. We recommend you restrict the server to a specific project by setting the `--project-ref` flag on the CLI command:
@@ -171,9 +454,9 @@ You can enable or disable specific tool groups by passing the `--features` flag
Available groups are: [`account`](#account), [`docs`](#knowledge-base), [`database`](#database), [`debugging`](#debugging), [`development`](#development), [`functions`](#edge-functions), [`storage`](#storage), and [`branching`](#branching-experimental-requires-a-paid-plan).
457
+
Available groups are: [`account`](#account), [`docs`](#knowledge-base), [`database`](#database), [`debugging`](#debugging), [`development`](#development), [`functions`](#edge-functions), [`storage`](#storage), [`branching`](#branching-experimental-requires-a-paid-plan), and [`runtime`](#runtime-claude-cli-optimized).
175
458
176
-
If this flag is not passed, the default feature groups are: `account`, `database`, `debugging`, `development`, `docs`, `functions`, and `branching`.
459
+
If this flag is not passed, the default feature groups are: `account`, `database`, `debugging`, `development`, `docs`, `functions`, `branching`, and `runtime`.
177
460
178
461
## Tools
179
462
@@ -255,6 +538,27 @@ Disabled by default to reduce tool count. Use `storage` to target this group of
255
538
-`get_storage_config`: Gets the storage config for a Supabase project.
256
539
-`update_storage_config`: Updates the storage config for a Supabase project (requires a paid plan).
257
540
541
+
#### Runtime (Claude CLI Optimized)
542
+
543
+
Enabled by default for enhanced Claude CLI integration. Use `runtime` to target this group of tools with the [`--features`](#feature-groups) option.
544
+
545
+
**Mode Management:**
546
+
-`toggle_read_only_mode`: Toggle between read-only and write modes with Claude CLI-specific confirmations
547
+
-`get_runtime_mode_status`: Get current mode status with security information and Claude CLI guidance
548
+
-`set_read_only_mode`: Explicitly set read-only or write mode
549
+
-`validate_mode_change`: Check mode change requirements and confirmations needed
550
+
551
+
**Project Management:**
552
+
-`switch_project`: Interactive project switching with Claude CLI-formatted project lists
553
+
-`get_current_project`: Get details about the currently selected project
554
+
-`list_projects`: List all available projects with Claude CLI-optimized display
555
+
556
+
**Claude CLI Features:**
557
+
- Interactive confirmations for destructive operations
558
+
- Visual status indicators (🔒 read-only, 🔓 write, 🎯 current project)
559
+
- Context-aware error messages and guidance
560
+
- Security warnings and recommendations
561
+
258
562
## Security risks
259
563
260
564
Connecting any data source to an LLM carries inherent risks, especially when it stores sensitive data. Supabase is no exception, so it's important to discuss what risks you should be aware of and extra precautions you can take to lower them.
0 commit comments