@futuretea/postgres-mcp-server 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 futuretea
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,91 @@
1
+ # PostgreSQL Read-only MCP Server
2
+
3
+ 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
+
5
+ ## Quick start
6
+
7
+ Set a connection target for a minimally privileged PostgreSQL role, then build and inspect the catalog:
8
+
9
+ ```sh
10
+ export DATABASE_URL='postgres://reader@127.0.0.1:5432/app?sslmode=disable'
11
+ make build
12
+ ./bin/postgres-mcp-server tools list
13
+ ./bin/postgres-mcp-server mcp
14
+ ```
15
+
16
+ `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
+
18
+ ## Tools
19
+
20
+ | Tool | Parameters | Purpose |
21
+ |---|---|---|
22
+ | `postgres_get_server_info` | none | Return server and current connection identity. |
23
+ | `postgres_list_databases` | none | List visible databases. |
24
+ | `postgres_list_schemas` | none | List visible schemas. |
25
+ | `postgres_list_tables` | `schema` | List tables and views in a schema. |
26
+ | `postgres_describe_table` | `schema`, `table` | Describe table columns. |
27
+ | `postgres_list_indexes` | `schema`, `table` | List indexes for a table. |
28
+ | `postgres_query` | `sql` | Run one strict read-only SELECT query. |
29
+
30
+ Every successful tool response is one JSON text envelope with `schema_version`, `tool`, and `data`. Parameters must be a JSON object with no unknown keys. Empty-parameter tools require `{}`; missing, `null`, array, or scalar arguments are rejected.
31
+
32
+ ## Database connection
33
+
34
+ Use a bare `DATABASE_URL`, or standard PostgreSQL environment variables such as `PGHOST`, `PGPORT`, `PGDATABASE`, `PGUSER`, `PGPASSWORD`, and `PGSSLMODE`. When `DATABASE_URL` is set it takes precedence. Configuration must resolve to one `host:port`; distinct URL or comma-separated `PGHOST` targets are rejected before a connection is created.
35
+
36
+ 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
+
38
+ ## Read-only boundary and deployment risk
39
+
40
+ 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.
41
+
42
+ This is not a complete proof that every user-defined function, extension, FDW, or future PostgreSQL built-in is harmless. Grant only the database access you intend the server to have.
43
+
44
+ HTTP transports have no authentication or TLS layer. The default listener is loopback. If you set `--listen` to a remote address, place the service only on a trusted network or behind infrastructure that provides the required protection. This server intentionally has no query timeout, row limit, response-size limit, or concurrency budget.
45
+
46
+ ## Running MCP and HTTP
47
+
48
+ ```sh
49
+ # stdio MCP
50
+ ./bin/postgres-mcp-server mcp
51
+
52
+ # HTTP MCP on loopback
53
+ ./bin/postgres-mcp-server mcp --port 8080
54
+
55
+ # Explicit remote listener; see the trusted-network requirement above
56
+ ./bin/postgres-mcp-server mcp --port 8080 --listen 0.0.0.0
57
+ ```
58
+
59
+ The HTTP health endpoint is `GET /healthz`. See `config.example.yaml` for transport and tool-filter settings; database connection settings remain in the environment.
60
+
61
+ ## CLI
62
+
63
+ ```sh
64
+ ./bin/postgres-mcp-server tools list --json
65
+ ./bin/postgres-mcp-server tools describe postgres_query --json
66
+ ./bin/postgres-mcp-server tools call postgres_list_schemas --params '{}'
67
+ ./bin/postgres-mcp-server tools call postgres_query --params '{"sql":"SELECT 1"}'
68
+ ./bin/postgres-mcp-server version
69
+ ```
70
+
71
+ ## Container
72
+
73
+ `make docker` first builds the Alpine CGO parser-check target and then builds the runnable image:
74
+
75
+ ```sh
76
+ make docker
77
+ docker run --rm -i --env DATABASE_URL postgres-mcp-server:dev
78
+ ```
79
+
80
+ The image entrypoint is `postgres-mcp-server mcp`.
81
+
82
+ ## Development checks
83
+
84
+ ```sh
85
+ make format
86
+ make lint
87
+ make test
88
+ make test-integration # requires a running Docker daemon; creates a PostgreSQL 17 fixture
89
+ make build
90
+ make docker
91
+ ```
package/bin/index.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require('child_process');
4
+
5
+ const BINARY_MAP = {
6
+ darwin_x64: {name: 'postgres-mcp-server-darwin-amd64', suffix: ''},
7
+ darwin_arm64: {name: 'postgres-mcp-server-darwin-arm64', suffix: ''},
8
+ linux_x64: {name: 'postgres-mcp-server-linux-amd64', suffix: ''},
9
+ linux_arm64: {name: 'postgres-mcp-server-linux-arm64', suffix: ''},
10
+ win32_x64: {name: 'postgres-mcp-server-windows-amd64', suffix: '.exe'},
11
+ };
12
+
13
+ const resolveBinaryPath = () => {
14
+ const binary = BINARY_MAP[`${process.platform}_${process.arch}`];
15
+ if (!binary) {
16
+ throw new Error(`Unsupported platform/architecture: ${process.platform}/${process.arch}`);
17
+ }
18
+
19
+ try {
20
+ return require.resolve(`@futuretea/${binary.name}/bin/postgres-mcp-server${binary.suffix}`);
21
+ } catch {
22
+ throw new Error(`Could not resolve binary path for platform/architecture: ${process.platform}/${process.arch}`);
23
+ }
24
+ };
25
+
26
+ const child = childProcess.spawn(resolveBinaryPath(), ['mcp', ...process.argv.slice(2)], {
27
+ stdio: 'inherit',
28
+ });
29
+
30
+ const handleSignal = (signal) => {
31
+ if (!child.killed) {
32
+ child.kill(signal);
33
+ }
34
+ };
35
+
36
+ ['SIGTERM', 'SIGINT', 'SIGHUP'].forEach((signal) => {
37
+ process.on(signal, () => handleSignal(signal));
38
+ });
39
+
40
+ child.on('close', (code, signal) => {
41
+ if (signal) {
42
+ process.exit(128 + (signal === 'SIGTERM' ? 15 : signal === 'SIGINT' ? 2 : 1));
43
+ }
44
+
45
+ process.exit(code || 0);
46
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@futuretea/postgres-mcp-server",
3
+ "version": "0.0.1",
4
+ "description": "Read-only PostgreSQL Model Context Protocol server",
5
+ "main": "./bin/index.js",
6
+ "bin": {
7
+ "postgres-mcp-server": "bin/index.js"
8
+ },
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"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/futuretea/postgres-mcp-server.git"
19
+ },
20
+ "keywords": [
21
+ "mcp",
22
+ "postgresql",
23
+ "postgres",
24
+ "database",
25
+ "model-context-protocol"
26
+ ],
27
+ "author": {
28
+ "name": "futuretea",
29
+ "url": "https://github.com/futuretea"
30
+ },
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/futuretea/postgres-mcp-server/issues"
34
+ },
35
+ "homepage": "https://github.com/futuretea/postgres-mcp-server#readme"
36
+ }