Skip to content

Commit 8cb4f2a

Browse files
mcp-validation-response (#589)
* mcp-validation-response Summary: - Added `valid` key to `validate_query_json_v2`, per contract. - Amended robot test `MCP HTTPS Server Validate Canonical`. - Added robot test `MCP HTTPS Server Validate Canonical Negative`. * - Corrrected keyword usage.
1 parent 2fb13b1 commit 8cb4f2a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

pkg/mcp_server/dto/dto.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ type QueryResultDTO struct {
181181
Warnings []string `json:"warnings,omitempty"`
182182
}
183183

184+
type ValidationResultDTO struct {
185+
IsValid bool `json:"valid"`
186+
Message string `json:"message,omitempty"`
187+
Errors []string `json:"errors,omitempty"`
188+
}
189+
184190
// GreetDTO carries a simple greeting payload.
185191
type GreetDTO struct {
186192
Greeting string `json:"greeting"`

pkg/mcp_server/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,15 @@ func newMCPServer(config *Config, backend Backend, logger *logrus.Logger) (MCPSe
231231
},
232232
func(ctx context.Context, req *mcp.CallToolRequest, args dto.QueryJSONInput) (*mcp.CallToolResult, any, error) {
233233
arr, err := backend.ValidateQuery(ctx, args.SQL)
234+
isValid := err == nil
235+
message := "Query validation succeeded."
236+
var errorsToPublish []string
234237
if err != nil {
235-
return nil, nil, err
238+
errorsToPublish = append(errorsToPublish, err.Error())
239+
arrBytes, _ := json.Marshal(arr)
240+
message = fmt.Sprintf("Query validation failed, returned data: %s", string(arrBytes))
236241
}
237-
out := dto.QueryResultDTO{Rows: arr, RowCount: len(arr), Format: "json"}
242+
out := dto.ValidationResultDTO{IsValid: isValid, Errors: errorsToPublish, Message: message}
238243
bytesOut, _ := json.Marshal(out)
239244
return &mcp.CallToolResult{Content: []mcp.Content{&mcp.TextContent{Text: string(bytesOut)}}}, out, nil
240245
},

test/robot/functional/mcp.robot

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Settings ***
22
Resource ${CURDIR}${/}stackql.resource
33
Library Collections
4+
Library Builtin
45

56

67
*** Keywords ***
@@ -523,8 +524,28 @@ MCP HTTPS Server Validate Canonical
523524
... stdout=${CURDIR}${/}tmp${/}MCP-HTTPS-validate-canonical.txt
524525
... stderr=${CURDIR}${/}tmp${/}MCP-HTTPS-validate-canonical-stderr.txt
525526
${meta_rels_obj}= Parse MCP JSON Output ${meta_rels.stdout}
526-
Dictionary Should Contain Key ${meta_rels_obj} rows
527-
Length Should Be ${meta_rels_obj['rows']} 1
527+
Dictionary Should Contain Key ${meta_rels_obj} valid
528+
Should Be True ${meta_rels_obj}[valid]
529+
530+
MCP HTTPS Server Validate Canonical Negative
531+
Pass Execution If "%{IS_SKIP_MCP_TEST=false}" == "true" Some platforms do not have the MCP client available
532+
# Future proofing: raw text format reserved; may gain structured hints later.
533+
${meta_rels}= Run Process
534+
... ${STACKQL_MCP_CLIENT_EXE}
535+
... exec
536+
... \-\-client\-type\=http
537+
... \-\-url\=https://127.0.0.1:9004
538+
... \-\-client\-cfg
539+
... { "apply_tls_globally": true, "insecure_skip_verify": true, "ca_file": "test/server/mtls/credentials/pg_server_cert.pem", "promote_leaf_to_ca": true }
540+
... \-\-exec.action
541+
... validate_query_json_v2
542+
... \-\-exec.args
543+
... {"sql":"select * from google.storage.buckets2 where project \= 'stackql\-demo';"}
544+
... stdout=${CURDIR}${/}tmp${/}MCP-HTTPS-validate-canonical-negative.txt
545+
... stderr=${CURDIR}${/}tmp${/}MCP-HTTPS-validate-canonical-negative-stderr.txt
546+
${meta_rels_obj}= Parse MCP JSON Output ${meta_rels.stdout}
547+
Dictionary Should Contain Key ${meta_rels_obj} valid
548+
Should Be True ${meta_rels_obj}[valid] == False
528549

529550
MCP HTTPS Server Query Canonical
530551
Pass Execution If "%{IS_SKIP_MCP_TEST=false}" == "true" Some platforms do not have the MCP client available

0 commit comments

Comments
 (0)