Skip to main content

db-compare: read-only MCP server that diffs SQL Server / Azure SQL schema between named environments.

Project description

db-compare MCP

Read-only MCP server for comparing SQL Server / Azure SQL schema between named environments (e.g. dev vs prod).

This server never writes to the database. All operations are SELECT queries against catalog views (sys.*). No DDL, DML, or EXEC is performed.

What it compares

  • Tables (columns, PKs, FKs, indexes, check constraints)
  • Stored procedures, views, functions, triggers (line-by-line definition diff)
  • Object inventory (objects only in A, only in B, or changed)

Prerequisites

  1. Python 3.10+ and uv
  2. Read-only database credentials for each environment (db_datareader + VIEW DEFINITION)
  3. One of these drivers:

Setup

cd c:\Users\yadukrishnan\Develop\DBCompare
uv sync

# JDBC only:
uv sync --extra jdbc

ODBC configuration (default)

SQLDIFF_DRIVER=odbc
SQLDIFF_CONN_<NAME>=<odbc connection string>

Example:

SQLDIFF_CONN_DEV=Driver={ODBC Driver 18 for SQL Server};Server=tcp:myserver-dev.database.windows.net,1433;Database=mydb;Uid=readonly;Pwd=...;Encrypt=yes;TrustServerCertificate=no;ApplicationIntent=ReadOnly;

JDBC configuration

SQLDIFF_DRIVER=jdbc
SQLDIFF_JDBC_JAR=C:/path/to/mssql-jdbc-12.8.1.jre11.jar
SQLDIFF_CONN_<NAME>=jdbc:sqlserver://host:1433;databaseName=mydb;encrypt=true;trustServerCertificate=false;
SQLDIFF_JDBC_USER_<NAME>=readonly
SQLDIFF_JDBC_PASSWORD_<NAME>=...

Notes:

  • A connection string starting with jdbc:sqlserver: automatically uses JDBC even if SQLDIFF_DRIVER=odbc.
  • Per-environment override: SQLDIFF_DRIVER_DEV=jdbc, SQLDIFF_DRIVER_PROD=odbc.
  • Credentials can be embedded in the JDBC URL (user=...;password=...) instead of separate env vars.
  • The server automatically appends read-only intent (ApplicationIntent=ReadOnly / applicationIntent=ReadOnly) if not present.

Run standalone

uv run server.py
# or
uv run db-compare

Cursor MCP integration

Edit .cursor/mcp.json with your connection strings (or use Cursor secrets). Restart Cursor, then verify tools appear in the MCP panel.

Example mcp.json:

{
  "mcpServers": {
    "db-compare": {
      "command": "uv",
      "args": ["run", "server.py"],
      "cwd": "/path/to/DBCompare",
      "env": {
        "SQLDIFF_CONN_DEV": "...",
        "SQLDIFF_CONN_PROD": "..."
      }
    }
  }
}

Example chat prompts:

  • "Use db-compare to list configured environments"
  • "Diff schema inventory between dev and prod"
  • "Show full drift report between dev and prod for schema dbo"
  • "Diff table structure for dbo.Orders between dev and prod"

MCP tools

Tool Description
list_environments Show configured environment names
test_connection Verify read-only connectivity
list_schemas List user schemas in one environment
list_objects List tables/views/procs/functions/triggers
diff_schema_inventory High-level inventory diff
diff_object_definition Line diff for a proc/view/function/trigger
diff_table_structure Structural diff for a table
full_drift_report Inventory + deep compare of all common objects

Testing

# Unit tests (no database required)
uv sync --extra dev
uv run pytest tests/test_differ.py tests/test_readonly.py -v

# Integration tests (requires .env.test with SQLDIFF_CONN_DEV and SQLDIFF_CONN_PROD)
uv run pytest tests/ -m integration -v

Copy .env.test.example to .env.test and fill in credentials. Integration tests are read-only — they never modify the database.

Known limitations

  • Encrypted modules cannot be diffed (reported explicitly)
  • Computed columns and filtered index WHERE clauses are not captured
  • Synonyms, sequences, and user-defined types are not yet included

Security

  • Use read-only database users, not admin accounts
  • Never commit connection strings — use .env.test (gitignored) or Cursor env secrets
  • All SQL passes through a SELECT-only guard in db.py

Install (for users)

After publishing to PyPI:

uvx db-compare-mcp

Or add to Cursor mcp.json:

{
  "mcpServers": {
    "db-compare": {
      "command": "uvx",
      "args": ["db-compare-mcp"],
      "env": {
        "SQLDIFF_CONN_DEV": "...",
        "SQLDIFF_CONN_PROD": "..."
      }
    }
  }
}

See PUBLISHING.md for maintainer release steps.

Publishing

Item Value
GitHub https://github.com/yadu-tv/db-compare
PyPI package db-compare-mcp
MCP registry name io.github.yadu-tv/db-compare
CLI entry point db-compare

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_compare_mcp-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_compare_mcp-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file db_compare_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: db_compare_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for db_compare_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c132c446fed637742a638cfd0f9b2d5274b5a505121f5c07947f8a06ea1038c
MD5 8f3b155dc2ea7371f52ac948b4a9fdd9
BLAKE2b-256 ce9e4f27600b6605006c002011dec9371c8f5420b74bc8267e59681c71b1b387

See more details on using hashes here.

File details

Details for the file db_compare_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: db_compare_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for db_compare_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0d25d3d93b10fbcbaedbc3a423ac8daeacf75775d2858ada95cc13f76a446ae
MD5 b07ee37dab6251fd9c184c94b23f1a9f
BLAKE2b-256 b4711d143e54998534242f6d194b0cf48b17d2ae6fcef6aea4ae60ca52c67754

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page