schema-navigator-mcp 0.2.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/LICENSE +21 -0
- package/README.md +215 -0
- package/dist/db/pg-adapter.d.ts +17 -0
- package/dist/db/pg-adapter.js +74 -0
- package/dist/db/pg-adapter.js.map +1 -0
- package/dist/db/postgres.d.ts +19 -0
- package/dist/db/postgres.js +34 -0
- package/dist/db/postgres.js.map +1 -0
- package/dist/db/supabase-adapter.d.ts +45 -0
- package/dist/db/supabase-adapter.js +148 -0
- package/dist/db/supabase-adapter.js.map +1 -0
- package/dist/db/types.d.ts +25 -0
- package/dist/db/types.js +2 -0
- package/dist/db/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +129 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/constraints.d.ts +22 -0
- package/dist/tools/constraints.js +80 -0
- package/dist/tools/constraints.js.map +1 -0
- package/dist/tools/functions.d.ts +20 -0
- package/dist/tools/functions.js +118 -0
- package/dist/tools/functions.js.map +1 -0
- package/dist/tools/overview.d.ts +29 -0
- package/dist/tools/overview.js +142 -0
- package/dist/tools/overview.js.map +1 -0
- package/dist/tools/policies.d.ts +29 -0
- package/dist/tools/policies.js +96 -0
- package/dist/tools/policies.js.map +1 -0
- package/dist/tools/relations.d.ts +18 -0
- package/dist/tools/relations.js +72 -0
- package/dist/tools/relations.js.map +1 -0
- package/dist/tools/search.d.ts +13 -0
- package/dist/tools/search.js +77 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/table-profile.d.ts +68 -0
- package/dist/tools/table-profile.js +477 -0
- package/dist/tools/table-profile.js.map +1 -0
- package/dist/utils/check-parser.d.ts +17 -0
- package/dist/utils/check-parser.js +61 -0
- package/dist/utils/check-parser.js.map +1 -0
- package/dist/utils/pg-array.d.ts +6 -0
- package/dist/utils/pg-array.js +42 -0
- package/dist/utils/pg-array.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EcoPanel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# schema-navigator-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/schema-navigator-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org)
|
|
6
|
+
|
|
7
|
+
**MCP server for PostgreSQL schema introspection.** Gives Claude live access to your database structure — columns, types, constraints, foreign keys, RLS policies, functions, and more.
|
|
8
|
+
|
|
9
|
+
Works with any PostgreSQL-compatible database: **Supabase**, **Neon**, **Railway**, **CockroachDB**, **AWS Aurora**, **local Postgres**.
|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
The most common bugs when working with databases:
|
|
14
|
+
|
|
15
|
+
1. **Wrong column names** — `total_price` doesn't exist, it's `total_amount`
|
|
16
|
+
2. **Invalid constraint values** — `'complete'` is not an allowed status
|
|
17
|
+
3. **RLS client mismatch** — browser client blocked by row-level security
|
|
18
|
+
4. **Blind migrations** — dropping a column referenced by 5 foreign keys
|
|
19
|
+
|
|
20
|
+
This server eliminates all four by giving your AI assistant live schema access.
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Option 1: Supabase (no password needed)
|
|
25
|
+
|
|
26
|
+
The easiest setup for Supabase projects. Uses the [Management API](https://supabase.com/docs/reference/api/introduction) — no database password or connection string required.
|
|
27
|
+
|
|
28
|
+
1. Get a Personal Access Token from [supabase.com/dashboard/account/tokens](https://supabase.com/dashboard/account/tokens)
|
|
29
|
+
2. Find your project ref in your dashboard URL: `supabase.com/dashboard/project/<project-ref>`
|
|
30
|
+
|
|
31
|
+
Add to your project's `.mcp.json`:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"db": {
|
|
37
|
+
"command": "npx",
|
|
38
|
+
"args": ["-y", "schema-navigator-mcp@latest"],
|
|
39
|
+
"env": {
|
|
40
|
+
"SUPABASE_ACCESS_TOKEN": "sbp_...",
|
|
41
|
+
"SUPABASE_PROJECT_REF": "your-project-ref"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or if you already have `SUPABASE_URL` or `NEXT_PUBLIC_SUPABASE_URL` set, the project ref is extracted automatically:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"db": {
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["-y", "schema-navigator-mcp@latest"],
|
|
56
|
+
"env": {
|
|
57
|
+
"SUPABASE_ACCESS_TOKEN": "sbp_...",
|
|
58
|
+
"SUPABASE_URL": "${SUPABASE_URL}"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Option 2: Direct connection (any PostgreSQL)
|
|
66
|
+
|
|
67
|
+
Works with any PostgreSQL-compatible database — Supabase, Neon, Railway, CockroachDB, AWS Aurora, local Postgres.
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"mcpServers": {
|
|
72
|
+
"db": {
|
|
73
|
+
"command": "npx",
|
|
74
|
+
"args": ["-y", "schema-navigator-mcp@latest"],
|
|
75
|
+
"env": { "DATABASE_URL": "${DATABASE_URL}" }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Set `DATABASE_URL` in your environment (e.g. `.env.local`) and restart Claude Code.
|
|
82
|
+
|
|
83
|
+
### Priority
|
|
84
|
+
|
|
85
|
+
If both are set, `DATABASE_URL` takes priority (direct connection is faster and has no rate limits).
|
|
86
|
+
|
|
87
|
+
### With the schema-nav Plugin
|
|
88
|
+
|
|
89
|
+
For slash commands (`/db:table`, `/db:find`, etc.) and auto-activated validation skills, install the companion [schema-nav](https://github.com/ivnv00/schema-nav) plugin.
|
|
90
|
+
|
|
91
|
+
## Tools
|
|
92
|
+
|
|
93
|
+
7 read-only tools, each under 200 chars description (~4.9K total context cost):
|
|
94
|
+
|
|
95
|
+
| Tool | What it does |
|
|
96
|
+
|------|-------------|
|
|
97
|
+
| `schema_overview` | Database dashboard — all tables with row counts and sizes, views, enums, extensions, health warnings |
|
|
98
|
+
| `schema_table` | Complete profile of a table/view/matview — columns, types, defaults, constraints, FKs, indexes, RLS, grants |
|
|
99
|
+
| `schema_find` | Cross-schema search across tables, columns, functions, views, policies, enums, comments |
|
|
100
|
+
| `schema_relations` | FK relationship graph — outbound and inbound references with cascade actions |
|
|
101
|
+
| `schema_functions` | Function inspector — arguments, return type, language, volatility, security definer, source code |
|
|
102
|
+
| `schema_constraints` | Value extractor — allowed values from CHECK constraints and ENUM types, merged |
|
|
103
|
+
| `schema_policies` | RLS analyzer — enabled status, policy expressions, role-by-operation access matrix |
|
|
104
|
+
|
|
105
|
+
### Example: `schema_table`
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
schema_table("orders") →
|
|
109
|
+
{
|
|
110
|
+
"object_type": "table",
|
|
111
|
+
"columns": [
|
|
112
|
+
{ "name": "id", "type": "uuid", "nullable": false, "default": "gen_random_uuid()" },
|
|
113
|
+
{ "name": "status", "type": "text", "nullable": false, "comment": "Order lifecycle state" },
|
|
114
|
+
{ "name": "total_amount", "type": "numeric", "nullable": false },
|
|
115
|
+
...
|
|
116
|
+
],
|
|
117
|
+
"constraints": [
|
|
118
|
+
{ "type": "CHECK", "column": "status", "allowed_values": ["pending", "processing", "shipped", ...] }
|
|
119
|
+
],
|
|
120
|
+
"fks_in": [
|
|
121
|
+
{ "from_table": "order_items", "from_column": "order_id", "on_delete": "CASCADE" }
|
|
122
|
+
],
|
|
123
|
+
"rls_enabled": true,
|
|
124
|
+
"row_count": 51200,
|
|
125
|
+
"total_size": "32.1 MB"
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Architecture
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
┌─────────────────────────────────────────────────────────┐
|
|
133
|
+
│ schema-navigator-mcp │
|
|
134
|
+
│ │
|
|
135
|
+
│ ┌─ DATABASE_URL ──► PgAdapter (pg.Pool) │
|
|
136
|
+
│ │ ├── BEGIN TRANSACTION READ ONLY │
|
|
137
|
+
│ │ ├── query (15s timeout) │
|
|
138
|
+
│ │ └── COMMIT │
|
|
139
|
+
│ │ │
|
|
140
|
+
│ └─ SUPABASE_ACCESS_TOKEN ──► SupabaseAdapter │
|
|
141
|
+
│ ├── Management API │
|
|
142
|
+
│ ├── batch N queries → 1 │
|
|
143
|
+
│ └── 30s timeout │
|
|
144
|
+
│ │
|
|
145
|
+
│ 7 tools registered via MCP SDK │
|
|
146
|
+
│ stdio transport (JSON-RPC) │
|
|
147
|
+
└─────────────────────────────────────────────────────────┘
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Direct connection (PgAdapter)
|
|
151
|
+
|
|
152
|
+
- **Read-only transactions** — every query wrapped in `BEGIN TRANSACTION READ ONLY`. Cannot modify data.
|
|
153
|
+
- **Connection pooling** — `pg.Pool` with max 5 connections, 5s connect timeout, 30s idle timeout.
|
|
154
|
+
- **Query timeout** — 15s `statement_timeout` prevents hanging queries.
|
|
155
|
+
- **Graceful shutdown** — SIGINT/SIGTERM handlers close pool connections cleanly.
|
|
156
|
+
|
|
157
|
+
### Supabase Management API (SupabaseAdapter)
|
|
158
|
+
|
|
159
|
+
- **Zero-password** — authenticates via Personal Access Token, no database credentials needed.
|
|
160
|
+
- **Batch queries** — multiple queries batched into a single API call using `json_build_array`, staying within the 10 req/min rate limit.
|
|
161
|
+
- **Parameter inlining** — `$1`, `$2` placeholders safely inlined with SQL escaping (all params are Zod-validated schema/table names).
|
|
162
|
+
- **30s timeout** — per-request timeout with `AbortController`.
|
|
163
|
+
|
|
164
|
+
## Universality
|
|
165
|
+
|
|
166
|
+
The server uses two query layers with automatic detection:
|
|
167
|
+
|
|
168
|
+
**Universal** (`information_schema` — SQL standard):
|
|
169
|
+
- Tables, columns, data types, defaults, nullability
|
|
170
|
+
- Foreign keys, CHECK constraints, UNIQUE constraints
|
|
171
|
+
- Views, routines, triggers
|
|
172
|
+
|
|
173
|
+
**PostgreSQL-specific** (`pg_catalog` — graceful degradation):
|
|
174
|
+
- RLS policies → returns `[]` + note on non-Postgres
|
|
175
|
+
- ENUM types → returns `[]`
|
|
176
|
+
- Function source code → signature-only fallback
|
|
177
|
+
- Table sizes, row estimates → `null`
|
|
178
|
+
- Column comments → `null`
|
|
179
|
+
|
|
180
|
+
Detection runs once at startup via `SELECT version()`.
|
|
181
|
+
|
|
182
|
+
## Programmatic API
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { createSchemaNavigator } from "schema-navigator-mcp";
|
|
186
|
+
|
|
187
|
+
// Direct PostgreSQL connection
|
|
188
|
+
const server = await createSchemaNavigator("postgresql://...");
|
|
189
|
+
|
|
190
|
+
// Supabase Management API
|
|
191
|
+
const server = await createSchemaNavigator({
|
|
192
|
+
accessToken: "sbp_...",
|
|
193
|
+
projectRef: "your-project-ref",
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// server is an McpServer instance — connect your own transport
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Security
|
|
200
|
+
|
|
201
|
+
- **Read-only** — direct connections use read-only transactions; Management API queries are all SELECT statements
|
|
202
|
+
- **No credentials stored** — `DATABASE_URL` / `SUPABASE_ACCESS_TOKEN` from environment only
|
|
203
|
+
- **No data access** — introspects schema metadata, never reads table data
|
|
204
|
+
- **Parameterized queries** — direct connections use native `$1` parameters; Management API inlines with SQL escaping (all inputs are Zod-validated)
|
|
205
|
+
|
|
206
|
+
## Requirements
|
|
207
|
+
|
|
208
|
+
- Node.js >= 18
|
|
209
|
+
- One of:
|
|
210
|
+
- `DATABASE_URL` — any PostgreSQL-compatible connection string
|
|
211
|
+
- `SUPABASE_ACCESS_TOKEN` + `SUPABASE_PROJECT_REF` (or `SUPABASE_URL` / `NEXT_PUBLIC_SUPABASE_URL`)
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QueryAdapter, QueryResult } from "./types.js";
|
|
2
|
+
export declare class PgAdapter implements QueryAdapter {
|
|
3
|
+
private pool;
|
|
4
|
+
private _isPostgres;
|
|
5
|
+
private _version;
|
|
6
|
+
constructor(connectionString: string);
|
|
7
|
+
get isPostgres(): boolean;
|
|
8
|
+
get version(): string | null;
|
|
9
|
+
/** Must be called once after construction, before any tool queries. */
|
|
10
|
+
detectVersion(): Promise<void>;
|
|
11
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
|
|
12
|
+
multiQuery(queries: Array<{
|
|
13
|
+
sql: string;
|
|
14
|
+
params?: unknown[];
|
|
15
|
+
}>): Promise<QueryResult[]>;
|
|
16
|
+
shutdown(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import pg from "pg";
|
|
2
|
+
const { Pool } = pg;
|
|
3
|
+
const QUERY_TIMEOUT_MS = 15000;
|
|
4
|
+
export class PgAdapter {
|
|
5
|
+
pool;
|
|
6
|
+
_isPostgres = false;
|
|
7
|
+
_version = null;
|
|
8
|
+
constructor(connectionString) {
|
|
9
|
+
this.pool = new Pool({
|
|
10
|
+
connectionString,
|
|
11
|
+
max: 5,
|
|
12
|
+
connectionTimeoutMillis: 5000,
|
|
13
|
+
idleTimeoutMillis: 30000,
|
|
14
|
+
statement_timeout: QUERY_TIMEOUT_MS,
|
|
15
|
+
});
|
|
16
|
+
this.pool.on("error", (err) => {
|
|
17
|
+
console.error("Unexpected pool error:", err.message);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
get isPostgres() {
|
|
21
|
+
return this._isPostgres;
|
|
22
|
+
}
|
|
23
|
+
get version() {
|
|
24
|
+
return this._version;
|
|
25
|
+
}
|
|
26
|
+
/** Must be called once after construction, before any tool queries. */
|
|
27
|
+
async detectVersion() {
|
|
28
|
+
const result = await this.pool.query("SELECT version()");
|
|
29
|
+
const version = result.rows[0]?.version;
|
|
30
|
+
this._isPostgres = /postgresql/i.test(version);
|
|
31
|
+
this._version = version;
|
|
32
|
+
}
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
async query(sql, params) {
|
|
35
|
+
const client = await this.pool.connect();
|
|
36
|
+
try {
|
|
37
|
+
await client.query("BEGIN TRANSACTION READ ONLY");
|
|
38
|
+
const result = await client.query(sql, params);
|
|
39
|
+
await client.query("COMMIT");
|
|
40
|
+
return { rows: result.rows, rowCount: result.rowCount ?? 0 };
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
await client.query("ROLLBACK").catch(() => { });
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
client.release();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async multiQuery(queries) {
|
|
51
|
+
const client = await this.pool.connect();
|
|
52
|
+
try {
|
|
53
|
+
await client.query("BEGIN TRANSACTION READ ONLY");
|
|
54
|
+
const results = [];
|
|
55
|
+
for (const q of queries) {
|
|
56
|
+
const r = await client.query(q.sql, q.params);
|
|
57
|
+
results.push({ rows: r.rows, rowCount: r.rowCount ?? 0 });
|
|
58
|
+
}
|
|
59
|
+
await client.query("COMMIT");
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
await client.query("ROLLBACK").catch(() => { });
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
client.release();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async shutdown() {
|
|
71
|
+
await this.pool.end();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=pg-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-adapter.js","sourceRoot":"","sources":["../../src/db/pg-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACpB,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,OAAO,SAAS;IACZ,IAAI,CAAU;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AAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin facade over the active QueryAdapter.
|
|
3
|
+
*
|
|
4
|
+
* Tools import readOnlyQuery / readOnlyMultiQuery / getIsPostgres from here.
|
|
5
|
+
* The actual backend (pg.Pool or Supabase Management API) is set once at
|
|
6
|
+
* startup via setAdapter().
|
|
7
|
+
*/
|
|
8
|
+
import type { QueryAdapter, QueryResult } from "./types.js";
|
|
9
|
+
export declare function setAdapter(a: QueryAdapter): void;
|
|
10
|
+
export declare function getAdapter(): QueryAdapter | null;
|
|
11
|
+
export type { QueryResult };
|
|
12
|
+
export declare function getIsPostgres(): boolean;
|
|
13
|
+
export declare function getPostgresVersion(): string | null;
|
|
14
|
+
export declare function readOnlyQuery<T = any>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
|
|
15
|
+
export declare function readOnlyMultiQuery(queries: Array<{
|
|
16
|
+
sql: string;
|
|
17
|
+
params?: unknown[];
|
|
18
|
+
}>): Promise<QueryResult[]>;
|
|
19
|
+
export declare function shutdownPool(): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
let adapter = null;
|
|
2
|
+
export function setAdapter(a) {
|
|
3
|
+
adapter = a;
|
|
4
|
+
}
|
|
5
|
+
export function getAdapter() {
|
|
6
|
+
return adapter;
|
|
7
|
+
}
|
|
8
|
+
// ── Existing exports preserved for tool compatibility ──
|
|
9
|
+
export function getIsPostgres() {
|
|
10
|
+
if (!adapter)
|
|
11
|
+
throw new Error("Adapter not initialized");
|
|
12
|
+
return adapter.isPostgres;
|
|
13
|
+
}
|
|
14
|
+
export function getPostgresVersion() {
|
|
15
|
+
return adapter?.version ?? null;
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
export async function readOnlyQuery(sql, params) {
|
|
19
|
+
if (!adapter)
|
|
20
|
+
throw new Error("Adapter not initialized");
|
|
21
|
+
return adapter.query(sql, params);
|
|
22
|
+
}
|
|
23
|
+
export async function readOnlyMultiQuery(queries) {
|
|
24
|
+
if (!adapter)
|
|
25
|
+
throw new Error("Adapter not initialized");
|
|
26
|
+
return adapter.multiQuery(queries);
|
|
27
|
+
}
|
|
28
|
+
export async function shutdownPool() {
|
|
29
|
+
if (adapter) {
|
|
30
|
+
await adapter.shutdown();
|
|
31
|
+
adapter = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=postgres.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/db/postgres.ts"],"names":[],"mappings":"AASA,IAAI,OAAO,GAAwB,IAAI,CAAC;AAExC,MAAM,UAAU,UAAU,CAAC,CAAe;IACxC,OAAO,GAAG,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC;AAMD,0DAA0D;AAE1D,MAAM,UAAU,aAAa;IAC3B,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC,UAAU,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;AAClC,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,MAAkB;IAElB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC,KAAK,CAAI,GAAG,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAmD;IAEnD,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { QueryAdapter, QueryResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Extract project ref from a Supabase URL.
|
|
4
|
+
* Handles: https://abc123.supabase.co, https://abc123.supabase.co/rest/v1/...
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractRefFromUrl(url: string): string | null;
|
|
7
|
+
export interface SupabaseAdapterConfig {
|
|
8
|
+
accessToken: string;
|
|
9
|
+
projectRef: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class SupabaseAdapter implements QueryAdapter {
|
|
12
|
+
private accessToken;
|
|
13
|
+
private projectRef;
|
|
14
|
+
readonly isPostgres = true;
|
|
15
|
+
readonly version: string | null;
|
|
16
|
+
constructor(config: SupabaseAdapterConfig);
|
|
17
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
|
|
18
|
+
multiQuery(queries: Array<{
|
|
19
|
+
sql: string;
|
|
20
|
+
params?: unknown[];
|
|
21
|
+
}>): Promise<QueryResult[]>;
|
|
22
|
+
shutdown(): Promise<void>;
|
|
23
|
+
private executeApi;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Inline $1, $2, ... placeholders with SQL-safe literal values.
|
|
27
|
+
*
|
|
28
|
+
* Safe because all parameters are Zod-validated strings (schema/table/function
|
|
29
|
+
* names) or computed integers, and the API is called with read_only: true.
|
|
30
|
+
*/
|
|
31
|
+
export declare function inlineParams(sql: string, params: unknown[]): string;
|
|
32
|
+
/**
|
|
33
|
+
* Escape a value as a PostgreSQL literal.
|
|
34
|
+
*/
|
|
35
|
+
export declare function escapeLiteral(value: unknown): string;
|
|
36
|
+
/**
|
|
37
|
+
* Batch N queries into 1 SQL statement using json_build_array.
|
|
38
|
+
*
|
|
39
|
+
* Each sub-query's result set becomes one element in a JSON array,
|
|
40
|
+
* turning N round-trips into 1 API call.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildBatchQuery(queries: Array<{
|
|
43
|
+
sql: string;
|
|
44
|
+
params?: unknown[];
|
|
45
|
+
}>): string;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract project ref from a Supabase URL.
|
|
3
|
+
* Handles: https://abc123.supabase.co, https://abc123.supabase.co/rest/v1/...
|
|
4
|
+
*/
|
|
5
|
+
export function extractRefFromUrl(url) {
|
|
6
|
+
try {
|
|
7
|
+
const hostname = new URL(url).hostname;
|
|
8
|
+
const match = hostname.match(/^([a-z0-9]+)\.supabase\.co$/);
|
|
9
|
+
return match?.[1] ?? null;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const API_BASE = "https://api.supabase.com";
|
|
16
|
+
const FETCH_TIMEOUT_MS = 30_000;
|
|
17
|
+
export class SupabaseAdapter {
|
|
18
|
+
accessToken;
|
|
19
|
+
projectRef;
|
|
20
|
+
isPostgres = true; // Supabase is always PostgreSQL
|
|
21
|
+
version = "PostgreSQL (Supabase Management API)";
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.accessToken = config.accessToken;
|
|
24
|
+
this.projectRef = config.projectRef;
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
async query(sql, params) {
|
|
28
|
+
const finalSql = params?.length ? inlineParams(sql, params) : sql;
|
|
29
|
+
const rows = await this.executeApi(finalSql);
|
|
30
|
+
return { rows: rows, rowCount: rows.length };
|
|
31
|
+
}
|
|
32
|
+
async multiQuery(queries) {
|
|
33
|
+
if (queries.length === 0)
|
|
34
|
+
return [];
|
|
35
|
+
if (queries.length === 1) {
|
|
36
|
+
return [await this.query(queries[0].sql, queries[0].params)];
|
|
37
|
+
}
|
|
38
|
+
// Batch all queries into a single API call using json_build_array
|
|
39
|
+
const batchSql = buildBatchQuery(queries);
|
|
40
|
+
const batchRows = await this.executeApi(batchSql);
|
|
41
|
+
const resultsArray = batchRows[0]?.results;
|
|
42
|
+
if (!Array.isArray(resultsArray)) {
|
|
43
|
+
throw new Error("Unexpected batch query response format from Supabase Management API");
|
|
44
|
+
}
|
|
45
|
+
return resultsArray.map((rows) => {
|
|
46
|
+
const rowArray = Array.isArray(rows) ? rows : [];
|
|
47
|
+
return {
|
|
48
|
+
rows: rowArray,
|
|
49
|
+
rowCount: rowArray.length,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async shutdown() {
|
|
54
|
+
// No persistent connections to close
|
|
55
|
+
}
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
async executeApi(sql) {
|
|
58
|
+
const url = `${API_BASE}/v1/projects/${this.projectRef}/database/query`;
|
|
59
|
+
const controller = new AbortController();
|
|
60
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch(url, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
67
|
+
},
|
|
68
|
+
// Note: read_only is intentionally omitted. The Management API's
|
|
69
|
+
// read_only mode uses a restricted role that blocks visibility into
|
|
70
|
+
// information_schema views needed for schema introspection
|
|
71
|
+
// (table_constraints, check_constraints, referential_constraints,
|
|
72
|
+
// constraint_column_usage, role_table_grants, triggers).
|
|
73
|
+
// All queries in this tool are hardcoded SELECT statements.
|
|
74
|
+
body: JSON.stringify({ query: sql }),
|
|
75
|
+
signal: controller.signal,
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
const body = await response.text().catch(() => "");
|
|
79
|
+
if (response.status === 401) {
|
|
80
|
+
throw new Error("Supabase Management API: unauthorized. Check that SUPABASE_ACCESS_TOKEN is a valid Personal Access Token.");
|
|
81
|
+
}
|
|
82
|
+
if (response.status === 429) {
|
|
83
|
+
throw new Error("Supabase Management API: rate limit exceeded (10 req/min). Wait a moment and retry.");
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`Supabase Management API error ${response.status}: ${body.slice(0, 500)}`);
|
|
86
|
+
}
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
return (await response.json());
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
92
|
+
throw new Error(`Supabase Management API: request timed out after ${FETCH_TIMEOUT_MS / 1000}s`);
|
|
93
|
+
}
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
clearTimeout(timeout);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ── Parameter inlining (exported for testing) ──
|
|
102
|
+
/**
|
|
103
|
+
* Inline $1, $2, ... placeholders with SQL-safe literal values.
|
|
104
|
+
*
|
|
105
|
+
* Safe because all parameters are Zod-validated strings (schema/table/function
|
|
106
|
+
* names) or computed integers, and the API is called with read_only: true.
|
|
107
|
+
*/
|
|
108
|
+
export function inlineParams(sql, params) {
|
|
109
|
+
return sql.replace(/\$(\d+)/g, (match, indexStr) => {
|
|
110
|
+
const index = parseInt(indexStr, 10) - 1;
|
|
111
|
+
if (index < 0 || index >= params.length)
|
|
112
|
+
return match;
|
|
113
|
+
return escapeLiteral(params[index]);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Escape a value as a PostgreSQL literal.
|
|
118
|
+
*/
|
|
119
|
+
export function escapeLiteral(value) {
|
|
120
|
+
if (value === null || value === undefined)
|
|
121
|
+
return "NULL";
|
|
122
|
+
if (typeof value === "boolean")
|
|
123
|
+
return value ? "TRUE" : "FALSE";
|
|
124
|
+
if (typeof value === "number") {
|
|
125
|
+
if (!Number.isFinite(value))
|
|
126
|
+
throw new Error(`Cannot inline non-finite number: ${value}`);
|
|
127
|
+
return String(value);
|
|
128
|
+
}
|
|
129
|
+
if (typeof value === "string") {
|
|
130
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
131
|
+
}
|
|
132
|
+
throw new Error(`Cannot inline parameter of type ${typeof value}: ${String(value)}`);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Batch N queries into 1 SQL statement using json_build_array.
|
|
136
|
+
*
|
|
137
|
+
* Each sub-query's result set becomes one element in a JSON array,
|
|
138
|
+
* turning N round-trips into 1 API call.
|
|
139
|
+
*/
|
|
140
|
+
export function buildBatchQuery(queries) {
|
|
141
|
+
const subQueries = queries.map((q, i) => {
|
|
142
|
+
const sql = q.params?.length ? inlineParams(q.sql, q.params) : q.sql;
|
|
143
|
+
const cleaned = sql.replace(/;\s*$/, "").trim();
|
|
144
|
+
return `(SELECT COALESCE(json_agg(row_to_json(q${i})), '[]'::json) FROM (${cleaned}) q${i})`;
|
|
145
|
+
});
|
|
146
|
+
return `SELECT json_build_array(\n ${subQueries.join(",\n ")}\n) AS results;`;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=supabase-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase-adapter.js","sourceRoot":"","sources":["../../src/db/supabase-adapter.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;QACvC,MAAM,KA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AC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAChD,OAAO,0CAA0C,CAAC,yBAAyB,OAAO,MAAM,CAAC,GAAG,CAAC;IAC/F,CAAC,CAAC,CAAC;IAEH,OAAO,+BAA+B,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend-agnostic query result.
|
|
3
|
+
* Matches the subset of pg.QueryResult that tools actually use (.rows, .rowCount).
|
|
4
|
+
*
|
|
5
|
+
* Default generic is `any` to match pg.QueryResult behavior — tools rely on
|
|
6
|
+
* implicit any when accessing row properties without explicit typing.
|
|
7
|
+
*/
|
|
8
|
+
export interface QueryResult<T = any> {
|
|
9
|
+
rows: T[];
|
|
10
|
+
rowCount: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Contract that both pg.Pool and Supabase Management API adapters implement.
|
|
14
|
+
* Tools never import this directly — they use the facade exports from postgres.ts.
|
|
15
|
+
*/
|
|
16
|
+
export interface QueryAdapter {
|
|
17
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
|
|
18
|
+
multiQuery(queries: Array<{
|
|
19
|
+
sql: string;
|
|
20
|
+
params?: unknown[];
|
|
21
|
+
}>): Promise<QueryResult[]>;
|
|
22
|
+
readonly isPostgres: boolean;
|
|
23
|
+
readonly version: string | null;
|
|
24
|
+
shutdown(): Promise<void>;
|
|
25
|
+
}
|
package/dist/db/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/db/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED