Skip to content

Commit a701e5f

Browse files
- Testing details.
1 parent 31677d5 commit a701e5f

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

internal/stackql/primitivebuilder/explain.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package primitivebuilder
22

33
import (
4+
"time"
5+
46
"github.com/stackql/any-sdk/public/sqlengine"
57
"github.com/stackql/stackql/internal/stackql/handler"
68
"github.com/stackql/stackql/internal/stackql/internal_data_transfer/internaldto"
@@ -50,11 +52,18 @@ func (nb *ExplainBuilder) Build() error {
5052
if nb.instructionErr != nil {
5153
return internaldto.NewErroneousExecutorOutput(nb.instructionErr)
5254
}
55+
oneLinerOutput := time.Now().Format("2006-01-02T15:04:05-07:00 MST")
56+
resultMap := map[string]any{
57+
"query": nb.handlerCtx.GetRawQuery(),
58+
"timestamp": oneLinerOutput,
59+
"valid": true,
60+
}
61+
columns := []string{"query", "timestamp", "valid"}
5362
return util.PrepareResultSet(
5463
internaldto.NewPrepareResultSetPlusRawDTO(
5564
nil,
56-
nil,
57-
nil,
65+
map[string]map[string]any{"0": resultMap},
66+
columns,
5867
nil,
5968
nil,
6069
internaldto.NewBackendMessages(nb.messages), nil,

pkg/mcp_server/server.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ func newMCPServer(config *Config, backend Backend, logger *logrus.Logger) (MCPSe
223223
return &mcp.CallToolResult{Content: []mcp.Content{&mcp.TextContent{Text: string(bytesOut)}}}, out, nil
224224
},
225225
)
226+
mcp.AddTool(
227+
server,
228+
&mcp.Tool{
229+
Name: "validate_query_json_v2",
230+
Description: "Explain a SQL query and return a JSON object expressing success, or else an error.",
231+
},
232+
func(ctx context.Context, req *mcp.CallToolRequest, args dto.QueryJSONInput) (*mcp.CallToolResult, any, error) {
233+
args.SQL = fmt.Sprintf("EXPLAIN %s", args.SQL)
234+
arr, err := backend.RunQueryJSON(ctx, args)
235+
if err != nil {
236+
return nil, nil, err
237+
}
238+
out := dto.QueryResultDTO{Rows: arr, RowCount: len(arr), Format: "json"}
239+
bytesOut, _ := json.Marshal(out)
240+
return &mcp.CallToolResult{Content: []mcp.Content{&mcp.TextContent{Text: string(bytesOut)}}}, out, nil
241+
},
242+
)
226243
mcp.AddTool(
227244
server,
228245
&mcp.Tool{

test/robot/functional/stackql_mocked_from_cmd_line.robot

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9018,16 +9018,16 @@ Delete Await Returning Generates Error
90189018
Explain Select Repeatably Generates Messages
90199019
[Documentation] This is fairly crude but useful in particular for MCP functions.
90209020
${inputStr} = Catenate
9021-
... explain select * from google.compute.instances where project = 'stackql-demo';
9022-
... explain select * from google.compute.instances where project = 'stackql-demo';
9021+
... explain select * from google.storage.buckets where project = 'stackql-demo';
9022+
... explain select * from google.storage.buckets where project = 'stackql-demo';
90239023
... explain select * from aws.ec2.instances where region = 'ap-southeast-2';
90249024
... explain select * from aws.ec2.instances where region = 'ap-southeast-2';
90259025
... explain select 1 as foo;
90269026
... explain select 1 as foo;
90279027
... explain select * from google.storage.buckets;
90289028
... explain select * from google.storage.buckets;
9029-
... explain select * from google.compute.instances where project = 'stackql-demo';
9030-
... explain select * from google.compute.instances where project = 'stackql-demo';
9029+
... explain select * from google.storage.buckets where project = 'stackql-demo';
9030+
... explain select * from google.storage.buckets where project = 'stackql-demo';
90319031
${outputErrStr} = Catenate SEPARATOR=\n
90329032
... Execution plan generated successfully
90339033
... OK
@@ -9037,17 +9037,15 @@ Explain Select Repeatably Generates Messages
90379037
... OK
90389038
... Execution plan generated successfully
90399039
... OK
9040-
... Execution plan generated successfully
90419040
... OK
9042-
... Execution plan generated successfully
90439041
... OK
90449042
... cannot find matching operation, possible causes include missing required parameters or an unsupported method for the resource, to find required parameters for supported methods run SHOW METHODS IN google.storage.buckets: no appropriate method = 'select' for resource = 'buckets'
90459043
... cannot find matching operation, possible causes include missing required parameters or an unsupported method for the resource, to find required parameters for supported methods run SHOW METHODS IN google.storage.buckets: no appropriate method = 'select' for resource = 'buckets'
90469044
... Execution plan generated successfully
90479045
... OK
90489046
... Execution plan generated successfully
90499047
... OK
9050-
Should Stackql Exec Inline Equal Both Streams
9048+
Should Stackql Exec Inline Equal Stderr
90519049
... ${STACKQL_EXE}
90529050
... ${OKTA_SECRET_STR}
90539051
... ${GITHUB_SECRET_STR}
@@ -9056,7 +9054,6 @@ Explain Select Repeatably Generates Messages
90569054
... ${AUTH_CFG_STR}
90579055
... ${SQL_BACKEND_CFG_STR_CANONICAL}
90589056
... ${inputStr}
9059-
... ${EMPTY}
90609057
... ${outputErrStr}
90619058
... stdout=${CURDIR}/tmp/Explain-Select-Repeatably-Generates-Messages.tmp
90629059
... stderr=${CURDIR}/tmp/Explain-Select-Repeatably-Generates-Messages-stderr.tmp

0 commit comments

Comments
 (0)