Skip to content

Commit b42b295

Browse files
committed
Add warehouse_id parameter to SQL execution for improved flexibility
1 parent 51e6ccf commit b42b295

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func main() {
6060
mcp.WithString("statement", mcp.Description("SQL statement to execute"), mcp.Required()),
6161
mcp.WithNumber("execution_timeout_seconds", mcp.Description("Maximum time in seconds to wait for query execution"), mcp.DefaultNumber(60)),
6262
mcp.WithNumber("max_rows", mcp.Description("Maximum number of rows to return in the result"), mcp.DefaultNumber(100)),
63+
mcp.WithString("warehouse_id", mcp.Description("ID of the warehouse to use for execution. If not specified, the first available warehouse will be used")),
6364
), tools.WithWorkspaceClientHandler(w, tools.ExecuteTool(tools.ExecuteSQL)))
6465

6566
s.AddTool(mcp.NewTool("list_warehouses",

tools/execute_sql.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func ExecuteSQL(ctx context.Context, request mcp.CallToolRequest) (interface{},
2020
sqlStatement := ExtractStringParam(request, "statement", "")
2121
timeoutSeconds := ExtractFloatParam(request, "execution_timeout_seconds", 60)
2222
maxRows := ExtractFloatParam(request, "max_rows", 100)
23+
warehouseId := ExtractStringParam(request, "warehouse_id", "")
2324

2425
// Poll every 10 seconds
2526
if timeoutSeconds < 5 {
@@ -30,21 +31,25 @@ func ExecuteSQL(ctx context.Context, request mcp.CallToolRequest) (interface{},
3031
// Poll for statement completion
3132
maxAttempts := int(timeoutSeconds / 10)
3233

33-
// Get available warehouses
34-
warehouses, err := w.Warehouses.ListAll(ctx, sql.ListWarehousesRequest{})
35-
if err != nil {
36-
return nil, fmt.Errorf("error listing warehouses: %w", err)
37-
}
38-
if len(warehouses) == 0 {
39-
return nil, fmt.Errorf("no warehouses available")
34+
// Determine which warehouse to use
35+
if warehouseId == "" {
36+
// Get available warehouses and use the first one
37+
warehouses, err := w.Warehouses.ListAll(ctx, sql.ListWarehousesRequest{})
38+
if err != nil {
39+
return nil, fmt.Errorf("error listing warehouses: %w", err)
40+
}
41+
if len(warehouses) == 0 {
42+
return nil, fmt.Errorf("no warehouses available")
43+
}
44+
warehouseId = warehouses[0].Id
4045
}
4146

4247
// Execute the SQL statement with the specified row limit
4348
res, err := w.StatementExecution.ExecuteStatement(ctx, sql.ExecuteStatementRequest{
4449
RowLimit: int64(maxRows),
4550
Statement: sqlStatement,
4651
WaitTimeout: "5s",
47-
WarehouseId: warehouses[0].Id,
52+
WarehouseId: warehouseId,
4853
})
4954
if err != nil {
5055
return nil, fmt.Errorf("error executing SQL statement: %w", err)

0 commit comments

Comments
 (0)