@@ -10,15 +10,21 @@ def register_schema_tools(mcp: FastMCP):
1010 def show_tables () -> str :
1111 """List all tables in the database."""
1212 rw = setup_risingwave_connection ()
13- result = rw .fetch ("SHOW TABLES" , format = OutputFormat .DATAFRAME )
14- return result
13+ try :
14+ result = rw .fetch ("SHOW TABLES" , format = OutputFormat .DATAFRAME )
15+ return result .to_json ()
16+ except Exception as e :
17+ return f"Error listing tables: { str (e )} "
1518
1619 @mcp .tool
1720 def list_databases () -> str :
1821 """List all databases in the RisingWave cluster."""
1922 rw = setup_risingwave_connection ()
20- result = rw .fetch ("SHOW DATABASES" , format = OutputFormat .DATAFRAME )
21- return result
23+ try :
24+ result = rw .fetch ("SHOW DATABASES" , format = OutputFormat .DATAFRAME )
25+ return result .to_json ()
26+ except Exception as e :
27+ return f"Error listing databases: { str (e )} "
2228
2329 @mcp .tool
2430 def describe_table (table_name : str ) -> str :
@@ -33,8 +39,11 @@ def describe_table(table_name: str) -> str:
3339 """
3440 rw = setup_risingwave_connection ()
3541 query = f"DESCRIBE { table_name } "
36- result = rw .fetch (query , format = OutputFormat .DATAFRAME )
37- return result
42+ try :
43+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
44+ return result .to_json ()
45+ except Exception as e :
46+ return f"Error describing table { table_name } : { str (e )} "
3847
3948 @mcp .tool
4049 def describe_materialized_view (mv_name : str ) -> str :
@@ -49,8 +58,11 @@ def describe_materialized_view(mv_name: str) -> str:
4958 """
5059 rw = setup_risingwave_connection ()
5160 query = f"DESCRIBE { mv_name } "
52- result = rw .fetch (query , format = OutputFormat .DATAFRAME )
53- return result
61+ try :
62+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
63+ return result .to_json ()
64+ except Exception as e :
65+ return f"Error describing materialized view { mv_name } : { str (e )} "
5466
5567 @mcp .tool
5668 def show_create_table (table_name : str ) -> str :
@@ -65,8 +77,11 @@ def show_create_table(table_name: str) -> str:
6577 """
6678 rw = setup_risingwave_connection ()
6779 query = f"SHOW CREATE TABLE { table_name } "
68- result = rw .fetch (query , format = OutputFormat .DATAFRAME )
69- return result
80+ try :
81+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
82+ return result .to_json ()
83+ except Exception as e :
84+ return f"Error showing create table for { table_name } : { str (e )} "
7085
7186 @mcp .tool
7287 def show_create_materialized_view (mv_name : str ) -> str :
@@ -81,8 +96,11 @@ def show_create_materialized_view(mv_name: str) -> str:
8196 """
8297 rw = setup_risingwave_connection ()
8398 query = f"SHOW CREATE MATERIALIZED VIEW { mv_name } "
84- result = rw .fetch (query , format = OutputFormat .DATAFRAME )
85- return result
99+ try :
100+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
101+ return result .to_json ()
102+ except Exception as e :
103+ return f"Error showing create materialized view for { mv_name } : { str (e )} "
86104
87105 @mcp .tool
88106 def check_table_exists (table_name : str , schema_name : str = "public" ) -> str :
@@ -97,8 +115,11 @@ def check_table_exists(table_name: str, schema_name: str = "public") -> str:
97115 Boolean result as string indicating if table exists
98116 """
99117 rw = setup_risingwave_connection ()
100- exists = rw .check_exist (name = table_name , schema_name = schema_name )
101- return f"Table '{ table_name } ' in schema '{ schema_name } ' exists: { exists } "
118+ try :
119+ exists = rw .check_exist (name = table_name , schema_name = schema_name )
120+ return f"Table '{ table_name } ' in schema '{ schema_name } ' exists: { exists } "
121+ except Exception as e :
122+ return f"Error checking if table exists: { str (e )} "
102123
103124 @mcp .tool
104125 def list_schemas () -> str :
@@ -109,9 +130,12 @@ def list_schemas() -> str:
109130 List of schemas as a formatted string
110131 """
111132 rw = setup_risingwave_connection ()
112- result = rw .fetch (
113- "SELECT schema_name FROM information_schema.schemata" , format = OutputFormat .DATAFRAME )
114- return result
133+ try :
134+ result = rw .fetch (
135+ "SELECT schema_name FROM information_schema.schemata" , format = OutputFormat .DATAFRAME )
136+ return result .to_json ()
137+ except Exception as e :
138+ return f"Error listing schemas: { str (e )} "
115139
116140 @mcp .tool
117141 def list_materialized_views () -> str :
@@ -126,8 +150,11 @@ def list_materialized_views() -> str:
126150 """
127151 rw = setup_risingwave_connection ()
128152 query = "SHOW MATERIALIZED VIEWS"
129- result = rw .fetch (query , format = OutputFormat .DATAFRAME )
130- return result
153+ try :
154+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
155+ return result .to_json ()
156+ except Exception as e :
157+ return f"Error listing materialized views: { str (e )} "
131158
132159 @mcp .tool
133160 def get_table_columns (table_name : str , schema_name : str = "public" ) -> str :
@@ -148,8 +175,11 @@ def get_table_columns(table_name: str, schema_name: str = "public") -> str:
148175 WHERE table_name = '{ table_name } ' AND table_schema = '{ schema_name } '
149176 ORDER BY ordinal_position
150177 """
151- result = rw .fetch (query , format = OutputFormat .DATAFRAME )
152- return result
178+ try :
179+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
180+ return result .to_json ()
181+ except Exception as e :
182+ return f"Error getting table columns for { table_name } : { str (e )} "
153183
154184 @mcp .tool
155185 def list_subscriptions (schema_name : str = "public" ) -> str :
@@ -166,7 +196,7 @@ def list_subscriptions(schema_name: str = "public") -> str:
166196 query = f"SHOW SUBSCRIPTIONS FROM { schema_name } "
167197 try :
168198 result = rw .fetch (query , format = OutputFormat .DATAFRAME )
169- return result
199+ return result . to_json ()
170200 except Exception as e :
171201 return f"Error listing subscriptions: { str (e )} "
172202
@@ -190,6 +220,40 @@ def list_table_privileges(table_name: str, schema_name: str = "public") -> str:
190220 """
191221 try :
192222 result = rw .fetch (query , format = OutputFormat .DATAFRAME )
193- return result
223+ return result . to_json ()
194224 except Exception as e :
195225 return f"Error getting table privileges: { str (e )} "
226+
227+ @mcp .tool
228+ def list_sinks () -> str :
229+ """
230+ List all sinks in the RisingWave database.
231+
232+ Returns:
233+ List of sinks as a formatted string
234+ """
235+ rw = setup_risingwave_connection ()
236+ query = "SHOW SINKS"
237+ try :
238+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
239+ return result .to_json ()
240+ except Exception as e :
241+ return f"Error listing sinks: { str (e )} "
242+
243+ @mcp .tool
244+ def show_create_sink (sink_name : str ) -> str :
245+ """
246+ Show the CREATE SINK statement for a specific sink.
247+
248+ Args:
249+ sink_name: Name of the sink
250+ Returns:
251+ CREATE SINK statement
252+ """
253+ rw = setup_risingwave_connection ()
254+ query = f"SHOW CREATE SINK { sink_name } "
255+ try :
256+ result = rw .fetch (query , format = OutputFormat .DATAFRAME )
257+ return result .to_json ()
258+ except Exception as e :
259+ return f"Error showing create sink: { str (e )} "
0 commit comments