Skip to content

Commit 5ac2dc1

Browse files
committed
bump version to 0.2.2, increase default query timeout to 300s and add DATABEND_QUERY_TIMEOUT config
1 parent bf453b7 commit 5ac2dc1

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Add to your MCP client configuration (e.g., Claude Desktop, Windsurf):
113113
- `DATABEND_DSN`: Databend connection string
114114
- `LOCAL_MODE`: Set to `true` to use local Databend
115115
- `SAFE_MODE`: Set to `false` to disable safe mode
116+
- `DATABEND_QUERY_TIMEOUT`: Query execution timeout in seconds (default: `300`)
116117
- `DATABEND_MCP_SERVER_TRANSPORT`: Default to `stdio`, set to `http` or `sse` to enable HTTP/SSE transport
117118
- `DATABEND_MCP_BIND_HOST`: Default to `127.0.0.1`, set to bind host for HTTP/SSE transport
118119
- `DATABEND_MCP_BIND_PORT`: Default to `8001`, set to bind port for HTTP/SSE transport

mcp_databend/env.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DatabendConfig:
2525
DATABEND_DSN: The dsn connect string (defaults to: "databend://default:@127.0.0.1:8000/?sslmode=disable")
2626
SAFE_MODE: Enable safe mode to restrict dangerous SQL operations (defaults to: "true")
2727
LOCAL_MODE: Enable local mode to use in-memory Databend (defaults to: "false")
28+
DATABEND_QUERY_TIMEOUT: Query execution timeout in seconds (defaults to: "300")
2829
"""
2930

3031
def __init__(self):
@@ -93,6 +94,23 @@ def mcp_bind_port(self) -> int:
9394
raise ValueError(f"Invalid port value '{port_str}'. Must be a valid integer.")
9495
raise
9596

97+
@property
98+
def query_timeout(self) -> int:
99+
"""Get the query execution timeout in seconds.
100+
101+
Default: 300
102+
"""
103+
timeout_str = os.getenv("DATABEND_QUERY_TIMEOUT", "300")
104+
try:
105+
timeout = int(timeout_str)
106+
if timeout < 1:
107+
raise ValueError(f"Query timeout must be greater than 0, got {timeout}")
108+
return timeout
109+
except ValueError as e:
110+
if "invalid literal" in str(e):
111+
raise ValueError(f"Invalid query timeout value '{timeout_str}'. Must be a valid integer.")
112+
raise
113+
96114

97115
# Global instance placeholder for the singleton pattern
98116
_CONFIG_INSTANCE = None

mcp_databend/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
# Constants
1616
SERVER_NAME = "mcp-databend"
17-
DEFAULT_TIMEOUT = 60 # seconds
1817

1918
# Configure logging
2019
logging.basicConfig(
@@ -158,9 +157,10 @@ def _execute_sql(sql: str) -> dict:
158157
try:
159158
# Submit query to thread pool
160159
future = QUERY_EXECUTOR.submit(execute_databend_query, sql)
160+
query_timeout = config.query_timeout
161161
try:
162162
# Wait for query to complete with timeout
163-
result = future.result(timeout=DEFAULT_TIMEOUT)
163+
result = future.result(timeout=query_timeout)
164164

165165
if isinstance(result, dict) and "error" in result:
166166
error_msg = f"Query execution failed: {result['error']}"
@@ -174,7 +174,7 @@ def _execute_sql(sql: str) -> dict:
174174
return {"status": "success", "data": result}
175175

176176
except concurrent.futures.TimeoutError:
177-
error_msg = f"Query timed out after {DEFAULT_TIMEOUT} seconds"
177+
error_msg = f"Query timed out after {query_timeout} seconds"
178178
logger.warning(f"{error_msg}: {sql}")
179179
future.cancel()
180180
return {"status": "error", "message": error_msg}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-databend"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "An MCP server for Databend."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)