Skip to content

Commit fa10430

Browse files
feat(query): expand get_tables to return table type and inclide foreign tables and views
1 parent 9265573 commit fa10430

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

supabase_mcp/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ async def get_db_schemas():
3232
return result
3333

3434

35-
@mcp.tool(description="List all tables in a schema with their sizes, row counts, and metadata.")
35+
@mcp.tool(
36+
description="List all tables, foreign tables, and views in a schema with their sizes, row counts, and metadata."
37+
)
3638
async def get_tables(schema_name: str):
37-
"""Get all tables from a schema with size, row count, column count, and index information."""
39+
"""Get all tables, foreign tables, and views from a schema with size, row count, column count, and index information."""
3840
schema_name = validate_schema_name(schema_name)
3941
query = PreBuiltQueries.get_tables_in_schema_query(schema_name)
4042
return supabase.execute_query(query)

supabase_mcp/queries.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ def get_tables_in_schema_query(schema_name: str) -> str:
3232
pg_stat_get_live_tuples(pc.oid) as row_count,
3333
(SELECT COUNT(*) FROM information_schema.columns c WHERE c.table_schema = t.table_schema AND c.table_name = t.table_name) as column_count,
3434
(SELECT COUNT(*) FROM pg_indexes i WHERE i.schemaname = t.table_schema AND i.tablename = t.table_name) as index_count,
35-
pg_total_relation_size(quote_ident(t.table_schema) || '.' || quote_ident(t.table_name)) as size_bytes -- Added for ordering
35+
pg_total_relation_size(quote_ident(t.table_schema) || '.' || quote_ident(t.table_name)) as size_bytes, -- Added for ordering
36+
t.table_type -- Added to distinguish between regular and foreign tables
3637
FROM information_schema.tables t
3738
JOIN pg_class pc
3839
ON pc.relname = t.table_name
3940
AND pc.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '{schema_name}')
4041
WHERE t.table_schema = '{schema_name}'
41-
AND t.table_type = 'BASE TABLE'
42+
AND t.table_type IN ('BASE TABLE', 'FOREIGN TABLE', 'VIEW')
4243
ORDER BY size_bytes DESC;
4344
"""
4445

0 commit comments

Comments
 (0)