Skip to main content
Glama

MCPDemo - Visual SQL Chat Platform

by Ayi456
sqlUtils.ts1.09 kB
/** * SQL 工具函数 * 共享的 SQL 相关辅助函数 */ /** * 只读 SQL 检查:仅允许 SELECT / WITH ... SELECT / EXPLAIN SELECT * * @param sql - 待检查的 SQL 语句 * @returns 是否为只读 SQL */ export function isReadOnlySql(sql: string): boolean { // 去除注释与空白 const cleaned = (sql || '') .replace(/\/\*[\s\S]*?\*\//g, '') // /* ... */ .replace(/--.*$/gm, '') // -- ... .replace(/#.*/gm, '') // # ... (MySQL) .trim() .toLowerCase(); if (!cleaned) return false; // 禁止多语句(保守策略) if (cleaned.split(';').filter(Boolean).length > 1) return false; // 拒绝包含任何 DML/DDL 关键字 const forbidden = /(insert|update|delete|create|alter|drop|truncate|grant|revoke|replace|merge|call|do|use|set|commit|rollback)\b/; if (forbidden.test(cleaned)) return false; // 允许的模式:SELECT、WITH ... SELECT、EXPLAIN [ANALYZE] SELECT const allowed = /^(with\s+[\s\S]*?select\s|select\s|explain\s+(analyze\s+)?select\s)/; return allowed.test(cleaned); }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ayi456/visual-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server