MCPcopy
hub / github.com/benborla/mcp-server-mysql / containsSelectStar

Function containsSelectStar

src/db/utils.ts:62–71  ·  view source on GitHub ↗

* Detect column wildcards (`SELECT *` or `SELECT t.*`) anywhere in the query, * including inside subqueries. Aggregate forms like `COUNT(*)` are *not* * flagged because the parser represents those as a `star`-typed expression * argument rather than a `column_ref` with column `"*"`. * * Returns

(sql: string)

Source from the content-addressed store, hash-verified

60 * path. We don't want a parser hiccup to block otherwise valid queries here.
61 */
62function containsSelectStar(sql: string): boolean {
63 let astOrArray: AST | AST[];
64 try {
65 astOrArray = parser.astify(sql, { database: "mysql" });
66 } catch {
67 return false;
68 }
69 const statements = Array.isArray(astOrArray) ? astOrArray : [astOrArray];
70 return statements.some((stmt) => nodeHasColumnStar(stmt));
71}
72
73function nodeHasColumnStar(node: unknown): boolean {
74 if (node == null || typeof node !== "object") return false;

Callers 2

executeReadOnlyQueryFunction · 0.85

Calls 1

nodeHasColumnStarFunction · 0.85

Tested by

no test coverage detected