CloudNativePG MCP Server
Enables management of PostgreSQL clusters through the CloudNativePG operator, providing tools for cluster creation, scaling, status monitoring, and health checking within Kubernetes environments
Manages PostgreSQL database clusters using CloudNativePG operator, offering high-level workflow tools for cluster lifecycle management, scaling operations, and monitoring cluster health and status
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., "@CloudNativePG MCP Serverlist all PostgreSQL clusters in production namespace"
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.
CloudNativePG MCP Server
An MCP server for managing PostgreSQL clusters through the CloudNativePG operator.
This version uses the MCP Base scaffold for its server layout, authentication,
container build, Helm chart, prompt registry, and test harness. The previous
manual implementation is retained under deprecated-v1/ for reference.
Tool Surface
The server exposes the CloudNativePG tools from the v1 implementation:
list_postgres_clustersget_cluster_statuscreate_postgres_clusterscale_postgres_clusterresize_postgres_clusterget_cluster_resize_statuspromote_cluster_instancedelete_cluster_instancedelete_postgres_clusterlist_postgres_rolesget_postgres_role_statuscreate_postgres_roleupdate_postgres_roledelete_postgres_rolelist_postgres_databasesget_postgres_database_statuscreate_postgres_databasedelete_postgres_database
Storage resize
resize_postgres_cluster changes .spec.storage.size. Growing is applied
directly and CloudNativePG expands the volumes in place. Shrinking cannot be
applied to an existing volume at all, so the tool only starts a migration and
returns immediately — replication can take hours, so no tool call blocks on it.
Starting a shrink (requires confirm_shrink=True) performs three requests: set
cnpg.io/validation: disabled, patch the smaller .spec.storage.size together
with an increased .spec.instances in a single request so the added instance is
created at the new size, then remove the annotation. Validation is restored even
if the patch fails; restore_validation_only=True recovers the annotation if a
run is interrupted.
The rest of the workflow is driven by separate tools, so you decide when each step happens:
get_cluster_resize_status— per-instance volume sizes (requested vs. actual), which instances still hold the previous size, replication health, and the recommended next action.promote_cluster_instance— switchover to the new, smaller instance by setting.status.targetPrimary. Refuses instances the operator does not report as healthy unlessforce=True.delete_cluster_instance— deletes one instance's PVCs and Pod, leaving.spec.instancesalone so the operator rebuilds it from the primary at the current size. Refuses to delete the current primary. Repeat for each instance still on the old size, one at a time.scale_postgres_cluster— return to your original instance count.
Growing needs a storage class with working volume expansion. If
get_cluster_resize_status keeps showing requested / actual sizes that differ,
the provisioner may advertise allowVolumeExpansion without running a resize
controller; the status output points at the PVC events that confirm this.
Roles are managed through CloudNativePG's first-class DatabaseRole CRD rather
than the deprecated Cluster .spec.managed.roles field. create_postgres_role
creates a DatabaseRole named <cluster>-<role> and, unless
disable_password is set, generates a password Secret referenced by the CRD.
Beyond the standard role flags (login, superuser, inherit, createdb,
createrole, replication, bypassrls) it exposes the CRD's in_roles,
connection_limit, valid_until, comment, client_certificate, and
reclaim_policy. update_postgres_role patches the CRD spec and can rotate the
password Secret; delete_postgres_role deletes the CRD, honoring its reclaim
policy, and accepts drop_role=True to force the role to be dropped from
PostgreSQL. get_postgres_role_status reports the CRD's current spec values and
operator reconciliation status. list_postgres_roles lists DatabaseRole CRDs
for a cluster and separately reports any legacy .spec.managed.roles entries
still present on the Cluster.
create_postgres_database supports CloudNativePG Database CRD create-time
locale options, including encoding, locale, locale_provider,
locale_collate, locale_ctype, icu_locale, icu_rules,
builtin_locale, and collation_version.
get_postgres_database_status reports the current Database CRD spec values for
those options along with the operator reconciliation status.
create_postgres_cluster accepts container_image to set the CloudNativePG
spec.imageName directly; when omitted it continues to derive the image from
postgres_version. It also exposes pod scheduling and storage placement
controls: storage_class (spec.storage.storageClass), node_selector
(spec.affinity.nodeSelector), and tolerations (spec.affinity.tolerations).
Together these enable node-local storage: pin instances with node_selector
(e.g. {"kubernetes.io/hostname": "worker-1"} for a specific node, or a label
like {"disktype": "nvme"} for a pool), select a node-local storage_class,
and supply tolerations so pods are admitted onto dedicated (tainted) storage
nodes. image_pull_policy maps to spec.imagePullPolicy.
It also includes MCP Base scaffold admin tools for prompt management:
admin_reload_promptsadmin_get_prompt_manifest
Related MCP server: PostgreSQL MCP Server
Layout
src/cnpg_mcp_server.py: production FastMCP HTTP entrypointsrc/cnpg_mcp_test_server.py: no-auth/OIDC test entrypointsrc/cnpg_mcp_tools.py: CloudNativePG tool implementations and registrationsrc/mcp_context.py: MCP context wrapper with user identity extractionsrc/auth_*.py: MCP Base scaffold authentication supportchart/: Helm deployment assetstest/: MCP plugin test harnessSCAFFOLD_INVENTORY.md: MCP Base scaffold artifact hashes
Development
Create an environment and install dependencies:
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt -r test/requirements.txtRun the scaffold registration smoke test:
python bin/smoke_test.pyRun the local no-auth MCP test suite:
python test/run-local-tests.pyRun the CloudNativePG Kubernetes integration tests adapted from
deprecated-v1/test/plugins:
python test/run-local-tests.py --include-integration
# or
make test-integrationThese tests create, scale, update, and delete real CloudNativePG resources. Useful optional settings:
CNPG_MCP_TEST_NAMESPACE: namespace for test resourcesCNPG_MCP_TEST_CLUSTER_PREFIX: generated cluster name prefixCNPG_MCP_TEST_STORAGE_SIZE: per-instance storage size, default1GiCNPG_MCP_TEST_CREATE_WAIT_SECONDS: cluster readiness timeout, default300CNPG_MCP_TEST_SCALE_WAIT_SECONDS: scale readiness timeout, default300
Running Locally
The scaffold entrypoint uses HTTP transport:
python src/cnpg_mcp_server.py --host 0.0.0.0 --port 4200The test server can be run without authentication:
python src/cnpg_mcp_test_server.py --host 127.0.0.1 --port 4201 --no-authKubernetes Access
The tools use the Kubernetes Python client. They load configuration in this order:
In-cluster service account configuration
Local kubeconfig from
~/.kube/configorKUBECONFIG
Most tools accept an optional namespace. When omitted, the current Kubernetes
context namespace is used, falling back to default.
For in-cluster Helm deployments, the server uses the deployment service account.
By default the chart grants that service account CNPG and secret permissions
only in the Helm release namespace. To manage CNPG resources in another
namespace, pass the tool's namespace argument and grant the service account
access there:
rbac:
targetNamespaces:
- application-databasesFor a shared MCP deployment that must operate in arbitrary namespaces, opt in to cluster-wide RBAC:
rbac:
clusterWide: trueCluster-wide mode grants secret access across namespaces, so prefer explicit
targetNamespaces when the target set is known.
Deployment
The MCP Base scaffold includes Docker and Helm assets:
make build
make push
make helm-installUse python bin/configure-make.py to generate make.env for image and
namespace settings before using the deployment targets.
This server cannot be installed
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
- Alicense-qualityAmaintenanceEnables secure, AI-driven PostgreSQL database administration, observability, and querying with support for extensions like PostGIS and pgvector, connection pooling, and advanced tool filtering.5712MIT
- Alicense-qualityDmaintenanceEnables LLMs to interact deeply with PostgreSQL databases—query data, manage schema, analyze performance, and administer the database.2254MIT
- Flicense-qualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.91
- Alicense-qualityBmaintenanceEnables AI agents to manage, monitor, and query CockroachDB using natural language, supporting cluster monitoring, database operations, table management, and query execution.MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
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/waTeim/cnpg-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server