Drizzle MCP Server
Provides database schema management, query execution, and schema introspection through Drizzle ORM and drizzle-kit CLI tools, supporting SQLite and PostgreSQL.
README
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
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
Option 3: Link for development (if working on the package)
# 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, ordrizzle.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
- drizzle_generate_migration - Generate new migration files
- drizzle_run_migrations - Apply pending migrations
- drizzle_introspect_schema - Introspect existing database schema
- execute_query - Execute raw SQL queries
- initialize_database - Initialize database connection
Available Resources
- database://tables - List all database tables
- 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.0drizzle-kit>= 0.30.0- For SQLite:
better-sqlite3>= 9.0.0 - For PostgreSQL:
pg>= 8.0.0 ORpostgres>= 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) orpostgres(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.localand.envfiles 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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。