@yawlabs/postgres-mcp 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -0
  3. package/dist/index.js +35744 -0
  4. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YawLabs
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,104 @@
1
+ # @yawlabs/postgres-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@yawlabs/postgres-mcp)](https://www.npmjs.com/package/@yawlabs/postgres-mcp)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![CI](https://github.com/YawLabs/postgres-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/YawLabs/postgres-mcp/actions/workflows/ci.yml) [![Release](https://github.com/YawLabs/postgres-mcp/actions/workflows/release.yml/badge.svg)](https://github.com/YawLabs/postgres-mcp/actions/workflows/release.yml)
6
+
7
+ **Query a PostgreSQL database from Claude Code, Cursor, and any MCP client.** Read-only by default — writes opt in via a single env var — so an agent can't silently drop your tables.
8
+
9
+ Built and maintained by [Yaw Labs](https://yaw.sh).
10
+
11
+ ## Why this one?
12
+
13
+ The official Anthropic `@modelcontextprotocol/server-postgres` was [deprecated on npm](https://www.npmjs.com/package/@modelcontextprotocol/server-postgres) in early 2026. This one picks up where it left off, with a few extras:
14
+
15
+ - **Read-only by default** — user SQL runs in a `BEGIN READ ONLY` transaction, so postgres itself (not string parsing) blocks writes. Opt in to writes with `ALLOW_WRITES=1`.
16
+ - **Schema introspection built in** — `pg_list_schemas`, `pg_list_tables`, `pg_describe_table` return columns, primary keys, foreign keys, and indexes without you having to remember the `pg_catalog` joins.
17
+ - **`EXPLAIN` as a first-class tool** — text or JSON format, with optional `ANALYZE`. ANALYZE for non-SELECT statements requires `ALLOW_WRITES=1` since it actually runs the query.
18
+ - **Health snapshot** — `pg_health` returns version, db size, connection counts, and the 10 longest-running active queries in one call. Use it as a connection smoke-test and to catch runaway queries.
19
+ - **Instant startup** — ships as a single bundled file with zero runtime dependencies. No multi-minute `node_modules` install on every npx cold start.
20
+ - **Result truncation** — large result sets are capped at `POSTGRES_MAX_ROWS` (default 1000) with a `truncated: true` flag, so a stray `SELECT * FROM events` doesn't blow out the model context.
21
+ - **Parameterized queries** — `pg_query` accepts a `params` array for `$1`, `$2`, etc. No string-interpolated SQL.
22
+
23
+ ## Quick start
24
+
25
+ **1. Create `.mcp.json` in your project root**
26
+
27
+ macOS / Linux / WSL:
28
+
29
+ ```json
30
+ {
31
+ "mcpServers": {
32
+ "postgres": {
33
+ "command": "npx",
34
+ "args": ["-y", "@yawlabs/postgres-mcp"],
35
+ "env": {
36
+ "DATABASE_URL": "postgres://user:password@host:5432/dbname"
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ```
42
+
43
+ Windows:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "postgres": {
49
+ "command": "cmd",
50
+ "args": ["/c", "npx", "-y", "@yawlabs/postgres-mcp"],
51
+ "env": {
52
+ "DATABASE_URL": "postgres://user:password@host:5432/dbname"
53
+ }
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ > **Why the extra step on Windows?** Since Node 20, `child_process.spawn` cannot directly execute `.cmd` files (that's what `npx` is on Windows). Wrapping with `cmd /c` is the standard workaround.
60
+
61
+ **2. Restart and approve**
62
+
63
+ Restart Claude Code (or your MCP client) and approve the postgres MCP server when prompted.
64
+
65
+ **3. (Optional) Enable writes**
66
+
67
+ Read-only is the default. If you want the agent to be able to `INSERT`, `UPDATE`, `DELETE`, or run DDL, add `ALLOW_WRITES=1` to the `env` block:
68
+
69
+ ```json
70
+ "env": {
71
+ "DATABASE_URL": "postgres://...",
72
+ "ALLOW_WRITES": "1"
73
+ }
74
+ ```
75
+
76
+ Prefer scoping this to dev/test databases — for production, leave writes off and use migration tools out-of-band.
77
+
78
+ ## Tools
79
+
80
+ | Tool | Description |
81
+ |------|-------------|
82
+ | `pg_query` | Run a SQL query. Read-only by default; writes require `ALLOW_WRITES=1`. Supports parameterized queries via `params`. |
83
+ | `pg_list_schemas` | List non-system schemas. |
84
+ | `pg_list_tables` | List tables (and optionally views) in a schema with estimated row counts. |
85
+ | `pg_describe_table` | Columns, primary key, foreign keys, and indexes for a table. |
86
+ | `pg_explain` | `EXPLAIN` or `EXPLAIN ANALYZE` for a SQL statement. Text or JSON output. |
87
+ | `pg_health` | Server version, database size, connection count, active queries, table count. |
88
+
89
+ ## Configuration
90
+
91
+ All env vars are read from the MCP server's environment:
92
+
93
+ | Variable | Default | Purpose |
94
+ |----------|---------|---------|
95
+ | `DATABASE_URL` | (required) | PostgreSQL connection string. |
96
+ | `ALLOW_WRITES` | unset | Set to `1` or `true` to allow DML/DDL via `pg_query` and `pg_explain` ANALYZE of writes. |
97
+ | `POSTGRES_STATEMENT_TIMEOUT_MS` | `30000` | Per-statement timeout. |
98
+ | `POSTGRES_MAX_ROWS` | `1000` | Cap on rows returned by `pg_query`. |
99
+
100
+ SSL is handled by the `pg` driver based on the connection string — use `?sslmode=require` (or equivalent) in `DATABASE_URL` for cloud-hosted databases.
101
+
102
+ ## License
103
+
104
+ MIT © 2026 YawLabs