HM

haticeguzell/multi-database-mcp-server

数据库管理

本页由 AI 翻译,技术细节请以原文为准。 查看原文

20 stars 4 forks 质量 61 趋势 37MIT

Read-only Model Context Protocol server for MySQL and PostgreSQL, built with TypeScript, TypeORM and Docker.

概览

A read-only Model Context Protocol (MCP) server built with TypeScript and TypeORM, providing a standardized way for AI applications to interact with MySQL and PostgreSQL databases. The server enables AI clients to discover database schemas and execute validated SQL queries through two MCP tools. - MySQL and PostgreSQL. - Retrieve table and column information without hardcoding database schemas. - Execute validated SELECT statements. - Restrict modification commands, dangerous operations, and multiple statements. - Automatically limit query results to a maximum of 100 rows. - Dedicated read-only users for the included Docker databases. - Run both databases and the MCP server without installing database servers locally. - rows: Query results. - rowCount: Number of returned rows. - executionTimeMs: Query execution time in milliseconds. The server connects to one configured database per instance.

README

以下为原文 README 节选,完整内容请查看原文。

Multi-Database MCP Server

English | Türkçe

A read-only Model Context Protocol (MCP) server built with TypeScript and TypeORM, providing a standardized way for AI applications to interact with MySQL and PostgreSQL databases.

The server enables AI clients to discover database schemas and execute validated SQL queries through two MCP tools.

Features

  • Multi-database support: MySQL and PostgreSQL.
  • Dynamic schema discovery: Retrieve table and column information without hardcoding database schemas.
  • Read-only querying: Execute validated SELECT statements.
  • SQL validation: Restrict modification commands, dangerous operations, and multiple statements.
  • Result limits: Automatically limit query results to a maximum of 100 rows.
  • Database-level protection: Dedicated read-only users for the included Docker databases.
  • Docker support: Run both databases and the MCP server without installing database servers locally.

MCP Tools

Tool Description
get_tables Returns the tables and column metadata of the connected database.
query Validates and executes read-only SELECT queries.

The query tool returns:

  • rows: Query results.
  • rowCount: Number of returned rows.
  • executionTimeMs: Query execution time in milliseconds.

The server connects to one configured database per instance.

Natural-language processing is handled by the connected AI application, not by the MCP server itself.

Architecture

User
  |
AI Application / LLM
  |
MCP Server
  |-- get_tables
  |-- query
  |     |
  |   SQL Validator
  |
Database Adapter
  |
MySQL / PostgreSQL

The project uses TypeORM for database connection and query management, with separate adapters for MySQL and PostgreSQL.

Requirements

  • Docker Desktop or Docker Engine with Compose
  • Node.js 22+ and npm for local tests and MCP Inspector

Local installation of MySQL or PostgreSQL is not required when using Docker.

Quick Start

The following commands are intended for Windows PowerShell. Run them from the repository root.

1. Configure the environment

Copy the example configuration:

Copy-Item .env.docker.example .env.docker

Open .env.docker and replace the four example passwords with your own local test passwords. Use letters, numbers, and underscores for simplest database URL compatibility. Never commit this private file.

2. Start the databases

docker compose --env-file .env.docker up -d --wait

Check their status:

docker compose --env-file .env.docker ps

Both MySQL and PostgreSQL should report a healthy status. Host ports default to 127.0.0.1:3307 (MySQL) and 127.0.0.1:5433 (PostgreSQL); adjust the optional ports in .env.docker if already occupied. The MCP containers use Docker-internal ports.

3. Build the MCP Docker image

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →