How executeautomation/mcp-database-server works
Project type and purpose
• This is a Node.js/TypeScript-based MCP (Model Context Protocol) Database Server that acts as a CLI/daemon providing database access (SQLite, SQL Server, PostgreSQL, MySQL) to the Claude AI agent. It’s an open-source tool rather than a monolithic full-stack application.
File structure
• Top-level:
• src/ – the implementation, subdivided into db/, handlers/, tools/, utils/
• index.ts – the CLI entrypoint and server bootstrap
• Dockerfile, build scripts – deployment/build artifacts
• docs/ – static website (Docusaurus) for user/reference documentation
• src/db/adapter.ts plus mysql-, postgresql-, sqlite-, sqlserver-adapter.ts implement a Strategy/Adapter pattern for each database engine.
• src/handlers/ define generic MCP “resource” and “tool” handlers that map incoming MCP calls to tool implementations.
• src/tools/ implement the concrete database operations (read_query, write_query, etc.).
• src/utils/ are helpers (formatting, logging, etc.).
README for additional insights
• The server is invoked via CLI arguments or “mcpServers” configuration in Claude Desktop.
• It exposes a fixed set of “tools” (read_query, create_table, etc.) which follow a command → handler → adapter → database workflow.
• CLI / Command Parser (index.ts + yargs or custom arg parsing)
• MCP Server Core – request dispatcher that listens for MCP calls from Claude
• Handler Layer
– ResourceHandlers (e.g. connection management)
– ToolHandlers (routes MCP “tool” calls to tool implementations)
• Tool Layer (src/tools/) – implementations of read_query, write_query, etc.
• Adapter Layer (src/db/*-adapter.ts) – Strategy implementations for each database
• External Databases – SQLite file, SQL Server, PostgreSQL, MySQL
• External Client – Claude Desktop / Claude Agent
1. Claude Desktop issues an MCP request → CLI / Command Parser
2. Parser initializes MCP Server Core → dispatches to the appropriate Handler
3. Handler invokes a Tool implementation → passes high-level params
4. Tool calls Adapter (via Adapter interface) → translates to SQL + driver library
5. Adapter opens connection → executes SQL against the external Database
6. Database returns results → Adapter wraps results → Tool formats output
7. Handler collects result → MCP Server Core serializes → returns to Claude
c. Architectural patterns & design principles
– Adapter/Strategy pattern for database engines
– Layered architecture (Command Parser → Handlers → Tools → Adapters → DB)
– Single Responsibility: each module has a clear concern (parsing, dispatching, business logic, persistence)
– Extensibility: adding a new database only requires implementing the Adapter interface
d. Key technologies
– Node.js (v18+), TypeScript
– npm scripts for build/dev (build.sh, Dockerfile)
– SQL driver libraries (mssql, pg, mysql2, sqlite3)
– Docusaurus for documentation (docs/ folder)