Skip to main content
Glama
defrex

Drizzle MCP Server

by defrex

Drizzle MCP Server

A Model Context Protocol (MCP) server that provides access to Drizzle ORM database operations and drizzle-kit CLI tools.

Features

  • Database Schema Management: Generate and run migrations using drizzle-kit

  • Query Execution: Execute raw SQL queries with parameter support

  • Schema Introspection: Explore database tables and schema information

  • Database Resources: Browse tables and schema through MCP resources

  • Cross-Project Compatibility: Works with any existing Drizzle project

  • Multi-Database Support: SQLite and PostgreSQL with automatic driver detection

  • Environment Variable Support: Automatic .env file loading for database credentials

  • Flexible Installation: Install globally, run with npx/bunx, or use as a linked package

Related MCP server: SQLx MCP Server

Installation

Option 1: Install globally from GitHub

npm install -g github:defrex/drizzle-mcp

Option 2: Run directly with npx/bunx (no installation required)

npx github:defrex/drizzle-mcp --help
bunx github:defrex/drizzle-mcp --help
# In the drizzle-mcp directory
bun link

# In your project directory
bun link drizzle-mcp

Usage

Basic Usage

Run the server with your Drizzle config file:

drizzle-mcp ./drizzle.config.ts

Or use the config option:

drizzle-mcp --config ./drizzle.config.ts

Claude Desktop Integration

Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "drizzle": {
      "command": "npx",
      "args": ["github:defrex/drizzle-mcp", "./drizzle.config.ts"]
    }
  }
}

Or with bunx:

{
  "mcpServers": {
    "drizzle": {
      "command": "bunx",
      "args": ["github:defrex/drizzle-mcp", "./drizzle.config.ts"]
    }
  }
}

Command Line Options

drizzle-mcp [options] [config]

Arguments:
  config               Path to drizzle config file

Options:
  -V, --version        output the version number
  -c, --config <path>  Path to drizzle config file
  -d, --cwd <path>     Working directory (default: current directory)
  -v, --verbose        Enable verbose logging
  -h, --help           display help for command

Configuration

The server automatically detects your Drizzle configuration from:

  • Command line argument: drizzle-mcp ./my-config.ts

  • Current directory: drizzle.config.ts, drizzle.config.js, or drizzle.config.mjs

Your Drizzle config should be a standard drizzle-kit configuration file.

Environment Variables

The server automatically loads environment variables from .env.local and .env files in your project directory. This is useful for database credentials:

# .env.local
DATABASE_URL=postgresql://username:password@localhost:5432/database

The server will detect and use DATABASE_URL from your environment variables, so you can use it in your drizzle config:

export default defineConfig({
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
  // ...
});

Available Tools

  1. drizzle_generate_migration - Generate new migration files

  2. drizzle_run_migrations - Apply pending migrations

  3. drizzle_introspect_schema - Introspect existing database schema

  4. execute_query - Execute raw SQL queries

  5. initialize_database - Initialize database connection

Available Resources

  1. database://tables - List all database tables

  2. database://schema - Complete database schema information

Note: Resources are database-agnostic and work with both SQLite and PostgreSQL

Requirements

  • Node.js 18 or higher

  • An existing Drizzle project with:

    • drizzle-orm >= 0.40.0

    • drizzle-kit >= 0.30.0

    • For SQLite: better-sqlite3 >= 9.0.0

    • For PostgreSQL: pg >= 8.0.0 OR postgres >= 3.4.0

Note: The server automatically detects which database driver you have installed and uses the appropriate one.

Example Configuration

SQLite Configuration

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  out: "./migrations",
  schema: "./src/schema.ts",
  dialect: "sqlite",
  dbCredentials: {
    url: "./database.db",
  },
});

PostgreSQL Configuration

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  out: "./migrations",
  schema: "./src/schema.ts",
  dialect: "postgresql",
  dbCredentials: {
    url: process.env.DATABASE_URL!,
    // Or use individual credentials:
    // host: "localhost",
    // port: 5432,
    // user: "username",
    // password: "password",
    // database: "database",
  },
});

Note: The server supports both pg (node-postgres) and postgres (postgres-js) drivers. It will automatically detect which one you have installed and use the appropriate one.

Supported Databases

Currently supports:

  • SQLite - Via better-sqlite3

  • PostgreSQL - Via pg (node-postgres) or postgres (postgres-js)

The server automatically detects which database drivers you have installed and uses the appropriate ones. For PostgreSQL, it will try postgres first, then fall back to pg.

Support for MySQL is planned for future releases.

Development

The server is built with:

  • Node.js - JavaScript runtime

  • TypeScript - Type-safe development

  • Drizzle ORM - Database ORM and query builder

  • Commander.js - CLI argument parsing

  • MCP SDK - Model Context Protocol implementation

  • dotenv - Environment variable loading

Building from Source

git clone https://github.com/defrex/drizzle-mcp.git
cd drizzle-mcp
bun install
bun run build

Key Features

  • Automatic Module Resolution: Resolves database drivers and drizzle-orm from your project's dependencies

  • Environment Variable Loading: Automatically loads .env.local and .env files from your project

  • Cross-Platform: Works with npm, bun, and various package managers

  • Comprehensive Error Handling: Detailed error messages with context for easier debugging

  • Security: Input validation and sanitization for all user inputs

License

MIT

Available Tools

5 tools
drizzle_generate_migrationB

Generate a new migration file using drizzle-kit

ParametersJSON Schema
NameRequiredDescriptionDefault
nameYesName for the migration
configNoPath to drizzle config file (optional)

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description is solely responsible for disclosing behavior. It fails to mention that this operation generates a file on disk, whether it modifies the database, or if it requires prior configuration. The one-line description leaves the agent with many unknowns.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that communicates the core purpose. No redundant wording or filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and an output schema, the description should compensate by explaining the generation process, output location, and relationship to sibling tools. It only states what it does, leaving the agent to infer side effects and execution context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides complete descriptions for both parameters (name and config) with 100% coverage. The description adds no additional parameter context, so the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (generate), the resource (a new migration file), and the mechanism (drizzle-kit). This distinguishes it from siblings like drizzle_run_migrations, which applies migrations, and drizzle_introspect_schema, which reads schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings. It does not mention that this tool only creates the migration file and does not apply it, nor does it explain prerequisites like requiring a drizzle config.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

drizzle_introspect_schemaB

Introspect database schema using drizzle-kit

ParametersJSON Schema
NameRequiredDescriptionDefault
configNoPath to drizzle config file (optional)

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description must disclose behavioral traits but does not. It only restates the tool name and mentions drizzle-kit. It does not indicate whether the operation is read-only, whether it modifies schema files, requires credentials, or what the output/return value is. This lacks essential behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no redundancy. It front-loads the core action ('Introspect database schema') and efficiently names the tool ('drizzle-kit'). Every phrase earns its place, making it appropriately concise and structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple tool (1 optional param, no output schema, no annotations), the description should provide enough context for the agent to know what happens on success and how to use it in a workflow. It does not explain what introspection produces, how it relates to config, or any side effects. The brief description leaves significant gaps for practical use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema provides a description for the only parameter 'config' ('Path to drizzle config file (optional)'), giving 100% schema description coverage. Per calibration, the baseline is 3, and the tool description adds no additional parameter semantics beyond what the schema already covers.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the tool as introspecting the database schema using drizzle-kit, which is a specific verb+resource combination. It is distinct from sibling tools like generate_migration or run_migrations, making its purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is given on when to use this tool versus alternatives. It does not mention any prerequisites, exclusions, or when introspection is appropriate (e.g., before generating migrations). The description simply states what it does without usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

drizzle_run_migrationsA

Run pending migrations using drizzle-kit

ParametersJSON Schema
NameRequiredDescriptionDefault
configNoPath to drizzle config file (optional)

TDQS

A3.5/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only says 'Run pending migrations using drizzle-kit' without mentioning that migrations can modify the database schema, may be irreversible, or may require specific permissions or a database connection. Given the potentially destructive nature of migrations, this lack of disclosure is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that is front-loaded and directly states the operation. Every word earns its place, with no filler or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple (one optional parameter, no output schema), so a brief description suffices. However, for a migration tool that may alter the database schema, the description lacks important context such as side effects, prerequisites, and the meaning of 'pending'. It is minimally complete but misses critical operational context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already fully documents the single 'config' parameter with a clear description ('Path to drizzle config file (optional)'). The tool description adds no additional parameter semantics, but since schema coverage is 100%, the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Run pending migrations using drizzle-kit' clearly states a specific verb ('run') and resource ('pending migrations'), and unambiguously distinguishes it from sibling tools like drizzle_generate_migration (which creates migrations) and execute_query (which runs arbitrary SQL).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is used to apply pending migrations, but it provides no explicit when-to-use guidance, exclusions, or alternative tool comparisons. It does not state when to prefer this over drizzle_generate_migration or execute_query, so the usage context is only implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

execute_queryB

Execute a raw SQL query on the database

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesSQL query to execute
paramsNoQuery parameters

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It only states 'Execute a raw SQL query' without disclosing potential side effects (e.g., mutation, transaction handling, error behavior) or that arbitrary SQL could be destructive. This is a significant gap for a raw SQL tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no filler. It is concise and front-loaded with the verb and object.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has no output schema and no annotations, yet the description does not explain return value, whether multiple statements are supported, or how parameters are applied. For a raw SQL execution tool, this leaves critical context missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema fully describes both parameters (query and params) with descriptions, so the description adds no additional semantic value. Baseline 3 is appropriate because schema coverage is 100%.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb 'Execute' and a clear resource 'raw SQL query on the database', which distinguishes it from sibling tools focused on migrations and schema introspection. It is unambiguous about the core function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like drizzle_run_migrations or initialize_database. There are no prerequisites, exclusions, or context on appropriate scenarios for raw SQL execution.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

initialize_databaseC

Initialize database connection

ParametersJSON Schema
NameRequiredDescriptionDefault
configNoPath to drizzle config file (optional)

TDQS

C2.8/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose side effects, safety, or idempotence. It simply says 'Initialize database connection' without explaining what happens, whether it creates or mutates resources, or if it is safe to run repeatedly. This is a significant gap for a tool that likely has side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence, which is positive, but it essentially rephrases the tool name without adding substantive detail. It is not as sparse as 'Process', but it under-delivers on useful content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no annotations, no output schema, and simple parameters, the description still fails to explain the behavior and purpose of initialization, such as whether it creates a database or just establishes a connection. This is inadequate for a tool named 'initialize_database'.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already includes a description for the one parameter ('Path to drizzle config file (optional)'), providing 100% schema coverage. The tool description adds no further context, so the baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Initialize') and the target resource ('database connection'), which distinguishes it from sibling tools that handle migrations and queries. However, 'database connection' is somewhat vague as it does not specify what initialization entails, but it is more than a tautology.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It does not mention prerequisites, whether initialization must precede other operations, or any exclusions, leaving the user to infer its place in the workflow.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 5 tool updatesv1.0.0
    • First observeddrizzle_generate_migration
    • First observeddrizzle_introspect_schema
    • First observeddrizzle_run_migrations
    • First observedexecute_query
    • First observedinitialize_database

TDQS

B3.4/5.0

Scored across 5 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: generating migrations, running migrations, introspecting schema, executing raw SQL, and initializing the connection. There is no overlap or ambiguity among them.

Naming Consistency3/5

The three drizzle-kit related tools use the 'drizzle_' prefix (e.g., drizzle_generate_migration) while the other two tools (execute_query, initialize_database) do not follow this prefix pattern. This creates a minor inconsistency, though all names are still snake_case and readable.

Tool Count5/5

With only 5 tools, the server is well-scoped for its purpose of handling Drizzle migrations and database interactions. Each tool is essential and the count is neither too sparse nor overwhelming.

Completeness4/5

The server covers the core lifecycle of Drizzle migrations (generate, run, introspect) and provides raw query access for additional operations. A minor gap is the lack of a dedicated migration rollback or status tool, but raw SQL and introspection can compensate.

Maintenance

ActivityInactive
ResponsivenessUnresponsive

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables secure database interactions with MySQL, PostgreSQL, and SQLite through granular permissions, multi-database support, and cloud-ready SSL/TLS connections. Supports read-only modes, schema-specific permissions, and transaction management for safe database operations.
    8 npm
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides comprehensive database management tools for PostgreSQL, MySQL, and SQLite databases. Enables querying table structures, executing read-only and write queries, exporting DDL statements, and managing database metadata through natural language.
    7 npm
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Database management — connect, query, describe schemas, run migrations, and monitor active queries across PostgreSQL, MySQL, and SQLite.
    15
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides secure access to Supabase databases via PostgREST API and management tools for projects, schemas, branches, logs, and code generation.
    MIT