CloudNativePG MCP服务器
用于通过以下方式管理PostgreSQL集群的MCP服务器 CloudNativePG 操作员。
此版本使用MCP Base脚手架进行服务器布局、身份验证、, 容器构建、Helm图表、提示注册表和测试工具。先前 手动实施保留在 deprecated-v1/ 以供参考。
刀具表面
服务器公开了v1实现中的CloudNativePG工具:
list_postgres_clustersget_cluster_statuscreate_postgres_clusterscale_postgres_clusterdelete_postgres_clusterlist_postgres_rolescreate_postgres_roleupdate_postgres_roledelete_postgres_rolelist_postgres_databasescreate_postgres_databasedelete_postgres_database
它还包括MCP Base脚手架管理工具,用于快速管理:
admin_reload_promptsadmin_get_prompt_manifest
布局
src/cnpg_mcp_server.py:生产FastMCP HTTP入口点src/cnpg_mcp_test_server.py:无身份验证/OIDC测试入口点src/cnpg_mcp_tools.py:CloudNativePG工具实现和注册src/mcp_context.py:具有用户身份提取的MCP上下文包装器src/auth_*.py:MCP Base脚手架身份验证支持chart/:Helm部署资产test/:MCP插件测试线束SCAFFOLD_INVENTORY.md:MCP Base脚手架工件哈希
发展
创建环境并安装依赖项:
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt -r test/requirements.txt进行脚手架登记烟雾测试:
python bin/smoke_test.py运行本地无身份验证MCP测试套件:
python test/run-local-tests.py运行改编自以下内容的CloudNativePG Kubernetes集成测试 deprecated-v1/test/plugins:
python test/run-local-tests.py --include-integration
# or
make test-integration这些测试创建、扩展、更新和删除真实的CloudNativePG资源。 有用的可选设置:
CNPG_MCP_TEST_NAMESPACE:测试资源的命名空间CNPG_MCP_TEST_CLUSTER_PREFIX:生成的群集名称前缀CNPG_MCP_TEST_STORAGE_SIZE:每个实例的存储大小,默认值1GiCNPG_MCP_TEST_CREATE_WAIT_SECONDS:群集就绪超时,默认值300CNPG_MCP_TEST_SCALE_WAIT_SECONDS:标尺就绪超时,默认值300
本地运行
脚手架入口点使用HTTP传输:
python src/cnpg_mcp_server.py --host 0.0.0.0 --port 4200测试服务器可以在没有身份验证的情况下运行:
python src/cnpg_mcp_test_server.py --host 127.0.0.1 --port 4201 --no-authKubernetes访问
这些工具使用Kubernetes Python客户端。他们在此加载配置 订单:
- 群集中服务帐户配置
- 本地kubeconfig来自
~/.kube/config或KUBECONFIG
大多数工具都接受可选 namespace.省略时,当前Kubernetes 使用了上下文命名空间,可以追溯到 default.
对于集群内Helm部署,服务器使用部署服务帐户。 默认情况下,图表授予该服务帐户CNPG和机密权限 仅在Helm release命名空间中。管理另一家公司的CNPG资源 命名空间,传递工具的 namespace 论证并授予服务帐户 访问那里:
rbac:
targetNamespaces:
- application-databases对于必须在任意命名空间中运行的共享MCP部署,请选择加入 集群范围RBAC:
rbac:
clusterWide: true集群范围模式授予跨命名空间的秘密访问权限,因此更喜欢显式 targetNamespaces 当目标集已知时。
部署
MCP Base脚手架包括Docker和Helm资产:
make build
make push
make helm-install使用 python bin/configure-make.py 生成 make.env 对于图像和 使用部署目标之前的命名空间设置。
