Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/stackql/mcpbackend/mcp_service_stackql.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,14 @@ func (s *simpleStackqlInterrogator) GetDescribeMethod(hI dto.HierarchyInput) (st
if hI.Descriptions {
extended = " EXTENDED"
}
return fmt.Sprintf("DESCRIBE METHOD%s %s.%s.%s.%s", extended, hI.Provider, hI.Service, hI.Resource, hI.Method), nil
// Quote each segment: a method (or service, or resource) may be named
// after a keyword such as `list`, which the parser rejects bare in
// this position. A quoted identifier parses as a plain identifier,
// and doubling an embedded quote keeps the statement well formed.
quoteIdent := func(value string) string {
return "\"" + strings.ReplaceAll(value, "\"", "\"\"") + "\""
}
return fmt.Sprintf("DESCRIBE METHOD%s %s.%s.%s.%s", extended, quoteIdent(hI.Provider), quoteIdent(hI.Service), quoteIdent(hI.Resource), quoteIdent(hI.Method)), nil
}
quote := func(value string) string {
return "'" + strings.ReplaceAll(strings.ReplaceAll(value, "\\", "\\\\"), "'", "''") + "'"
Expand Down
32 changes: 32 additions & 0 deletions internal/stackql/mcpbackend/method_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ import (
"github.com/stackql/stackql/pkg/mcp_server/dto"
)

func TestDescribeMethodQuotesKeywordMethodNames(t *testing.T) {
// stackql/stackql#926: `list` lexes as a keyword, so the parser rejects
// it bare in this position. The host-native branch must quote its
// identifiers, and the quoted statement must still resolve to the same
// method name downstream.
input := dto.HierarchyInput{Provider: "stackql_preview", Service: "google", Resource: "buckets", Method: "list", Descriptions: true}
query, err := mcpbackend.NewSimpleStackqlInterrogator().GetDescribeMethod(input)
if err != nil {
t.Fatal(err)
}
parsed, err := sqlparser.Parse(query)
if err != nil {
t.Fatalf("quoted DESCRIBE METHOD does not parse: %v (%s)", err, query)
}
dm, ok := parsed.(*sqlparser.DescribeMethod)
if !ok {
t.Fatalf("parsed statement is %T, not DescribeMethod", parsed)
}
if got := dm.Method.GetRawVal(); got != "list" {
t.Fatalf("method parsed as %q, want %q", got, "list")
}
// A name carrying a quote must not escape the quoted identifier.
input.Method = `we"ird`
query, err = mcpbackend.NewSimpleStackqlInterrogator().GetDescribeMethod(input)
if err != nil {
t.Fatal(err)
}
if _, err := sqlparser.Parse(query); err != nil {
t.Fatalf("quoted identifier with an embedded quote does not parse: %v (%s)", err, query)
}
}

func TestDescribeMethodSerializesControlsForBothBackends(t *testing.T) {
input := dto.HierarchyInput{Provider: "google", Service: "compute", Resource: "instances", Method: "insert", Depth: 2, Path: "data__settings.mode", Descriptions: true, ParamType: "input", IncludeGlobal: true}
query, err := mcpbackend.NewSimpleStackqlInterrogator().GetDescribeMethod(input)
Expand Down
39 changes: 39 additions & 0 deletions test/robot/functional/MethodSchemaLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,42 @@ def request(identifier, method, params):
if process.poll() is None:
process.kill()
process.wait()

def mcp_describe_method_named_list(self):
flags = list(self.flags)
flags[flags.index("--preview") + 1] = json.dumps({"unstable": False})
command = self.prefix + flags + ["--mcp.config", json.dumps({"server": {"transport": "stdio", "audit": {"disabled": True}}, "enabled_tools": ["describe_method"]}), "mcp"]
process = subprocess.Popen(command, env=self.env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
watchdog = threading.Timer(45, process.kill)
watchdog.start()
try:
def request(identifier, method, params):
process.stdin.write((json.dumps({"jsonrpc": "2.0", "id": identifier, "method": method, "params": params}) + "\n").encode())
process.stdin.flush()
while True:
line = process.stdout.readline()
assert line, "MCP closed before response"
message = json.loads(line)
if message.get("id") == identifier:
return message
request(1, "initialize", {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "schema-test", "version": "1"}})
process.stdin.write(b'{"jsonrpc":"2.0","method":"notifications/initialized"}\n')
args = {"provider": "widgets", "service": "things", "resource": "widgets", "method": "list", "format": "json"}
response = request(2, "tools/call", {"name": "describe_method", "arguments": args})
assert "error" not in response and not response["result"].get("isError"), response
content = response["result"].get("structuredContent")
if content is None:
content = json.loads(response["result"]["content"][0]["text"])
rows = content["rows"]
assert rows, "describe_method list returned no rows"
assert self.named(rows, "region")["param_type"] == "input_required", rows
assert not self.calls, "MCP discovery called the provider"
process.stdin.close()
process.stdin = None
process.communicate(timeout=10)
assert process.returncode == 0
finally:
watchdog.cancel()
if process.poll() is None:
process.kill()
process.wait()
3 changes: 3 additions & 0 deletions test/robot/functional/stackql_method_schema.robot
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ Method Schema Rejects Invalid Controls And Missing Paths

MCP Describe Method Applies Schema Controls
Mcp Method Schema Controls Reach Backend

MCP Describe Method Accepts Keyword Named Method
Mcp Describe Method Named List
Loading