(query: string)
| 20 | }; |
| 21 | |
| 22 | export function validateQuery(query: string): QueryValidationResult { |
| 23 | for (const pattern of BLOCKED_PATTERNS) { |
| 24 | if (pattern.test(query)) { |
| 25 | return { |
| 26 | allowed: false, |
| 27 | warning: `Query blocked: ${query.trim().split(/\s+/).slice(0, 3).join(' ').toUpperCase()} is not allowed via MCP`, |
| 28 | }; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if (DELETE_WITHOUT_WHERE.test(query)) { |
| 33 | return { |
| 34 | allowed: true, |
| 35 | warning: 'Warning: DELETE without WHERE clause detected', |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | for (const { pattern, label } of WARNING_PATTERNS) { |
| 40 | if (pattern.test(query)) { |
| 41 | return { |
| 42 | allowed: true, |
| 43 | warning: `Warning: ${label} statement detected`, |
| 44 | }; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return { allowed: true }; |
| 49 | } |
| 50 | |
| 51 | export function getQueryType(query: string): string { |
| 52 | const match = query.trim().match(/^\s*(\w+)/); |
no outgoing calls
no test coverage detected