Skip to content

feat: add generate_schema_docs tool for database documentation#278

Open
hasithasandunlakshan wants to merge 2 commits into
supabase-community:mainfrom
hasithasandunlakshan:feat/db-documentation-generator
Open

feat: add generate_schema_docs tool for database documentation#278
hasithasandunlakshan wants to merge 2 commits into
supabase-community:mainfrom
hasithasandunlakshan:feat/db-documentation-generator

Conversation

@hasithasandunlakshan
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature

What is the current behavior?

Currently, to understand the full structure of a database (tables, columns, RLS policies, triggers, and functions), an AI agent or developer must call multiple tools (e.g., list_tables with verbose: true, execute_sql, etc.) or perform multiple manual queries. There is no single, consolidated way to get a documentation-ready overview of the database schema.

Relevant Issue: #277

What is the new behavior?

This PR introduces a new tool, generate_schema_docs, which provides a comprehensive, documentation-ready summary of the database schema in a single call.

Key Features:

  • Consolidated View: Fetches tables, columns, foreign keys, RLS policies, triggers, and user-defined functions in one operation.
  • Dual Output Formats: Supports markdown (optimized for humans/AI context windows), json (optimized for programmatic use), or both.
  • Smart Filtering: Includes options to filter by specific schemas and toggle the inclusion of internal/system functions.
  • RLS Awareness: Highlights whether RLS is enabled and lists policies directly under their respective tables in the markdown output.
  • Architectural Alignment: Correctly integrated into the database feature group and wired into the MCP server runtime.

Additional context

  • Test Coverage: Added comprehensive unit tests in server.test.ts covering various output formats and edge cases. All 172 unit tests are passing.
  • Zod Integration: Fully typed input and output schemas, allowing for type-safe usage via the AI SDK.
  • Performance: Uses parameterized SQL queries and grouping logic to minimize token bloat while maintaining high information density.

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.

1 participant