Skip to content

Commit e54dcbd

Browse files
committed
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
1 parent 5d9ca75 commit e54dcbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4715
-735
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"[json]": {
66
"editor.defaultFormatter": "biomejs.biome"
77
}
8-
}
8+
}

AGENTS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Repository Guidelines
2+
3+
## Project Structure & Module Organization
4+
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.
12+
- `pnpm format` / `pnpm format:check` — apply or verify Biome formatting.
13+
14+
## Coding Style & Naming Conventions
15+
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.

CLAUDE.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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

Comments
 (0)