database-server-rules

Development rules and examples for database-server code, including synchronous and asynchronous database connections and SQL query security. Asynchronous code can handle other work while waiting for database operations.

In plain words
What is it for?
Use them when writing database connection code, async database operations, or checks for SQL injection and other dangerous queries.
Why use it?
They provide a shared reference for database access and call attention to unsafe SQL patterns. The input does not define a complete database framework or service.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/kenlan2022/mcp_servers_showcase/database-server-rules
Clone the repo
git clone --depth 1 https://github.com/Kenlan2022/mcp_servers_showcase

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 3,919 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.03919
Opus 5 $0.00000 $0.01959
Sonnet 5 $0.00000 $0.00784
Haiku 4.5 $0.00000 $0.00392

Measured 2d ago against content hash d51bfe8586dd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-server-rules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/database-server-rules.mdc · 615 lines

How it starts

The opening of the file, as written. The whole thing — 615 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Server Specific Development Rules

Core Database Operations

Async Database Operations

import asyncio
import aiosqlite
from typing import Dict, Any, List, Optional
import logging

logger = logging.getLogger(__name__)

class DatabaseConnection:
    """Async database connection manager"""
    
    def __init__(self, db_path: str):
        self.db_path = db_path
        self.connection: Optional[aiosqlite.Connection] = None
    
    async def connect(self) -> None:
        """Establish database connection"""
        try:
            self.connection = await aiosqlite.connect(self.db_path)
            await self.connection.execute("PRAGMA foreign_keys = ON")
            await self.connection.commit()
            logger.info(f"Connected to database: {self.db_path}")
        except Exception as e:
            logger.error(f"Database connection error: {e}")
            raise
    
    async def disconnect(self) -> None:
        """Close database connection"""
        if self.connection:
            await self.connection.close()
            self.connection = None
            logger.info("Database connection closed")

SQL Query Security

import re
from typing import Dict, Any, List

# Dangerous SQL patterns to detect
DANGEROUS_PATTERNS = [
    r'\b(DROP|DELETE|TRUNCATE|ALTER|CREATE|INSERT|UPDATE)\b',
    r';\s*--',  # SQL injection comments
    r'\bUNION\b.*\bSELECT\b',
    r'\bEXEC\b|\bEXECUTE\b',
    r'\bxp_cmdshell\b',
    r'\bsp_\w+\b'
]

def validate_sql_query(query: str, allowed_operations: List[str] = None) -> bool:
    """Validate SQL query for security"""
    if not allowed_operations:
        allowed_operations = ['SELECT']
    
    # Check for dangerous patterns
    for pattern in DANGEROUS_PATTERNS:
        if re.search(pattern, query, re.IGNORECASE):
            first_word = query.strip().split()[0].upper()
            if first_word not in allowed_operations:
                raise ValueError(f"Dangerous SQL operation detected: {first_word}")
    
    return True

def sanitize_sql_input(value: Any) -> str:
    """Sanitize SQL input to prevent injection"""
    if isinstance(value, str):
        # Remove SQL special characters
        sanitized = re.sub(r'[^\w\s.-]', '', value)
        return sanitized
    return str(value)

Read the full file on GitHub · 615 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 615 lines · 0 tokens per session scan A d51bfe8586dd

Subscribe to this mod's changes

database-server-rules is a cursor rule published in the GitHub repository Kenlan2022/mcp_servers_showcase (0 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 3,919 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.