feat: add schema comments and materialized view support#160
Open
stephanhaeuslschmid wants to merge 3 commits into
Open
feat: add schema comments and materialized view support#160stephanhaeuslschmid wants to merge 3 commits into
stephanhaeuslschmid wants to merge 3 commits into
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
list_objectsandget_object_detailsnow include PostgreSQLCOMMENT ONmetadata viaobj_description()andcol_description()frompg_catalogobject_type='materialized_view'for both tools, queryingpg_class(since materialized views are not ininformation_schema)Motivation
LLMs using this MCP server to explore databases cannot currently see schema documentation stored as
COMMENT ON TABLE/VIEW/COLUMNstatements — 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.tablesdoes not include them.Changes
list_objects:obj_description()ascommentfieldobject_type='materialized_view'queriespg_class WHERE relkind = 'm'with commentsget_object_details:col_description()ascommentfieldbasicsection viaobj_description()pg_attribute(notinformation_schema.columns)Example
These comments now appear in
list_objectsandget_object_detailsresponses, giving LLMs the context they need to write correct queries.Closes #71