@aliyun-rds/supabase-mcp-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -0
- package/dist/index.js +1875 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Self-Hosted Supabase MCP Server
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) server for self-hosted Supabase instances. Allows AI assistants like Claude to interact with your self-hosted Supabase database.
|
|
4
|
+
|
|
5
|
+
Originally developed by [HenkDz](https://github.com/HenkDz), now maintained by lemontreen.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
This server exposes a rich set of tools for interacting with your self-hosted Supabase instance:
|
|
10
|
+
|
|
11
|
+
* **Database Schema**
|
|
12
|
+
* `list_tables`: Lists all tables in the `public` schema.
|
|
13
|
+
* `list_extensions`: Lists installed PostgreSQL extensions.
|
|
14
|
+
* `get_database_connections`: Retrieves current database connection information.
|
|
15
|
+
* `get_database_stats`: Gets database statistics (e.g., table sizes).
|
|
16
|
+
* **Migrations & SQL**
|
|
17
|
+
* `list_migrations`: Lists applied migrations from the `supabase_migrations` schema.
|
|
18
|
+
* `apply_migration`: Applies a new SQL migration (Requires direct DB access).
|
|
19
|
+
* `execute_sql`: Executes arbitrary SQL (Requires helper function in DB or direct DB access).
|
|
20
|
+
* `generate_typescript_types`: Generates TypeScript types from the database schema.
|
|
21
|
+
* **Project Configuration**
|
|
22
|
+
* `get_project_url`: Returns the configured Supabase project URL.
|
|
23
|
+
* `get_anon_key`: Returns the configured Supabase Anon Key.
|
|
24
|
+
* `get_service_key`: Returns the configured Supabase Service Role Key (if provided).
|
|
25
|
+
* `verify_jwt_secret`: Verifies the provided JWT secret against the database (Requires direct DB access).
|
|
26
|
+
* **Infrastructure**
|
|
27
|
+
* `rebuild_hooks`: Attempts to restart the `pg_net` worker (if used).
|
|
28
|
+
* **Auth User Management**
|
|
29
|
+
* `list_auth_users`: Lists users from `auth.users`.
|
|
30
|
+
* `get_auth_user`: Retrieves details for a specific user.
|
|
31
|
+
* `create_auth_user`: Creates a new user (Requires direct DB access, insecure password handling).
|
|
32
|
+
* `delete_auth_user`: Deletes a user (Requires direct DB access).
|
|
33
|
+
* `update_auth_user`: Updates user details (Requires direct DB access, insecure password handling).
|
|
34
|
+
* **Storage Insights**
|
|
35
|
+
* `list_storage_buckets`: Lists all storage buckets.
|
|
36
|
+
* `list_storage_objects`: Lists objects within a specific bucket.
|
|
37
|
+
* **Realtime Inspection**
|
|
38
|
+
* `list_realtime_publications`: Lists PostgreSQL publications (often `supabase_realtime`).
|
|
39
|
+
|
|
40
|
+
*(Note: `get_logs` was initially planned but skipped due to implementation complexities in a self-hosted environment).*
|
|
41
|
+
|
|
42
|
+
## How It Works
|
|
43
|
+
|
|
44
|
+
This MCP server works with AI assistant tools like Claude Desktop, Cursor, and other MCP-compatible applications. Once configured, these AI assistants can automatically use the tools provided by this server to interact with your self-hosted Supabase instance.
|
|
45
|
+
|
|
46
|
+
For example, when you ask an AI assistant "List all tables in my database", it will:
|
|
47
|
+
1. Recognize it needs to use a database tool
|
|
48
|
+
2. Call the `list_tables` tool from this server
|
|
49
|
+
3. Execute the tool against your Supabase instance
|
|
50
|
+
4. Present the results in a human-readable format
|
|
51
|
+
|
|
52
|
+
## Setup and Installation
|
|
53
|
+
|
|
54
|
+
### Method 1: Using npx (Recommended)
|
|
55
|
+
|
|
56
|
+
The easiest way to use this server is via npx, which requires no installation:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx @lemontreen/rds-supabase-mcp-server --url http://localhost:8000 --anon-key YOUR_ANON_KEY
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Method 2: Installing via Smithery
|
|
63
|
+
|
|
64
|
+
To install Self-Hosted Supabase MCP Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@HenkDz/selfhosted-supabase-mcp):
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npx -y @smithery/cli install @HenkDz/selfhosted-supabase-mcp --client claude
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Method 3: Global Installation
|
|
71
|
+
|
|
72
|
+
Install the package globally:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install -g @lemontreen/rds-supabase-mcp-server
|
|
76
|
+
supabase-mcp --url http://localhost:8000 --anon-key YOUR_ANON_KEY
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Method 4: Local Installation and Build
|
|
80
|
+
|
|
81
|
+
If you want to build from source:
|
|
82
|
+
|
|
83
|
+
#### Prerequisites
|
|
84
|
+
|
|
85
|
+
* Node.js (Version 18.x or later recommended)
|
|
86
|
+
* npm (usually included with Node.js)
|
|
87
|
+
* Access to your self-hosted Supabase instance (URL, keys, potentially direct DB connection string).
|
|
88
|
+
|
|
89
|
+
#### Steps
|
|
90
|
+
|
|
91
|
+
1. **Clone the repository:**
|
|
92
|
+
```bash
|
|
93
|
+
git clone <repository-url>
|
|
94
|
+
cd selfhosted-supabase-mcp
|
|
95
|
+
```
|
|
96
|
+
2. **Install dependencies:**
|
|
97
|
+
```bash
|
|
98
|
+
npm install
|
|
99
|
+
```
|
|
100
|
+
3. **Build the project:**
|
|
101
|
+
```bash
|
|
102
|
+
npm run build
|
|
103
|
+
```
|
|
104
|
+
This compiles the TypeScript code to JavaScript in the `dist` directory.
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
The server requires configuration details for your Supabase instance. These can be provided via command-line arguments or environment variables. CLI arguments take precedence.
|
|
109
|
+
|
|
110
|
+
**Required:**
|
|
111
|
+
|
|
112
|
+
* `--url <url>` or `SUPABASE_URL=<url>`: The main HTTP URL of your Supabase project (e.g., `http://localhost:8000`).
|
|
113
|
+
* `--anon-key <key>` or `SUPABASE_ANON_KEY=<key>`: Your Supabase project's anonymous key.
|
|
114
|
+
|
|
115
|
+
**Optional (but Recommended/Required for certain tools):**
|
|
116
|
+
|
|
117
|
+
* `--service-key <key>` or `SUPABASE_SERVICE_ROLE_KEY=<key>`: Your Supabase project's service role key. Needed for operations requiring elevated privileges, like attempting to automatically create the `execute_sql` helper function if it doesn't exist.
|
|
118
|
+
* `--db-url <url>` or `DATABASE_URL=<url>`: The direct PostgreSQL connection string for your Supabase database (e.g., `postgresql://postgres:password@localhost:5432/postgres`). Required for tools needing direct database access or transactions (`apply_migration`, Auth tools, Storage tools, querying `pg_catalog`, etc.).
|
|
119
|
+
* `--jwt-secret <secret>` or `SUPABASE_AUTH_JWT_SECRET=<secret>`: Your Supabase project's JWT secret. Needed for tools like `verify_jwt_secret`.
|
|
120
|
+
* `--tools-config <path>`: Path to a JSON file specifying which tools to enable (whitelist). If omitted, all tools defined in the server are enabled. The file should have the format `{"enabledTools": ["tool_name_1", "tool_name_2"]}`.
|
|
121
|
+
|
|
122
|
+
### Important Notes:
|
|
123
|
+
|
|
124
|
+
* **`execute_sql` Helper Function:** Many tools rely on a `public.execute_sql` function within your Supabase database for secure and efficient SQL execution via RPC. The server attempts to check for this function on startup. If it's missing *and* a `service-key` (or `SUPABASE_SERVICE_ROLE_KEY`) *and* `db-url` (or `DATABASE_URL`) are provided, it will attempt to create the function and grant necessary permissions. If creation fails or keys aren't provided, tools relying solely on RPC may fail.
|
|
125
|
+
* **Direct Database Access:** Tools interacting directly with privileged schemas (`auth`, `storage`) or system catalogs (`pg_catalog`) generally require the `DATABASE_URL` to be configured for a direct `pg` connection.
|
|
126
|
+
|
|
127
|
+
## Using with AI Assistant Tools
|
|
128
|
+
|
|
129
|
+
### Cursor
|
|
130
|
+
|
|
131
|
+
1. Create or open the file `.cursor/mcp.json` in your project root.
|
|
132
|
+
2. Add the following configuration:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"mcpServers": {
|
|
137
|
+
"selfhosted-supabase": {
|
|
138
|
+
"command": "npx",
|
|
139
|
+
"args": [
|
|
140
|
+
"@lemontreen/rds-supabase-mcp-server",
|
|
141
|
+
"--url",
|
|
142
|
+
"<your-supabase-url>", // e.g., "http://localhost:8000"
|
|
143
|
+
"--anon-key",
|
|
144
|
+
"<your-anon-key>",
|
|
145
|
+
// Optional - Add these if needed by the tools you use
|
|
146
|
+
"--service-key",
|
|
147
|
+
"<your-service-key>",
|
|
148
|
+
"--db-url",
|
|
149
|
+
"<your-db-url>", // e.g., "postgresql://postgres:password@host:port/postgres"
|
|
150
|
+
"--jwt-secret",
|
|
151
|
+
"<your-jwt-secret>",
|
|
152
|
+
// Optional - Whitelist specific tools
|
|
153
|
+
"--tools-config",
|
|
154
|
+
"<path-to-tools-config.json>"
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Claude for Desktop
|
|
162
|
+
|
|
163
|
+
For Claude Desktop, you can add the following to your configuration:
|
|
164
|
+
|
|
165
|
+
1. Open Claude Desktop Settings
|
|
166
|
+
2. Go to "Developer" and enable "Custom MCP Servers"
|
|
167
|
+
3. Add a new server with the following configuration:
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"name": "Self-Hosted Supabase",
|
|
172
|
+
"command": "npx",
|
|
173
|
+
"args": [
|
|
174
|
+
"@lemontreen/rds-supabase-mcp-server",
|
|
175
|
+
"--url",
|
|
176
|
+
"http://localhost:8000",
|
|
177
|
+
"--anon-key",
|
|
178
|
+
"YOUR_ANON_KEY_HERE"
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Other MCP-Compatible Tools
|
|
184
|
+
|
|
185
|
+
Most MCP-compatible tools follow similar configuration patterns. The general format is:
|
|
186
|
+
- Command: `npx`
|
|
187
|
+
- Arguments: `[@lemontreen/rds-supabase-mcp-server, --url, YOUR_URL, --anon-key, YOUR_ANON_KEY, ...]`
|
|
188
|
+
|
|
189
|
+
## Development
|
|
190
|
+
|
|
191
|
+
To develop and contribute to this project:
|
|
192
|
+
|
|
193
|
+
1. Clone the repository
|
|
194
|
+
2. Run `npm install`
|
|
195
|
+
3. Make your changes
|
|
196
|
+
4. Run `npm run build` to compile
|
|
197
|
+
5. Test with `node dist/index.js` or directly with an MCP client
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
202
|
+
|
|
203
|
+
Originally developed by [HenkDz](https://github.com/HenkDz), now maintained by lemontreen.
|