Skip to content

feat: add schema comments and materialized view support#160

Open
stephanhaeuslschmid wants to merge 3 commits into
crystaldba:mainfrom
stephanhaeuslschmid:feat/schema-comments-and-matviews
Open

feat: add schema comments and materialized view support#160
stephanhaeuslschmid wants to merge 3 commits into
crystaldba:mainfrom
stephanhaeuslschmid:feat/schema-comments-and-matviews

Conversation

@stephanhaeuslschmid
Copy link
Copy Markdown

Summary

  • Schema comments: list_objects and get_object_details now include PostgreSQL COMMENT ON metadata via obj_description() and col_description() from pg_catalog
  • Materialized views: New object_type='materialized_view' for both tools, querying pg_class (since materialized views are not in information_schema)

Motivation

LLMs using this MCP server to explore databases cannot currently see schema documentation stored as COMMENT ON TABLE/VIEW/COLUMN statements — the standard PostgreSQL mechanism for documenting columns (units, enums, business logic). This makes it much harder for LLMs to correctly interpret data.

Similarly, materialized views (commonly used for analytics/reporting layers) are invisible because information_schema.tables does not include them.

Changes

list_objects:

  • Tables and views now include obj_description() as comment field
  • New object_type='materialized_view' queries pg_class WHERE relkind = 'm' with comments

get_object_details:

  • Column results now include col_description() as comment field
  • Object-level comment added to basic section via obj_description()
  • For materialized views, columns are queried from pg_attribute (not information_schema.columns)

Example

COMMENT ON TABLE raw.orders IS 'Customer orders. One row per order. Currency: EUR.';
COMMENT ON COLUMN raw.orders.amount IS 'Order total in EUR cents. Divide by 100 for EUR.';

These comments now appear in list_objects and get_object_details responses, giving LLMs the context they need to write correct queries.

Closes #71

…ools

Add PostgreSQL COMMENT support to list_objects and get_object_details:
- list_objects: include obj_description() for tables, views, and materialized views
- get_object_details: include col_description() for column comments and
  obj_description() for table/view/materialized view comments

Add materialized view as a new object_type:
- list_objects: query pg_class with relkind='m' for materialized views
- get_object_details: query pg_attribute for columns (since materialized
  views are not in information_schema.columns)

This enables LLMs using the MCP server to discover schema documentation
stored as COMMENT ON TABLE/VIEW/COLUMN statements, which is the standard
PostgreSQL mechanism for schema documentation.

Closes crystaldba#71
These pg_catalog functions are read-only and needed for the schema
comment feature to work in restricted mode.
Add "PostgreSQL" keyword to all tool descriptions so LLM search
can find them. Make get_object_details and list_objects descriptions
explicit about returned data (columns, comments, constraints, indexes).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Addition of Table/Column Comments to metadata tools?

1 participant