npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sql-mcp

v0.1.2

Published

MCP server for SQL databases with guardrails against destructive operations

Readme

sql-mcp

An MCP (Model Context Protocol) server for SQL databases with built-in guardrails against destructive operations.

AI coding agents can execute SQL queries autonomously — which means they can also accidentally run DELETE, DROP, or UPDATE on the wrong rows. sql-mcp sits between the agent and your database, intercepting guarded operations and requiring explicit confirmation before they execute.

Supported databases: Microsoft SQL Server, PostgreSQL


Installation

# Run directly without installing
npx sql-mcp

# Or install globally
npm install -g sql-mcp
sql-mcp

Configuration

sql-mcp is configured entirely via environment variables — either in your shell or in your MCP client's config.

Required

| Variable | Description | |---|---| | DB_TYPE | Database type: mssql or pgsql | | DB_HOST | Database server hostname | | DB_NAME | Database name | | DB_USER | Database username | | DB_PASSWORD | Database password |

Optional

| Variable | Default | Description | |---|---|---| | DB_PORT | 5432 (pgsql) / 1433 (mssql) | Database port | | GUARD_MODE | confirm | confirm — hold guarded queries for approval. block — reject them outright | | GUARDED_OPERATIONS | See below | Comma-separated SQL keywords to guard. NONE disables guarding. ALL uses the full default list | | DB_TRUST_SERVER_CERTIFICATE | false | MSSQL only. Set to true for local/dev instances with self-signed certificates |

Default guarded operations: INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, EXEC, EXECUTE, MERGE, CREATE, GRANT, REVOKE, DENY


MCP Client Setup

Claude Code / Cursor / Windsurf

Add to your MCP settings (e.g. ~/.claude/settings.json or your client's equivalent):

PostgreSQL:

{
  "mcpServers": {
    "database": {
      "command": "npx",
      "args": ["sql-mcp"],
      "env": {
        "DB_TYPE": "pgsql",
        "DB_HOST": "localhost",
        "DB_NAME": "mydb",
        "DB_USER": "postgres",
        "DB_PASSWORD": "secret"
      }
    }
  }
}

SQL Server:

{
  "mcpServers": {
    "database": {
      "command": "npx",
      "args": ["sql-mcp"],
      "env": {
        "DB_TYPE": "mssql",
        "DB_HOST": "localhost",
        "DB_NAME": "mydb",
        "DB_USER": "sa",
        "DB_PASSWORD": "secret",
        "DB_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

Guard Modes

confirm (default)

When a guarded operation is detected, sql-mcp holds the query and returns a token. The agent must call confirm_query with that token to execute it. This gives you a chance to review and approve before anything runs.

Agent: run_query("DELETE FROM users WHERE inactive = true")
  ← { needs_confirmation: true, token: "uuid", query: "...", expires_in_minutes: 5 }

[You review and approve]

Agent: confirm_query("uuid")
  ← { success: true, rowsAffected: [47] }

Tokens expire after 5 minutes. If a token expires, re-run the original query to get a new one.

Note for "run everything" / auto-approve agent modes: If your MCP client is configured to execute tool calls automatically without pausing for human review (e.g. Cursor's "run everything" mode), the agent may call confirm_query immediately after run_query without any human checkpoint. In this case, confirm mode offers no real protection — use block mode instead.

block

All guarded operations are rejected immediately with no option to confirm. Use this for production environments or any setup where the agent runs autonomously without human review.


Tools

list_tables

Lists all user tables in the connected database.

Returns: schema name, table name, row count, size (MB) for each table.

{
  "success": true,
  "table_count": 12,
  "tables": [
    { "schema": "public", "table": "users", "full_name": "public.users", "row_count": 15234, "size_mb": 45.2 }
  ]
}

describe_table

Returns detailed schema information for a table.

Parameters:

  • tableName — table name, optionally schema-prefixed (e.g. "users" or "dbo.users")

Returns: columns (with types, nullability, defaults, PK/identity flags), foreign keys, indexes, row count, and sample rows.

{
  "success": true,
  "table": "public.users",
  "statistics": { "row_count": 15234 },
  "columns": [
    { "name": "id", "type": "integer", "nullable": false, "default": null, "primary_key": true, "identity": true },
    { "name": "email", "type": "character varying(255)", "nullable": false, "default": null, "primary_key": false, "identity": false }
  ],
  "foreign_keys": [ ... ],
  "indexes": [ ... ],
  "sample_rows": [ ... ]
}

run_query

Executes a SQL query.

Parameters:

  • sql — the SQL query to run

Safe (non-guarded) queries execute immediately and return results. Guarded queries are handled according to the configured GUARD_MODE.

Results are capped at 1000 rows. If a result set is truncated, the response includes "truncated": true.


confirm_query

Executes a previously held guarded query.

Parameters:

  • token — the UUID token returned by run_query

Only works if the token exists and has not expired (5-minute TTL).


analyze_query_impact

Analyzes a destructive SQL query without executing it. Returns an estimate of how many rows will be affected, any CASCADE relationships that will trigger on child tables, warnings, and recommendations.

Parameters:

  • sql — the SQL query to analyze (DELETE, UPDATE, TRUNCATE, or DROP)

Returns: operation type, target table, estimated rows affected, cascade details, warnings, and recommendations.

{
  "operation": "UPDATE",
  "table": "public.orders",
  "estimated_rows_affected": 3200,
  "cascades": [],
  "warnings": [],
  "recommendations": [
    "Large operation (3,200 rows). Consider batching with LIMIT to reduce lock duration."
  ]
}

For DELETE, TRUNCATE, and DROP, the response also includes cascades — child tables that have an ON DELETE CASCADE foreign key relationship with the target table. Cascade row counts are best-effort and may be null for complex queries.

Note: In confirm mode, run_query automatically includes impact analysis in its response when holding a guarded query — you do not need to call analyze_query_impact separately.


Requirements

  • Node.js ≥ 18
  • Network access to your database

License

MIT