Skip to content

Commit bf453b7

Browse files
committed
add multi sql
1 parent b631fb2 commit bf453b7

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

mcp_databend/server.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ def create_databend_client():
8181
config = get_config()
8282

8383
if config.local_mode:
84+
logger.info("Creating Databend client local")
8485
# Use local in-memory Databend
8586
import databend
86-
8787
return databend.SessionContext()
8888
else:
89+
logger.info("Creating Databend client dsn")
8990
# Use remote Databend server
9091
from databend_driver import BlockingDatabendClient
9192

@@ -184,6 +185,24 @@ def _execute_sql(sql: str) -> dict:
184185
return {"status": "error", "message": error_msg}
185186

186187

188+
def execute_multi_sql(sqls: list[str]) -> list[dict]:
189+
"""
190+
Execute multiple SQL queries against Databend database with MCP safe mode protection.
191+
192+
Safe mode (enabled by default) blocks dangerous operations like DROP, DELETE,
193+
TRUNCATE, ALTER, UPDATE, and REVOKE. Set SAFE_MODE=false to disable.
194+
195+
Args:
196+
sqls: List of SQL query strings to execute
197+
198+
Returns:
199+
List of dictionaries containing either query results or error information
200+
"""
201+
results = []
202+
for sql in sqls:
203+
results.append(execute_sql(sql))
204+
return results
205+
187206
def execute_sql(sql: str) -> dict:
188207
"""
189208
Execute SQL query against Databend database with MCP safe mode protection.
@@ -316,6 +335,7 @@ def create_stage(
316335

317336
# Register all tools
318337
mcp.add_tool(Tool.from_function(execute_sql))
338+
mcp.add_tool(Tool.from_function(execute_multi_sql))
319339
mcp.add_tool(Tool.from_function(show_databases))
320340
mcp.add_tool(Tool.from_function(show_tables))
321341
mcp.add_tool(Tool.from_function(show_functions))

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies = [
2626
"fastmcp>=2.12.3",
2727
"pyarrow>=21.0.0",
2828
"python-dotenv>=1.1.0",
29+
"lmdb>=1.5.1",
2930
]
3031

3132
[project.urls]

uv.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)