Kenning PG MCP
Provides tools for interacting with a PostgreSQL database, including listing schemas and objects, describing table structures, executing read-only queries, explaining query plans, listing extensions, and (in unrestricted mode) executing DML statements.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Kenning PG MCPshow me the schema of the orders table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Kenning PG MCP
A PostgreSQL Model Context Protocol server built on two convictions:
Dependencies are pinned exactly. Every dependency is resolved once, recorded in a committed lockfile, and upgraded only as a deliberate, reviewed act. The published package carries
==pins; the Docker image is built withuv sync --frozen. Nothing resolves at launch time.Read-only means the database says no — not a regex. Access control is transaction- and role-based. The server never inspects SQL text to decide whether a statement is "safe," because that model is unwinnable: a data-modifying CTE, a
VOLATILEfunction that writes, orCOPY ... TO PROGRAMall pass keyword filters. PostgreSQL itself is the enforcement.
Built on the MCP Python SDK v2 (2026-07-28 stateless protocol revision),
psycopg 3, and pydantic-settings. Serves stdio and streamable HTTP from
one set of handlers.
The security model
Four layers, none of which parse SQL:
Read-only transactions. Every read path runs inside
BEGIN ... READ ONLY. PostgreSQL rejects any write attempt with SQLSTATE25006— including data-modifying CTEs,SELECT ... FOR UPDATE, and volatile functions that write.One statement per call, enforced by the server. Every user statement is executed through the extended query protocol, where PostgreSQL rejects multi-command strings outright. Statement stacking dies in the database, not in a parser.
A purpose-built role. Connect as a minimal role (SQL below). This is what blocks
COPY ... TO PROGRAM,pg_read_file(),lo_export(), andpg_terminate_backend()— capabilities that begin withSELECTorCOPYand would sail through any keyword guard. Privilege, not pattern matching.Timeouts on every session.
statement_timeoutandidle_in_transaction_session_timeoutare set at connection time, so a badly planned query cannot pin a connection indefinitely.
On startup (in read-only mode), the server probes that a write inside a
read-only transaction really fails with 25006 — and exits non-zero if it
doesn't, rather than silently serving a read-only server that isn't. An
adversarial test suite attempts every bypass listed above against a real
PostgreSQL; every case must fail at the database.
Write access is never inferred. In the default restricted mode the write
tool is not merely refused — it is not registered, so it never appears in
tools/list. Setting PG_MCP_ACCESS_MODE=unrestricted registers a single
DML tool; read tools still run read-only transactions.
The role
CREATE ROLE mcp_ro LOGIN PASSWORD '...';
GRANT CONNECT ON DATABASE mydb TO mcp_ro;
GRANT USAGE ON SCHEMA public TO mcp_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_ro;
ALTER ROLE mcp_ro SET default_transaction_read_only = on;
ALTER ROLE mcp_ro SET statement_timeout = '30s';
ALTER ROLE mcp_ro SET idle_in_transaction_session_timeout = '60s';For read-write deployments, the equivalent role carries INSERT, UPDATE,
DELETE and nothing more. DDL is an operator decision, not a server feature.
Related MCP server: PostgreSQL Multi-Schema MCP Server
Install
The server is a deployable tool, not a library — install it isolated, where exact pins are a feature:
uv tool install kenning-pg-mcp # or: pipx install kenning-pg-mcpOr use the Docker image (the primary distribution artifact — resolution happens at build time, never at launch):
docker build -t kenning-pg-mcp:0.1.0 .Do not run this server via uvx. uvx re-resolves against PyPI on every
invocation, which is the exact failure mode this project exists to eliminate.
Install once, pin the version, upgrade deliberately.
Configuration
Setting | Env var | Default |
Connection URI (required) |
| — |
Access mode |
|
|
Transport |
|
|
HTTP bind host / port |
|
|
Max rows / response bytes |
|
|
Statement timeout |
|
|
Pool min / max |
|
|
Schema allowlist (comma-sep) |
| all non-system |
Log level |
|
|
Flags --access-mode, --transport, --host, --port override the
environment. The effective configuration is logged at startup with the
connection password redacted.
Tools
Tool | Purpose |
| Schemas, honoring the allowlist. |
| Tables, views, matviews, sequences in a schema. |
| Columns, PK, FKs both directions, indexes, constraints, comments, approximate row count. |
| One read statement in a read-only transaction; capped results with an explicit truncation notice (no |
|
|
| Installed and available extensions. |
| Version, role, database, access mode, key settings. |
| Single DML statement — registered only in |
Results serialize honestly: numeric → string (never float), timestamps →
ISO 8601 with timezone, bytea → base64 with a length note, json/jsonb →
nested structures, NULL → null.
Claude Desktop
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "DATABASE_URI", "kenning-pg-mcp:0.1.0"],
"env": {
"DATABASE_URI": "postgresql://mcp_ro:PASSWORD@host.docker.internal:5432/mydb"
}
}
}
}Or with a tool install:
{
"mcpServers": {
"postgres": {
"command": "/absolute/path/to/kenning-pg-mcp",
"env": {
"DATABASE_URI": "postgresql://mcp_ro:PASSWORD@localhost:5432/mydb"
}
}
}
}HTTP mode
PG_MCP_TRANSPORT=http kenning-pg-mcpClients connect to http://127.0.0.1:8000/mcp. Binding beyond loopback
requires PG_MCP_ALLOW_REMOTE=true, and there is no built-in
authentication — put the server behind a reverse proxy that authenticates,
and set PG_MCP_ALLOWED_HOSTS / PG_MCP_ALLOWED_ORIGINS to match your
deployment.
Development
uv sync --frozen
make check # lint + type-check + full test suiteThe test suite has three layers: unit (no database), integration against a real PostgreSQL via testcontainers, and an adversarial layer that attempts every write-bypass in the threat model as a low-privilege role — each case must fail at the database. Docker is required for the latter two.
License
Licensed under the Hippocratic License 3.0 with the Mass Surveillance module — an ethical-source license. This project is source-available, not OSI open source. See LICENSE.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- -license-qualityAmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.Last updated126,03689,188MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases with enhanced multi-schema support, allowing LLMs to inspect database schemas across multiple namespaces and execute read-only queries while maintaining schema isolation.Last updated1233MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.Last updated126,036MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server that provides AI assistants with secure, read-only access to PostgreSQL databases while offering comprehensive tools for schema exploration, query validation, and performance optimization.Last updatedMIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
MCP server for managing Prisma Postgres.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kenningai/kenning-pg-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server