@futuretea/postgres-mcp-server 0.0.1 → 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 (2) hide show
  1. package/README.md +143 -0
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # PostgreSQL Read-only MCP Server
2
2
 
3
+ [中文](README.zh.md)
4
+
3
5
  An MCP (Model Context Protocol) server for discovering one PostgreSQL 17+ instance and running a deliberately narrow SELECT subset. It exposes MCP over stdio or HTTP and includes a CLI.
4
6
 
5
7
  ## Quick start
@@ -15,6 +17,97 @@ make build
15
17
 
16
18
  `tools list` and `tools describe` do not read database connection settings. Starting MCP/HTTP or calling a tool validates the connection and verifies the server and role before it reports ready.
17
19
 
20
+ ## Use a release
21
+
22
+ Release `v0.0.1` is available as an npm package and a multi-architecture Docker image. Both release entry points start MCP over stdio by default.
23
+
24
+ ### npm
25
+
26
+ Run the published package with `npx`:
27
+
28
+ ```sh
29
+ export DATABASE_URL='postgres://reader@127.0.0.1:5432/app?sslmode=disable'
30
+ npx -y @futuretea/postgres-mcp-server@0.0.1
31
+ ```
32
+
33
+ For an MCP client configuration, use:
34
+
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "postgres-readonly": {
39
+ "command": "npx",
40
+ "args": ["-y", "@futuretea/postgres-mcp-server@0.0.1"],
41
+ "env": {
42
+ "DATABASE_URL": "postgres://reader@127.0.0.1:5432/app?sslmode=disable"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ The npm command is an MCP entry point, not a wrapper for the server's other CLI subcommands. Pin the package version you intend to run.
50
+
51
+ ### Docker
52
+
53
+ Run the published image directly:
54
+
55
+ ```sh
56
+ export DATABASE_URL='postgres://reader@db.example.internal:5432/app?sslmode=require'
57
+ docker run --rm -i \
58
+ --env DATABASE_URL \
59
+ ghcr.io/futuretea/postgres-mcp-server:v0.0.1
60
+ ```
61
+
62
+ For an MCP client that launches Docker, pass the connection setting through the Docker process:
63
+
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "postgres-readonly": {
68
+ "command": "docker",
69
+ "args": [
70
+ "run",
71
+ "--rm",
72
+ "-i",
73
+ "--env",
74
+ "DATABASE_URL",
75
+ "ghcr.io/futuretea/postgres-mcp-server:v0.0.1"
76
+ ],
77
+ "env": {
78
+ "DATABASE_URL": "postgres://reader@db.example.internal:5432/app?sslmode=require"
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ The database hostname must be reachable from the container. `localhost` inside the container is not the host machine; use a database hostname on the Docker network, or the platform-specific host gateway when appropriate.
86
+
87
+ The Docker examples use `sslmode=require` for a remote database. Set the PostgreSQL TLS mode and certificates required by your deployment.
88
+
89
+ ### HTTP mode
90
+
91
+ Pass MCP flags after the release command to start HTTP instead of stdio. On the host, the default listener is loopback:
92
+
93
+ ```sh
94
+ export DATABASE_URL='postgres://reader@127.0.0.1:5432/app?sslmode=disable'
95
+ npx -y @futuretea/postgres-mcp-server@0.0.1 --port 8080
96
+ ```
97
+
98
+ For Docker, the server must listen on all container interfaces, while the published port can remain loopback-only on the host:
99
+
100
+ ```sh
101
+ export DATABASE_URL='postgres://reader@db.example.internal:5432/app?sslmode=require'
102
+ docker run --rm \
103
+ --env DATABASE_URL \
104
+ --publish 127.0.0.1:8080:8080 \
105
+ ghcr.io/futuretea/postgres-mcp-server:v0.0.1 \
106
+ --port 8080 --listen 0.0.0.0
107
+ ```
108
+
109
+ Use `http://127.0.0.1:8080/mcp` for Streamable HTTP MCP clients. The server also provides SSE at `/sse` with messages at `/message`, and `GET /healthz` for health checks. HTTP has no authentication or TLS; keep it on a trusted network or place it behind infrastructure that provides both.
110
+
18
111
  ## Tools
19
112
 
20
113
  | Tool | Parameters | Purpose |
@@ -35,6 +128,56 @@ Use a bare `DATABASE_URL`, or standard PostgreSQL environment variables such as
35
128
 
36
129
  At startup the server requires PostgreSQL 17 or newer and rejects service roles that are superusers, bypass row-level security, have replication, or belong to server-file, server-program, or backend-signalling roles. Use a dedicated, least-privilege database role.
37
130
 
131
+ If you cannot provision such a role, set `allow_unsafe_database_role: true` (`MCP_ALLOW_UNSAFE_DATABASE_ROLE=true` for the environment) to skip only this role check. The server still wraps every statement in a read-only transaction, but the role-level guarantee is gone: a superuser role can read tables you did not intend to expose, read server files, and run server-side programs that a read-only transaction does not constrain, and a `BYPASSRLS` role sees through row-level security policies. Enable it only against a database you control.
132
+
133
+ ### Create a read-only service role
134
+
135
+ Run the following in `psql` as a database administrator. Replace `app` and `public` with your database and schema. This creates a fresh login role with no inherited privileges; do not reuse an administrator or application-owner role.
136
+
137
+ ```sql
138
+ CREATE ROLE mcp_reader
139
+ LOGIN
140
+ NOSUPERUSER NOCREATEDB NOCREATEROLE
141
+ NOINHERIT NOREPLICATION NOBYPASSRLS;
142
+ \password mcp_reader
143
+
144
+ GRANT CONNECT ON DATABASE app TO mcp_reader;
145
+ \connect app
146
+ GRANT USAGE ON SCHEMA public TO mcp_reader;
147
+ GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_reader;
148
+ ```
149
+
150
+ ### Verify effective schema privileges
151
+
152
+ Before configuring `DATABASE_URL`, verify that `mcp_reader` cannot create objects in the target schema:
153
+
154
+ ```sql
155
+ SELECT has_schema_privilege('mcp_reader', 'public', 'CREATE') AS can_create_objects;
156
+ ```
157
+
158
+ The result must be `false`. A result of `true` means the role is not restricted to read access in that schema. This can occur when an installation upgraded from PostgreSQL 14 or earlier retains a shared `PUBLIC` `CREATE` grant on `public`. Do not revoke a shared `PUBLIC` privilege solely for this server; have the database administrator decide the database-wide schema policy first.
159
+
160
+ The `\password` command prompts without placing the password in shell history. Store the resulting connection secret only in the runtime secret or environment manager, not in the repository. If the role must read tables created in the future and `postgres` creates those tables, run this optional command as `postgres`. Replace `postgres` with the actual object-creator role in other environments:
161
+
162
+ ```sql
163
+ ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public
164
+ GRANT SELECT ON TABLES TO mcp_reader;
165
+ ```
166
+
167
+ Before configuring `DATABASE_URL`, connect as `mcp_reader` and verify that every boolean below is `false`:
168
+
169
+ ```sql
170
+ SELECT current_user, rolsuper, rolbypassrls, rolreplication,
171
+ pg_has_role(current_user, 'pg_read_server_files', 'member') AS read_server_files,
172
+ pg_has_role(current_user, 'pg_write_server_files', 'member') AS write_server_files,
173
+ pg_has_role(current_user, 'pg_execute_server_program', 'member') AS execute_server_program,
174
+ pg_has_role(current_user, 'pg_signal_backend', 'member') AS signal_backend
175
+ FROM pg_roles
176
+ WHERE rolname = current_user;
177
+ ```
178
+
179
+ If any value is `true`, use a new dedicated role rather than removing privileges from a shared administrator or application role.
180
+
38
181
  ## Read-only boundary and deployment risk
39
182
 
40
183
  Each database operation uses a PostgreSQL read-only transaction and pgx's extended execution protocol. `postgres_query` is parsed as exactly one SELECT, rejecting DML, DDL, row locks, SELECT INTO, modifying CTEs, and selected PostgreSQL built-ins with known side effects.
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@futuretea/postgres-mcp-server",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Read-only PostgreSQL Model Context Protocol server",
5
5
  "main": "./bin/index.js",
6
6
  "bin": {
7
7
  "postgres-mcp-server": "bin/index.js"
8
8
  },
9
9
  "optionalDependencies": {
10
- "@futuretea/postgres-mcp-server-darwin-amd64": "0.0.1",
11
- "@futuretea/postgres-mcp-server-darwin-arm64": "0.0.1",
12
- "@futuretea/postgres-mcp-server-linux-amd64": "0.0.1",
13
- "@futuretea/postgres-mcp-server-linux-arm64": "0.0.1",
14
- "@futuretea/postgres-mcp-server-windows-amd64": "0.0.1"
10
+ "@futuretea/postgres-mcp-server-darwin-amd64": "0.1.0",
11
+ "@futuretea/postgres-mcp-server-darwin-arm64": "0.1.0",
12
+ "@futuretea/postgres-mcp-server-linux-amd64": "0.1.0",
13
+ "@futuretea/postgres-mcp-server-linux-arm64": "0.1.0",
14
+ "@futuretea/postgres-mcp-server-windows-amd64": "0.1.0"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",