Skip to content

Commit 79290ab

Browse files
feat: Add total_rows and column_count to list_tables output (#32)
1 parent 1a9aaa4 commit 79290ab

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mcp_clickhouse/mcp_server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def list_databases():
4646

4747
@mcp.tool()
4848
def list_tables(database: str, like: str = None):
49-
"""List available ClickHouse tables in a database"""
49+
"""List available ClickHouse tables in a database, including schema, comment,
50+
row count, and column count."""
5051
logger.info(f"Listing tables in database '{database}'")
5152
client = create_clickhouse_client()
5253
query = f"SHOW TABLES FROM {quote_identifier(database)}"
@@ -87,6 +88,12 @@ def get_table_info(table):
8788
column_dict['comment'] = None
8889
columns.append(column_dict)
8990

91+
# Get row count and column count from the table
92+
row_count_query = f"SELECT count() FROM {quote_identifier(database)}.{quote_identifier(table)}"
93+
row_count_result = client.query(row_count_query)
94+
row_count = row_count_result.result_rows[0][0] if row_count_result.result_rows else 0
95+
column_count = len(columns)
96+
9097
create_table_query = f"SHOW CREATE TABLE {database}.`{table}`"
9198
create_table_result = client.command(create_table_query)
9299

@@ -96,6 +103,8 @@ def get_table_info(table):
96103
"comment": table_comments.get(table),
97104
"columns": columns,
98105
"create_table_query": create_table_result,
106+
"row_count": row_count,
107+
"column_count": column_count,
99108
}
100109

101110
tables = []

0 commit comments

Comments
 (0)