# dpflucas/mysql-mcp-server architecture

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

- Interactive diagram: https://gitdiagram.com/dpflucas/mysql-mcp-server
- Repository: https://github.com/dpflucas/mysql-mcp-server

## Overview

This repository is a read-only MySQL MCP server. An MCP client discovers and invokes database tools over stdio; the server dispatches each request, validates arbitrary SQL, executes it through a pooled MySQL connection, and returns rows as JSON text. The tools cover database listing, table listing, schema description, and read-only queries. The connection layer also applies timeouts, row limits, and exact large-number handling. Relationships are based on the shown entry point and connection/validator source; README capability descriptions supplement the documented tool surface.

Main entry points: [`src/index.ts`](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts) (MCP entrypoint), [`src/connection.ts`](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts) (Query execution), [`src/validators.ts`](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/validators.ts) (SQL validator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["MCP server"]
  node_entry["MCP entrypoint<br/>[index.ts]"]
  node_tool_catalog["Tool discovery<br/>[index.ts]"]
  node_tool_dispatch["Tool dispatch<br/>[index.ts]"]
  node_result_format["Result formatting<br/>[index.ts]"]
  node_stdio["Stdio transport<br/>[index.ts]"]
end

subgraph group_access["Database access"]
  node_config["Environment config<br/>[connection.ts]"]
  node_pool["Connection pool<br/>[connection.ts]"]
  node_query_exec["Query execution<br/>[connection.ts]"]
end

subgraph group_safety["Query safety"]
  node_validator["SQL validator<br/>[validators.ts]"]
end

node_client(("MCP client"))
node_mysql[("MySQL database")]

node_client -->|"sends requests"| node_stdio
node_entry -->|"registers tools"| node_tool_catalog
node_entry -->|"handles calls"| node_tool_dispatch
node_entry -->|"connects transport"| node_stdio
node_tool_dispatch -->|"validates SQL"| node_validator
node_tool_dispatch -->|"executes tools"| node_query_exec
node_tool_dispatch -->|"formats rows"| node_result_format
node_entry -->|"loads settings"| node_config
node_entry -->|"creates pool"| node_pool
node_query_exec -->|"acquires connection"| node_pool
node_query_exec -->|"runs SQL"| node_mysql
node_pool -->|"connects"| node_mysql
node_stdio -->|"returns responses"| node_client

click node_entry "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts"
click node_tool_catalog "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts"
click node_tool_dispatch "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts"
click node_result_format "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts"
click node_stdio "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts"
click node_validator "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/validators.ts"
click node_config "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts"
click node_pool "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts"
click node_query_exec "https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_tool_catalog,node_tool_dispatch,node_result_format,node_stdio,node_client toneBlue
class node_config,node_pool,node_query_exec,node_mysql toneAmber
class node_validator toneMint
```

## Components

### MCP server

- [MCP entrypoint](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts): `src/index.ts`
- [Tool discovery](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts): `src/index.ts`
- [Tool dispatch](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts): `src/index.ts`
- [Result formatting](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts): `src/index.ts`
- [Stdio transport](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/index.ts): `src/index.ts`

### Database access

- [Environment config](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts): `src/connection.ts`
- [Connection pool](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts): `src/connection.ts`
- [Query execution](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/connection.ts): `src/connection.ts`

### Query safety

- [SQL validator](https://github.com/dpflucas/mysql-mcp-server/blob/main/src/validators.ts): `src/validators.ts`

### Other components

- **MCP client**
- **MySQL database**

## Connections

- MCP client → Stdio transport: sends requests (evidence: `src/index.ts`)
- MCP entrypoint → Tool discovery: registers tools (evidence: `src/index.ts`)
- MCP entrypoint → Tool dispatch: handles calls (evidence: `src/index.ts`)
- MCP entrypoint → Stdio transport: connects transport (evidence: `src/index.ts`)
- Tool dispatch → SQL validator: validates SQL (evidence: `src/index.ts`)
- Tool dispatch → Query execution: executes tools (evidence: `src/index.ts`)
- Tool dispatch → Result formatting: formats rows (evidence: `src/index.ts`)
- MCP entrypoint → Environment config: loads settings (evidence: `src/index.ts`)
- MCP entrypoint → Connection pool: creates pool (evidence: `src/index.ts`)
- Query execution → Connection pool: acquires connection (evidence: `src/connection.ts`)
- Query execution → MySQL database: runs SQL (evidence: `src/connection.ts`)
- Connection pool → MySQL database: connects (evidence: `src/connection.ts`)
- Stdio transport → MCP client: returns responses (evidence: `src/index.ts`)
