From 5e86d49b92de347407e95d3a6753959a36ce7cb4 Mon Sep 17 00:00:00 2001 From: Shital mehta Date: Sun, 2 Nov 2025 16:49:23 +0530 Subject: [PATCH 1/2] fix: correct Python version mismatch in Dockerfile - Changed runtime image from python:3.13-slim-bookworm to python:3.12-slim-bookworm - Matches builder stage Python version (python3.12) - Fixes ModuleNotFoundError when running Docker containers due to venv incompatibility --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 76cf45e..305d003 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-dev -FROM python:3.13-slim-bookworm +FROM python:3.12-slim-bookworm # It is important to use the image that matches the builder, as the path to the # Python executable must be the same, e.g., using `python:3.11-slim-bookworm` # will fail. From 624ccfff76c01f1bae0734e7a1cffc8a4622e262 Mon Sep 17 00:00:00 2001 From: Shital mehta Date: Mon, 3 Nov 2025 08:39:20 +0530 Subject: [PATCH 2/2] fix: resolve get_database_schema resource validation errors - Fixed SQL query in database_resources.py to use pg_class directly instead of ::regclass - This avoids errors when querying views (::regclass only works for tables/materialized views) - Changed to LEFT JOIN with pg_namespace and pg_class for compatibility - Added obj_description, col_description, and shobj_description to SafeSqlDriver allowed functions - These functions are needed for retrieving table/object comments in schema queries - Fixes 'Error validating query' when get_database_schema resource is accessed Resolves query validation errors that prevented the database://schema resource from working correctly. --- src/postgres_mcp/resources/database_resources.py | 5 ++++- src/postgres_mcp/sql/safe_sql.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/postgres_mcp/resources/database_resources.py b/src/postgres_mcp/resources/database_resources.py index cb3ed42..0f957f1 100644 --- a/src/postgres_mcp/resources/database_resources.py +++ b/src/postgres_mcp/resources/database_resources.py @@ -35,13 +35,16 @@ async def get_database_schema() -> str: # pyright: ignore[reportUnusedFunction] sql_driver: Any = await get_sql_driver_func() # Query information_schema for tables + # Use pg_class directly to avoid ::regclass issues with views tables_query = """ SELECT t.table_schema, t.table_name, t.table_type, - obj_description((t.table_schema||'.'||t.table_name)::regclass) as table_comment + obj_description(c.oid, 'pg_class') as table_comment FROM information_schema.tables t + LEFT JOIN pg_namespace n ON n.nspname = t.table_schema + LEFT JOIN pg_class c ON c.relnamespace = n.oid AND c.relname = t.table_name WHERE t.table_schema NOT IN ('pg_catalog', 'information_schema') ORDER BY t.table_schema, t.table_name """ diff --git a/src/postgres_mcp/sql/safe_sql.py b/src/postgres_mcp/sql/safe_sql.py index 2726531..99f47a6 100644 --- a/src/postgres_mcp/sql/safe_sql.py +++ b/src/postgres_mcp/sql/safe_sql.py @@ -306,6 +306,9 @@ class SafeSqlDriver(SqlDriver): "unicode_version", "icu_unicode_version", # Database object information functions + "obj_description", + "col_description", + "shobj_description", "pg_column_size", "pg_column_compression", "pg_column_toast_chunk_id",