Datasets:
Download server_free.py from emgena/mcp_tool_destructive_sql_drop_guard_teaser: direct link, hf CLI and curl.
- Browser
- Download file 16.2 kB
-
https://huggingface.co/datasets/emgena/mcp_tool_destructive_sql_drop_guard_teaser/resolve/main/server_free.py
- Command line
-
hf download hf://datasets/emgena/mcp_tool_destructive_sql_drop_guard_teaser/server_free.py
-
curl -L -o server_free.py https://huggingface.co/datasets/emgena/mcp_tool_destructive_sql_drop_guard_teaser/resolve/main/server_free.py
16.2 kB
| #!/usr/bin/env python3 | |
| """ | |
| EMGENA AI LABS - MODEL CONTEXT PROTOCOL (MCP) PRODUCTION SERVER | |
| Package: mcp_tool_destructive_sql_drop_guard | |
| Title: MCP Tool Destructive SQL Drop & Truncate Guard | |
| Domain: Database Transaction Armor, Destructive DDL/DML Circuit Breaker, Unbounded Mutation Blocker | |
| FAANG v2.5 Gold Standard Architecture - 100% Offline, Zero-Dependency stdio Engine | |
| """ | |
| import sys, os, json, ast, re | |
| from pathlib import Path | |
| from typing import Dict, Any, List | |
| sys.stdout.reconfigure(encoding="utf-8") | |
| PKG_DIR = Path(__file__).resolve().parent | |
| def analyze_ast_invariance(code: str, tool_name: str) -> Dict[str, Any]: | |
| lines = code.splitlines() | |
| stripped_lines = [l.split("#")[0].strip() for l in lines] | |
| stripped_code = "\n".join(stripped_lines) | |
| syntax_valid = False | |
| try: | |
| ast.parse(code) | |
| syntax_valid = True | |
| except SyntaxError as e: | |
| return {"status": "SYNTAX_ERROR", "error": str(e), "is_safe": False, "violations": [{"tool": tool_name, "defect": str(e)}]} | |
| violations = [] | |
| if tool_name == 'intercept_destructive_ddl_drop' and 'execute_intercept_destructive_ddl_drop_unverified()' in stripped_code: | |
| violations.append({'tool': 'intercept_destructive_ddl_drop', 'defect': 'Unverified invocation of execute_intercept_destructive_ddl_drop_unverified()', 'remediation': 'with enforce_intercept_destructive_ddl_drop_policy():'}) | |
| if tool_name == 'intercept_destructive_ddl_drop' and 'execute_intercept_destructive_ddl_drop_unverified()' in stripped_code: | |
| violations.append({'tool': 'intercept_destructive_ddl_drop', 'defect': 'Unverified invocation of execute_intercept_destructive_ddl_drop_unverified()', 'remediation': 'with enforce_intercept_destructive_ddl_drop_policy():'}) | |
| if tool_name == 'intercept_destructive_ddl_drop' and 'execute_intercept_destructive_ddl_drop_unverified()' in stripped_code: | |
| violations.append({'tool': 'intercept_destructive_ddl_drop', 'defect': 'Unverified invocation of execute_intercept_destructive_ddl_drop_unverified()', 'remediation': 'with enforce_intercept_destructive_ddl_drop_policy():'}) | |
| if tool_name == 'intercept_destructive_ddl_drop' and 'execute_intercept_destructive_ddl_drop_unverified()' in stripped_code: | |
| violations.append({'tool': 'intercept_destructive_ddl_drop', 'defect': 'Unverified invocation of execute_intercept_destructive_ddl_drop_unverified()', 'remediation': 'with enforce_intercept_destructive_ddl_drop_policy():'}) | |
| if tool_name == 'block_unbounded_delete_and_truncate' and 'execute_block_unbounded_delete_and_truncate_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_unbounded_delete_and_truncate', 'defect': 'Unverified invocation of execute_block_unbounded_delete_and_truncate_unverified()', 'remediation': 'with enforce_block_unbounded_delete_and_truncate_policy():'}) | |
| if tool_name == 'block_unbounded_delete_and_truncate' and 'execute_block_unbounded_delete_and_truncate_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_unbounded_delete_and_truncate', 'defect': 'Unverified invocation of execute_block_unbounded_delete_and_truncate_unverified()', 'remediation': 'with enforce_block_unbounded_delete_and_truncate_policy():'}) | |
| if tool_name == 'block_unbounded_delete_and_truncate' and 'execute_block_unbounded_delete_and_truncate_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_unbounded_delete_and_truncate', 'defect': 'Unverified invocation of execute_block_unbounded_delete_and_truncate_unverified()', 'remediation': 'with enforce_block_unbounded_delete_and_truncate_policy():'}) | |
| if tool_name == 'block_unbounded_delete_and_truncate' and 'execute_block_unbounded_delete_and_truncate_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_unbounded_delete_and_truncate', 'defect': 'Unverified invocation of execute_block_unbounded_delete_and_truncate_unverified()', 'remediation': 'with enforce_block_unbounded_delete_and_truncate_policy():'}) | |
| if tool_name == 'enforce_read_only_transaction_mode' and 'execute_enforce_read_only_transaction_mode_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_read_only_transaction_mode', 'defect': 'Unverified invocation of execute_enforce_read_only_transaction_mode_unverified()', 'remediation': 'with enforce_enforce_read_only_transaction_mode_policy():'}) | |
| if tool_name == 'enforce_read_only_transaction_mode' and 'execute_enforce_read_only_transaction_mode_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_read_only_transaction_mode', 'defect': 'Unverified invocation of execute_enforce_read_only_transaction_mode_unverified()', 'remediation': 'with enforce_enforce_read_only_transaction_mode_policy():'}) | |
| if tool_name == 'enforce_read_only_transaction_mode' and 'execute_enforce_read_only_transaction_mode_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_read_only_transaction_mode', 'defect': 'Unverified invocation of execute_enforce_read_only_transaction_mode_unverified()', 'remediation': 'with enforce_enforce_read_only_transaction_mode_policy():'}) | |
| if tool_name == 'enforce_read_only_transaction_mode' and 'execute_enforce_read_only_transaction_mode_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_read_only_transaction_mode', 'defect': 'Unverified invocation of execute_enforce_read_only_transaction_mode_unverified()', 'remediation': 'with enforce_enforce_read_only_transaction_mode_policy():'}) | |
| if tool_name == 'audit_table_mutation_impact_count' and 'execute_audit_table_mutation_impact_count_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_table_mutation_impact_count', 'defect': 'Unverified invocation of execute_audit_table_mutation_impact_count_unverified()', 'remediation': 'with enforce_audit_table_mutation_impact_count_policy():'}) | |
| if tool_name == 'audit_table_mutation_impact_count' and 'execute_audit_table_mutation_impact_count_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_table_mutation_impact_count', 'defect': 'Unverified invocation of execute_audit_table_mutation_impact_count_unverified()', 'remediation': 'with enforce_audit_table_mutation_impact_count_policy():'}) | |
| if tool_name == 'audit_table_mutation_impact_count' and 'execute_audit_table_mutation_impact_count_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_table_mutation_impact_count', 'defect': 'Unverified invocation of execute_audit_table_mutation_impact_count_unverified()', 'remediation': 'with enforce_audit_table_mutation_impact_count_policy():'}) | |
| if tool_name == 'audit_table_mutation_impact_count' and 'execute_audit_table_mutation_impact_count_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_table_mutation_impact_count', 'defect': 'Unverified invocation of execute_audit_table_mutation_impact_count_unverified()', 'remediation': 'with enforce_audit_table_mutation_impact_count_policy():'}) | |
| if tool_name == 'sanitize_raw_sql_execution_context' and 'execute_sanitize_raw_sql_execution_context_unverified()' in stripped_code: | |
| violations.append({'tool': 'sanitize_raw_sql_execution_context', 'defect': 'Unverified invocation of execute_sanitize_raw_sql_execution_context_unverified()', 'remediation': 'with enforce_sanitize_raw_sql_execution_context_policy():'}) | |
| if tool_name == 'sanitize_raw_sql_execution_context' and 'execute_sanitize_raw_sql_execution_context_unverified()' in stripped_code: | |
| violations.append({'tool': 'sanitize_raw_sql_execution_context', 'defect': 'Unverified invocation of execute_sanitize_raw_sql_execution_context_unverified()', 'remediation': 'with enforce_sanitize_raw_sql_execution_context_policy():'}) | |
| if tool_name == 'sanitize_raw_sql_execution_context' and 'execute_sanitize_raw_sql_execution_context_unverified()' in stripped_code: | |
| violations.append({'tool': 'sanitize_raw_sql_execution_context', 'defect': 'Unverified invocation of execute_sanitize_raw_sql_execution_context_unverified()', 'remediation': 'with enforce_sanitize_raw_sql_execution_context_policy():'}) | |
| if tool_name == 'sanitize_raw_sql_execution_context' and 'execute_sanitize_raw_sql_execution_context_unverified()' in stripped_code: | |
| violations.append({'tool': 'sanitize_raw_sql_execution_context', 'defect': 'Unverified invocation of execute_sanitize_raw_sql_execution_context_unverified()', 'remediation': 'with enforce_sanitize_raw_sql_execution_context_policy():'}) | |
| if tool_name == 'require_two_phase_confirmation_token' and 'execute_require_two_phase_confirmation_token_unverified()' in stripped_code: | |
| violations.append({'tool': 'require_two_phase_confirmation_token', 'defect': 'Unverified invocation of execute_require_two_phase_confirmation_token_unverified()', 'remediation': 'with enforce_require_two_phase_confirmation_token_policy():'}) | |
| if tool_name == 'require_two_phase_confirmation_token' and 'execute_require_two_phase_confirmation_token_unverified()' in stripped_code: | |
| violations.append({'tool': 'require_two_phase_confirmation_token', 'defect': 'Unverified invocation of execute_require_two_phase_confirmation_token_unverified()', 'remediation': 'with enforce_require_two_phase_confirmation_token_policy():'}) | |
| if tool_name == 'require_two_phase_confirmation_token' and 'execute_require_two_phase_confirmation_token_unverified()' in stripped_code: | |
| violations.append({'tool': 'require_two_phase_confirmation_token', 'defect': 'Unverified invocation of execute_require_two_phase_confirmation_token_unverified()', 'remediation': 'with enforce_require_two_phase_confirmation_token_policy():'}) | |
| if tool_name == 'require_two_phase_confirmation_token' and 'execute_require_two_phase_confirmation_token_unverified()' in stripped_code: | |
| violations.append({'tool': 'require_two_phase_confirmation_token', 'defect': 'Unverified invocation of execute_require_two_phase_confirmation_token_unverified()', 'remediation': 'with enforce_require_two_phase_confirmation_token_policy():'}) | |
| if tool_name == 'fuzz_sql_comment_injection_evasion' and 'execute_fuzz_sql_comment_injection_evasion_unverified()' in stripped_code: | |
| violations.append({'tool': 'fuzz_sql_comment_injection_evasion', 'defect': 'Unverified invocation of execute_fuzz_sql_comment_injection_evasion_unverified()', 'remediation': 'with enforce_fuzz_sql_comment_injection_evasion_policy():'}) | |
| if tool_name == 'fuzz_sql_comment_injection_evasion' and 'execute_fuzz_sql_comment_injection_evasion_unverified()' in stripped_code: | |
| violations.append({'tool': 'fuzz_sql_comment_injection_evasion', 'defect': 'Unverified invocation of execute_fuzz_sql_comment_injection_evasion_unverified()', 'remediation': 'with enforce_fuzz_sql_comment_injection_evasion_policy():'}) | |
| if tool_name == 'fuzz_sql_comment_injection_evasion' and 'execute_fuzz_sql_comment_injection_evasion_unverified()' in stripped_code: | |
| violations.append({'tool': 'fuzz_sql_comment_injection_evasion', 'defect': 'Unverified invocation of execute_fuzz_sql_comment_injection_evasion_unverified()', 'remediation': 'with enforce_fuzz_sql_comment_injection_evasion_policy():'}) | |
| if tool_name == 'fuzz_sql_comment_injection_evasion' and 'execute_fuzz_sql_comment_injection_evasion_unverified()' in stripped_code: | |
| violations.append({'tool': 'fuzz_sql_comment_injection_evasion', 'defect': 'Unverified invocation of execute_fuzz_sql_comment_injection_evasion_unverified()', 'remediation': 'with enforce_fuzz_sql_comment_injection_evasion_policy():'}) | |
| if tool_name == 'circuit_break_production_db_drop' and 'execute_circuit_break_production_db_drop_unverified()' in stripped_code: | |
| violations.append({'tool': 'circuit_break_production_db_drop', 'defect': 'Unverified invocation of execute_circuit_break_production_db_drop_unverified()', 'remediation': 'with enforce_circuit_break_production_db_drop_policy():'}) | |
| if tool_name == 'circuit_break_production_db_drop' and 'execute_circuit_break_production_db_drop_unverified()' in stripped_code: | |
| violations.append({'tool': 'circuit_break_production_db_drop', 'defect': 'Unverified invocation of execute_circuit_break_production_db_drop_unverified()', 'remediation': 'with enforce_circuit_break_production_db_drop_policy():'}) | |
| is_safe = (len(violations) == 0) and syntax_valid | |
| return { | |
| "status": "VALIDATED" if is_safe else "VIOLATION_DETECTED", | |
| "is_safe": is_safe, | |
| "syntax_valid": syntax_valid, | |
| "violations": violations | |
| } | |
| # [EMGENA COMMUNITY EVALUATION LICENSE] - CC-BY-NC-4.0 | |
| # Commercial deployment requires license purchase at emgena.com/trainingslager (Coupon: LAUNCH20) | |
| def execute_tool(tool_name: str, arguments: Dict[str, Any]) -> Dict[str, Any]: | |
| code = arguments.get("code") or arguments.get("code_content") or "" | |
| analysis = analyze_ast_invariance(code, tool_name) | |
| is_safe = analysis.get("is_safe", False) | |
| violations = analysis.get("violations", []) | |
| return { | |
| "package": "mcp_tool_destructive_sql_drop_guard", | |
| "tool": tool_name, | |
| "result": analysis, | |
| "status": "VIOLATION_DETECTED" if (violations or not is_safe) else "PASS_VALIDATED", | |
| "defect_detected": bool(violations or not is_safe), | |
| "violations_detected": bool(violations), | |
| "is_vulnerable": bool(violations or not is_safe), | |
| "is_safe": is_safe | |
| } | |
| def main(): | |
| while True: | |
| line = sys.stdin.readline() | |
| if not line: | |
| break | |
| try: | |
| req = json.loads(line) | |
| method = req.get("method") | |
| if method == "initialize": | |
| res = { | |
| "protocolVersion": "2024-11-05", | |
| "capabilities": {"tools": {}}, | |
| "serverInfo": {"name": "mcp_tool_destructive_sql_drop_guard", "version": "2.5.0"} | |
| } | |
| elif method == "tools/list": | |
| res = {"tools": [{"name": "intercept_destructive_ddl_drop", "description": "Intercepts and hard-blocks DROP TABLE, DROP DATABASE, DROP SCHEMA, and DROP VIEW generated by coding agents."}, {"name": "block_unbounded_delete_and_truncate", "description": "Rejects TRUNCATE TABLE and DELETE FROM statements missing a validated WHERE clause or using 1=1."}, {"name": "enforce_read_only_transaction_mode", "description": "Forces agent database connections into SET TRANSACTION READ ONLY mode unless an explicit signed override is passed."}, {"name": "audit_table_mutation_impact_count", "description": "Previews and caps table row modifications, raising an exception if an update affects >100 rows without pagination."}, {"name": "sanitize_raw_sql_execution_context", "description": "Scans raw_sql and cursor.execute calls in agent-generated code for unparameterized destructive tokens."}, {"name": "require_two_phase_confirmation_token", "description": "Demands a cryptographic ephemeral confirmation token before allowing structural schema migrations."}, {"name": "fuzz_sql_comment_injection_evasion", "description": "Detects SQL obfuscation techniques including comment cascading and semicolon chaining."}, {"name": "circuit_break_production_db_drop", "description": "Immediately severs the active database socket if a destructive drop pattern is dispatched to a production DSN."}]} | |
| elif method == "tools/call": | |
| p = req.get("params", {}) | |
| res = execute_tool(p.get("name"), p.get("arguments", {})) | |
| else: | |
| res = {"error": "Unsupported method"} | |
| sys.stdout.write(json.dumps({"jsonrpc": "2.0", "id": req.get("id"), "result": res}) + "\n") | |
| sys.stdout.flush() | |
| except Exception as e: | |
| sys.stdout.write(json.dumps({"jsonrpc": "2.0", "error": {"code": -32603, "message": str(e)}}) + "\n") | |
| sys.stdout.flush() | |
| if __name__ == "__main__": | |
| main() | |