Skip to content

Commit 20cb20d

Browse files
committed
add stage tool
1 parent 2f2d7f9 commit 20cb20d

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ An MCP server for Databend database interactions.
66

77
## What You Can Do
88

9+
### Database Operations
910
- **execute_sql** - Execute SQL queries with timeout protection and safe mode security
1011
- **show_databases** - List all databases
1112
- **show_tables** - List tables in a database (with optional filter)
1213
- **describe_table** - Get table schema information
1314

15+
### Stage Management
16+
- **show_stages** - List all available Databend stages
17+
- **list_stage_files** - List files in a specific stage (supports @stage_name format)
18+
- **create_stage** - Create a new stage with connection support
19+
20+
### Connection Management
21+
- **show_connections** - List all available Databend connections
22+
1423
## Security Features
1524

1625
### MCP Safe Mode (Enabled by Default)
@@ -93,11 +102,21 @@ Add to your MCP client configuration (e.g., Claude Desktop, Windsurf):
93102
### Step 4: Start Using
94103

95104
Once configured, you can ask your AI assistant to:
105+
106+
**Database Operations:**
96107
- "Show me all databases"
97-
- "List tables in the sales database"
108+
- "List tables in the sales database"
98109
- "Describe the users table structure"
99110
- "Run this SQL query: SELECT * FROM products LIMIT 10"
100111

112+
**Stage Management:**
113+
- "Show me all stages"
114+
- "List files in @my_stage"
115+
- "Create a stage named my_s3_stage with URL s3://my-bucket using connection my_connection"
116+
117+
**Connection Management:**
118+
- "Show all connections"
119+
101120
## Development
102121

103122
```bash

mcp_databend/server.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,73 @@ def describe_table(table: str, database: Optional[str] = None):
204204
return execute_sql(sql)
205205

206206

207+
@mcp.tool()
208+
def show_stages():
209+
"""List available Databend stages (safe operation, not affected by MCP safe mode)"""
210+
logger.info("Listing all stages")
211+
return _execute_sql("SHOW STAGES")
212+
213+
214+
@mcp.tool()
215+
def list_stage_files(stage_name: str, path: Optional[str] = None):
216+
"""
217+
List files in a Databend stage (safe operation, not affected by MCP safe mode)
218+
Args:
219+
stage_name: The stage name (with @ prefix)
220+
path: Optional path within the stage
221+
222+
Returns:
223+
Dictionary containing either query results or error information
224+
"""
225+
if not stage_name.startswith('@'):
226+
stage_name = f"@{stage_name}"
227+
228+
if path:
229+
stage_path = f"{stage_name}/{path.strip('/')}"
230+
else:
231+
stage_path = stage_name
232+
233+
logger.info(f"Listing files in stage '{stage_path}'")
234+
sql = f"LIST {stage_path}"
235+
return _execute_sql(sql)
236+
237+
238+
@mcp.tool()
239+
def show_connections():
240+
"""List available Databend connections (safe operation, not affected by MCP safe mode)"""
241+
logger.info("Listing all connections")
242+
return _execute_sql("SHOW CONNECTIONS")
243+
244+
245+
@mcp.tool()
246+
async def create_stage(name: str, url: str, connection_name: Optional[str] = None, **kwargs) -> dict:
247+
"""
248+
Create a Databend stage with connection
249+
Args:
250+
name: The stage name
251+
url: The stage URL (e.g., 's3://bucket-name')
252+
connection_name: Optional connection name to use
253+
**kwargs: Additional stage options
254+
255+
Returns:
256+
Dictionary containing either query results or error information
257+
"""
258+
logger.info(f"Creating stage '{name}' with URL '{url}'")
259+
260+
sql_parts = [f"CREATE STAGE {name}", f"URL = '{url}'"]
261+
262+
if connection_name:
263+
sql_parts.append(f"CONNECTION = (CONNECTION_NAME = '{connection_name}')")
264+
265+
# Add any additional options from kwargs
266+
for key, value in kwargs.items():
267+
if key not in ['name', 'url', 'connection_name']:
268+
sql_parts.append(f"{key.upper()} = '{value}'")
269+
270+
sql = " ".join(sql_parts)
271+
return _execute_sql(sql)
272+
273+
207274
def main():
208275
"""Main entry point for the MCP server."""
209276
try:

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.1.7"
3+
version = "0.1.8"
44
description = "An MCP server for Databend."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)