# executeautomation/mcp-database-server architecture

> Architecture diagram of the GitHub repository executeautomation/mcp-database-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/executeautomation/mcp-database-server
- Repository: https://github.com/executeautomation/mcp-database-server

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Claude Desktop Client"]:::client
    Client -->|"MCP Request"| CLI

    %% Command Parser Layer
    subgraph "CLI / Command Parser"
        CLI["CLI / Command Parser\n(index.ts)"]:::internal
    end
    click CLI "https://github.com/executeautomation/mcp-database-server/blob/main/index.ts"

    CLI -->|"initialize"| Core

    %% Core Layer
    subgraph "MCP Server Core"
        Core["Request Dispatcher & Bootstrap\n(src/index.ts)"]:::internal
    end
    click Core "https://github.com/executeautomation/mcp-database-server/blob/main/src/index.ts"

    Core -->|"dispatch"| ResourceHandlers
    Core -->|"dispatch"| ToolHandlers

    %% Handler Layer
    subgraph "Handler Layer"
        ResourceHandlers["Resource Handlers\n(src/handlers/resourceHandlers.ts)"]:::internal
        ToolHandlers["Tool Handlers\n(src/handlers/toolHandlers.ts)"]:::internal
    end
    click ResourceHandlers "https://github.com/executeautomation/mcp-database-server/blob/main/src/handlers/resourceHandlers.ts"
    click ToolHandlers "https://github.com/executeautomation/mcp-database-server/blob/main/src/handlers/toolHandlers.ts"

    ResourceHandlers -->|"invoke"| ToolsGroup
    ToolHandlers -->|"invoke"| ToolsGroup

    %% Tool Layer
    subgraph "Tool Layer"
        QueryTools["Query Tools\n(src/tools/queryTools.ts)"]:::internal
        SchemaTools["Schema Tools\n(src/tools/schemaTools.ts)"]:::internal
        InsightTools["Insight Tools\n(src/tools/insightTools.ts)"]:::internal
    end
    click QueryTools "https://github.com/executeautomation/mcp-database-server/blob/main/src/tools/queryTools.ts"
    click SchemaTools "https://github.com/executeautomation/mcp-database-server/blob/main/src/tools/schemaTools.ts"
    click InsightTools "https://github.com/executeautomation/mcp-database-server/blob/main/src/tools/insightTools.ts"

    QueryTools -->|"call Adapter Interface"| AdapterInterface
    SchemaTools -->|"call Adapter Interface"| AdapterInterface
    InsightTools -->|"call Adapter Interface"| AdapterInterface

    %% Adapter Layer
    subgraph "Adapter Layer"
        AdapterInterface["Adapter Interface\n(src/db/adapter.ts)"]:::internal
        MySQLAdapter["MySQL Adapter\n(src/db/mysql-adapter.ts)"]:::internal
        PostgresAdapter["PostgreSQL Adapter\n(src/db/postgresql-adapter.ts)"]:::internal
        SQLiteAdapter["SQLite Adapter\n(src/db/sqlite-adapter.ts)"]:::internal
        SQLServerAdapter["SQL Server Adapter\n(src/db/sqlserver-adapter.ts)"]:::internal
    end
    click AdapterInterface "https://github.com/executeautomation/mcp-database-server/blob/main/src/db/adapter.ts"
    click MySQLAdapter "https://github.com/executeautomation/mcp-database-server/blob/main/src/db/mysql-adapter.ts"
    click PostgresAdapter "https://github.com/executeautomation/mcp-database-server/blob/main/src/db/postgresql-adapter.ts"
    click SQLiteAdapter "https://github.com/executeautomation/mcp-database-server/blob/main/src/db/sqlite-adapter.ts"
    click SQLServerAdapter "https://github.com/executeautomation/mcp-database-server/blob/main/src/db/sqlserver-adapter.ts"

    AdapterInterface --> MySQLAdapter
    AdapterInterface --> PostgresAdapter
    AdapterInterface --> SQLiteAdapter
    AdapterInterface --> SQLServerAdapter

    MySQLAdapter -->|"SQL Query"| MySQLDB
    PostgresAdapter -->|"SQL Query"| PostgresDB
    SQLiteAdapter -->|"SQL Query"| SQLiteDB
    SQLServerAdapter -->|"SQL Query"| SQLServerDB

    %% Database Layer
    subgraph "External Databases"
        MySQLDB["MySQL"]:::db
        PostgresDB["PostgreSQL"]:::db
        SQLiteDB["SQLite File"]:::db
        SQLServerDB["SQL Server"]:::db
    end

    MySQLDB -->|"Result"| MySQLAdapter
    PostgresDB -->|"Result"| PostgresAdapter
    SQLiteDB -->|"Result"| SQLiteAdapter
    SQLServerDB -->|"Result"| SQLServerAdapter

    AdapterInterface -->|"wrap results"| ToolsGroup
    ToolsGroup -->|"format output"| HandlerResponse
    HandlerResponse["Handler Collects Result\n→ MCP Server Core"]:::internal
    HandlerResponse -->|"serialize"| Core
    Core -->|"response"| Client

    %% Utilities & Docs
    Util["Utility Functions\n(src/utils/formatUtils.ts)"]:::util
    Docs["Documentation Site\n(docs/)"]:::internal
    Docker["Dockerfile"]:::internal
    Build["build.sh"]:::internal

    Core -.-> Util
    CLI -.-> Docker
    CLI -.-> Build
    Docs -.-> CLI

    click Util "https://github.com/executeautomation/mcp-database-server/blob/main/src/utils/formatUtils.ts"
    click Docs "https://github.com/executeautomation/mcp-database-server/tree/main/docs/"
    click Docker "https://github.com/executeautomation/mcp-database-server/tree/main/Dockerfile"
    click Build "https://github.com/executeautomation/mcp-database-server/blob/main/build.sh"

    %% Styles
    classDef internal fill:#D6EAF8,stroke:#21618C
    classDef db fill:#D5F5E3,stroke:#196F3D
    classDef client fill:#EBDEF0,stroke:#7D3C98
    classDef util fill:#FCF3CF,stroke:#B7950B
```
