postgres-mcp-jacob 0.3.0__tar.gz

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 (68) hide show
  1. postgres_mcp_jacob-0.3.0/.claude/settings.local.json +7 -0
  2. postgres_mcp_jacob-0.3.0/.github/workflows/build.yml +50 -0
  3. postgres_mcp_jacob-0.3.0/.github/workflows/docker-build-dockerhub.yml +88 -0
  4. postgres_mcp_jacob-0.3.0/.gitignore +185 -0
  5. postgres_mcp_jacob-0.3.0/.python-version +1 -0
  6. postgres_mcp_jacob-0.3.0/Dockerfile +65 -0
  7. postgres_mcp_jacob-0.3.0/LICENSE +21 -0
  8. postgres_mcp_jacob-0.3.0/PKG-INFO +668 -0
  9. postgres_mcp_jacob-0.3.0/README.md +651 -0
  10. postgres_mcp_jacob-0.3.0/assets/postgres-mcp-pro.png +0 -0
  11. postgres_mcp_jacob-0.3.0/devenv.lock +155 -0
  12. postgres_mcp_jacob-0.3.0/devenv.nix +84 -0
  13. postgres_mcp_jacob-0.3.0/devenv.yaml +22 -0
  14. postgres_mcp_jacob-0.3.0/docker-entrypoint.sh +99 -0
  15. postgres_mcp_jacob-0.3.0/examples/movie-app.md +130 -0
  16. postgres_mcp_jacob-0.3.0/justfile +35 -0
  17. postgres_mcp_jacob-0.3.0/pyproject.toml +109 -0
  18. postgres_mcp_jacob-0.3.0/smithery.yaml +21 -0
  19. postgres_mcp_jacob-0.3.0/src/postgres_mcp/__init__.py +24 -0
  20. postgres_mcp_jacob-0.3.0/src/postgres_mcp/artifacts.py +323 -0
  21. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/__init__.py +4 -0
  22. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/buffer_health_calc.py +62 -0
  23. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/connection_health_calc.py +76 -0
  24. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/constraint_health_calc.py +101 -0
  25. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/database_health.py +98 -0
  26. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/index_health_calc.py +345 -0
  27. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/replication_calc.py +165 -0
  28. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/sequence_health_calc.py +164 -0
  29. postgres_mcp_jacob-0.3.0/src/postgres_mcp/database_health/vacuum_health_calc.py +102 -0
  30. postgres_mcp_jacob-0.3.0/src/postgres_mcp/explain/README.md +26 -0
  31. postgres_mcp_jacob-0.3.0/src/postgres_mcp/explain/__init__.py +7 -0
  32. postgres_mcp_jacob-0.3.0/src/postgres_mcp/explain/explain_plan.py +241 -0
  33. postgres_mcp_jacob-0.3.0/src/postgres_mcp/index/dta_calc.py +837 -0
  34. postgres_mcp_jacob-0.3.0/src/postgres_mcp/index/index_opt_base.py +671 -0
  35. postgres_mcp_jacob-0.3.0/src/postgres_mcp/index/llm_opt.py +384 -0
  36. postgres_mcp_jacob-0.3.0/src/postgres_mcp/index/presentation.py +266 -0
  37. postgres_mcp_jacob-0.3.0/src/postgres_mcp/server.py +767 -0
  38. postgres_mcp_jacob-0.3.0/src/postgres_mcp/sql/__init__.py +31 -0
  39. postgres_mcp_jacob-0.3.0/src/postgres_mcp/sql/bind_params.py +816 -0
  40. postgres_mcp_jacob-0.3.0/src/postgres_mcp/sql/extension_utils.py +246 -0
  41. postgres_mcp_jacob-0.3.0/src/postgres_mcp/sql/index.py +52 -0
  42. postgres_mcp_jacob-0.3.0/src/postgres_mcp/sql/safe_sql.py +1036 -0
  43. postgres_mcp_jacob-0.3.0/src/postgres_mcp/sql/sql_driver.py +272 -0
  44. postgres_mcp_jacob-0.3.0/src/postgres_mcp/top_queries/__init__.py +4 -0
  45. postgres_mcp_jacob-0.3.0/src/postgres_mcp/top_queries/top_queries_calc.py +249 -0
  46. postgres_mcp_jacob-0.3.0/tests/Dockerfile.postgres-hypopg +21 -0
  47. postgres_mcp_jacob-0.3.0/tests/README.md +30 -0
  48. postgres_mcp_jacob-0.3.0/tests/conftest.py +29 -0
  49. postgres_mcp_jacob-0.3.0/tests/integration/dta/test_dta_calc_integration.py +1417 -0
  50. postgres_mcp_jacob-0.3.0/tests/integration/test_top_queries_integration.py +181 -0
  51. postgres_mcp_jacob-0.3.0/tests/unit/database_health/test_database_health_tool.py +182 -0
  52. postgres_mcp_jacob-0.3.0/tests/unit/database_health/test_sequence_health_calc.py +75 -0
  53. postgres_mcp_jacob-0.3.0/tests/unit/explain/test_explain_plan.py +477 -0
  54. postgres_mcp_jacob-0.3.0/tests/unit/explain/test_explain_plan_real_db.py +265 -0
  55. postgres_mcp_jacob-0.3.0/tests/unit/explain/test_server.py +131 -0
  56. postgres_mcp_jacob-0.3.0/tests/unit/explain/test_server_integration.py +160 -0
  57. postgres_mcp_jacob-0.3.0/tests/unit/index/test_dta_calc.py +1289 -0
  58. postgres_mcp_jacob-0.3.0/tests/unit/sql/test_db_conn_pool.py +214 -0
  59. postgres_mcp_jacob-0.3.0/tests/unit/sql/test_obfuscate_password.py +104 -0
  60. postgres_mcp_jacob-0.3.0/tests/unit/sql/test_readonly_enforcement.py +87 -0
  61. postgres_mcp_jacob-0.3.0/tests/unit/sql/test_safe_sql.py +760 -0
  62. postgres_mcp_jacob-0.3.0/tests/unit/sql/test_sql_driver.py +367 -0
  63. postgres_mcp_jacob-0.3.0/tests/unit/test_access_mode.py +114 -0
  64. postgres_mcp_jacob-0.3.0/tests/unit/test_cost_limit.py +168 -0
  65. postgres_mcp_jacob-0.3.0/tests/unit/test_transport.py +129 -0
  66. postgres_mcp_jacob-0.3.0/tests/unit/top_queries/test_top_queries_calc.py +254 -0
  67. postgres_mcp_jacob-0.3.0/tests/utils.py +155 -0
  68. postgres_mcp_jacob-0.3.0/uv.lock +1661 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(uv run pytest *)"
5
+ ]
6
+ }
7
+ }
@@ -0,0 +1,50 @@
1
+ name: Postgres MCP CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths-ignore:
8
+ - "**/README.md"
9
+ pull_request:
10
+ types: [opened, synchronize, reopened]
11
+ paths-ignore:
12
+ - "**/README.md"
13
+
14
+ jobs:
15
+ postgres-mcp-ci:
16
+ runs-on: ubuntu-latest
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Set up Python
23
+ uses: actions/setup-python@v5
24
+ with:
25
+ python-version: "3.12"
26
+
27
+ - name: Start Docker service
28
+ run: sudo service docker start || true
29
+
30
+ - name: Verify Docker is running
31
+ run: docker info
32
+
33
+ - name: Install uv
34
+ uses: astral-sh/setup-uv@v5
35
+ with:
36
+ version: "0.6.9"
37
+
38
+ - name: Build
39
+ run: uv sync
40
+
41
+ - name: Run Lint
42
+ run: |
43
+ uv run ruff format --check .
44
+ uv run ruff check .
45
+
46
+ - name: Run Check
47
+ run: uv run pyright
48
+
49
+ - name: Run Tests
50
+ run: uv run pytest -v --log-cli-level=INFO
@@ -0,0 +1,88 @@
1
+ # act -W ../.github/workflows/docker-build-dockerhub.yml -s DOCKERHUB_USERNAME -s DOCKERHUB_TOKEN -s GITHUB_TOKEN="$(gh auth token)"
2
+ ---
3
+ name: Build and Push Docker Image to DockerHub
4
+
5
+ on:
6
+ push:
7
+ tags:
8
+ - "v*"
9
+ workflow_dispatch:
10
+ inputs:
11
+ version:
12
+ description: "Version to release (without v prefix)"
13
+ required: true
14
+ default: ""
15
+
16
+ jobs:
17
+ prepare:
18
+ runs-on: ubuntu-latest
19
+ outputs:
20
+ version: ${{ steps.set-version.outputs.VERSION }}
21
+ steps:
22
+ - name: Set version from tag
23
+ id: set-version
24
+ run: |
25
+ if [[ "${{ github.event_name }}" == "push" && \
26
+ "${{ github.ref_type }}" == "tag" ]]; then
27
+ VERSION="${GITHUB_REF#refs/tags/v}"
28
+ else
29
+ VERSION="${{ github.event.inputs.version }}"
30
+ fi
31
+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
32
+
33
+ build-and-push:
34
+ needs: prepare
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - name: Checkout
38
+ uses: actions/checkout@v4
39
+
40
+ - name: Set up Docker Buildx
41
+ id: buildx
42
+ uses: docker/setup-buildx-action@v3
43
+ with:
44
+ install: true
45
+ version: latest
46
+ driver-opts: image=moby/buildkit:latest
47
+
48
+ - name: Inspect builder
49
+ run: |
50
+ echo "Available platforms: $(docker buildx inspect --bootstrap | grep 'Platforms:')"
51
+ docker buildx ls
52
+
53
+ - name: Set up QEMU
54
+ uses: docker/setup-qemu-action@v3
55
+ with:
56
+ platforms: arm64,amd64
57
+ image: tonistiigi/binfmt:latest
58
+
59
+ - name: Prepare Docker tags
60
+ id: docker_meta
61
+ uses: docker/metadata-action@v5
62
+ with:
63
+ images: crystaldba/postgres-mcp
64
+ tags: |
65
+ type=raw,value=${{ needs.prepare.outputs.version }}
66
+ type=raw,value=latest
67
+
68
+ - name: Check directory structure
69
+ run: |
70
+ echo "check pwd: $(pwd)"
71
+ echo "check ls: $(ls -lta)"
72
+
73
+ - name: Login to DockerHub
74
+ uses: docker/login-action@v3
75
+ with:
76
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
77
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
78
+
79
+ - name: Build and push
80
+ uses: docker/build-push-action@v5
81
+ with:
82
+ context: .
83
+ file: Dockerfile
84
+ platforms: linux/amd64,linux/arm64
85
+ push: true
86
+ tags: ${{ steps.docker_meta.outputs.tags }}
87
+ cache-from: type=registry,ref=crystaldba/postgres-mcp:buildcache
88
+ cache-to: type=registry,ref=crystaldba/postgres-mcp:buildcache,mode=max
@@ -0,0 +1,185 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+ # Devenv
177
+ .devenv*
178
+ devenv.local.nix
179
+
180
+ # direnv
181
+ .direnv
182
+
183
+ # pre-commit
184
+ .pre-commit-config.yaml
185
+ *.sql
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,65 @@
1
+ # First, build the application in the `/app` directory.
2
+ # See `Dockerfile` for details.
3
+ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
4
+ ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
5
+
6
+ # Disable Python downloads, because we want to use the system interpreter
7
+ # across both images. If using a managed Python version, it needs to be
8
+ # copied from the build image into the final image; see `standalone.Dockerfile`
9
+ # for an example.
10
+ ENV UV_PYTHON_DOWNLOADS=0
11
+
12
+ WORKDIR /app
13
+ RUN apt-get update \
14
+ && apt-get install -y libpq-dev gcc \
15
+ && rm -rf /var/lib/apt/lists/*
16
+ RUN --mount=type=cache,target=/root/.cache/uv \
17
+ --mount=type=bind,source=uv.lock,target=uv.lock \
18
+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
19
+ uv sync --frozen --no-install-project --no-dev
20
+ ADD . /app
21
+ RUN --mount=type=cache,target=/root/.cache/uv \
22
+ uv sync --frozen --no-dev
23
+
24
+
25
+ FROM python:3.12-slim-bookworm
26
+ # It is important to use the image that matches the builder, as the path to the
27
+ # Python executable must be the same, e.g., using `python:3.11-slim-bookworm`
28
+ # will fail.
29
+
30
+ RUN groupadd -r app && useradd -r -g app app
31
+
32
+ COPY --from=builder --chown=app:app /app /app
33
+
34
+ ENV PATH="/app/.venv/bin:$PATH"
35
+
36
+ ARG TARGETPLATFORM
37
+ ARG BUILDPLATFORM
38
+ LABEL org.opencontainers.image.description="Postgres MCP Agent - Multi-architecture container (${TARGETPLATFORM})"
39
+ LABEL org.opencontainers.image.source="https://github.com/crystaldba/postgres-mcp"
40
+ LABEL org.opencontainers.image.licenses="Apache-2.0"
41
+ LABEL org.opencontainers.image.vendor="Crystal DBA"
42
+ LABEL org.opencontainers.image.url="https://www.crystaldba.ai"
43
+
44
+ # Install runtime system dependencies
45
+ RUN apt-get update && apt-get install -y \
46
+ libpq-dev \
47
+ iputils-ping \
48
+ dnsutils \
49
+ net-tools \
50
+ && rm -rf /var/lib/apt/lists/*
51
+
52
+ COPY docker-entrypoint.sh /app/
53
+ RUN chmod +x /app/docker-entrypoint.sh
54
+
55
+ USER app
56
+
57
+ # Expose the SSE port
58
+ EXPOSE 8000
59
+
60
+ # Run the postgres-mcp server
61
+ # Users can pass a database URI or individual connection arguments:
62
+ # docker run -it --rm postgres-mcp postgres://user:pass@host:port/dbname
63
+ # docker run -it --rm postgres-mcp -h myhost -p 5432 -U myuser -d mydb
64
+ ENTRYPOINT ["/app/docker-entrypoint.sh", "postgres-mcp"]
65
+ CMD []
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Crystal Corp.
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.