db-mcp-server
If you are the rightful owner of db-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project is a Model Context Protocol (MCP) Stdio server compatible with Cursor IDE, designed to return the table structure and relationships of MySQL or MariaDB databases.
MCP Stdio Server (MySQL/MariaDB)
์ด ํ๋ก์ ํธ๋ Cursor IDE์ ์ฐ๋ ๊ฐ๋ฅํ Model Context Protocol (MCP) Stdio ์๋ฒ์ ๋๋ค. MySQL ๋๋ MariaDB ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ํ ์ด๋ธ ๊ตฌ์กฐ์ ๊ด๊ณ๋ฅผ ๋ฐํํฉ๋๋ค.
โ ๊ธฐ๋ฅ
- MCP ๊ณต์ Python SDK ๊ธฐ๋ฐ
stdio
๋ชจ๋๋ก Cursor IDE ์ฐ๋.env
ํ์ผ ๊ธฐ๋ฐ DB ์ค์ - ํ ์ด๋ธ ๋ชฉ๋ก, ์ปฌ๋ผ, ์ธ๋ํค ๊ด๊ณ ๋ฐํ
- ๋ฐ์ดํฐ ์กฐํ ๋ฐ ๋ถ์ ๊ธฐ๋ฅ
- ์ฟผ๋ฆฌ ์คํ ๋ฐ ์ต์ ํ ๊ธฐ๋ฅ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ชจ๋ํฐ๋ง ๊ธฐ๋ฅ
- ์ฑ๋ฅ ๋ถ์ ๋ฐ ์ต์ ํ ์ ์
๐ฆ ์ค์น
git clone <this-repo-url>
cd db-mcp-server
python -m venv venv
source venv/bin/activate # ๋๋ venv\Scripts\activate (Windows)
pip install -r requirements.txt
โ๏ธ .env ์ค์
๋ฃจํธ์ .env
ํ์ผ์ ์๋์ ๊ฐ์ด ์์ฑํ์ธ์:
# Database connection settings for MCP Python server
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=your_db
DB_CHARSET=utf8mb4
๐ ์คํ
Cursor IDE์์ MCP Server
์ถ๊ฐ > Transport: stdio
> Command: python main.py
Cursor IDE์ MCP ์๋ฒ ์ถ๊ฐ์ JSON env ํ๊ฒฝ๊ฐ์ ์ ๋ฌํ์ฌ ํ๋ก์ ํธ๋ณ DB ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ๊ฐ๋ณ์ ์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค.
๐ก ์ง์ ๋ฉ์๋
์คํค๋ง ์กฐํ
mysql.get_schema
: ๋ชจ๋ ํ ์ด๋ธ ๊ตฌ์กฐ + ์ธ๋ํค ๋ฐํ
๋ฐ์ดํฐ ์กฐํ ๋ฐ ๋ถ์
mysql.get_table_stats
: ํ ์ด๋ธ๋ณ ํต๊ณ ์ ๋ณด (ํ ์, NULL ๊ฐ ๋น์จ, ๊ณ ์ ๊ฐ ์)mysql.get_sample_data
: ํ ์ด๋ธ์ ์ํ ๋ฐ์ดํฐ ์กฐํmysql.get_column_stats
: ํน์ ์ปฌ๋ผ์ ์์ธ ํต๊ณ ์ ๋ณด
์ฟผ๋ฆฌ ์คํ ๋ฐ ์ต์ ํ
mysql.execute_query
: ์์ ํ ์ฝ๊ธฐ ์ ์ฉ ์ฟผ๋ฆฌ ์คํmysql.explain_query
: ์ฟผ๋ฆฌ ์คํ ๊ณํ ๋ถ์mysql.optimize_query
: ์ฟผ๋ฆฌ ์ต์ ํ ์ ์
๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ชจ๋ํฐ๋ง
mysql.get_db_status
: ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ํ ์ ๋ณด (์ฐ๊ฒฐ ์, ์ฟผ๋ฆฌ ํต๊ณ ๋ฑ)mysql.get_table_size
: ํ ์ด๋ธ๋ณ ํฌ๊ธฐ ์ ๋ณดmysql.get_index_usage
: ์ธ๋ฑ์ค ์ฌ์ฉ ํต๊ณ
์ฑ๋ฅ ๋ถ์
mysql.analyze_performance
: ์ฑ๋ฅ ๋ณ๋ชฉ ์ง์ ๋ถ์mysql.suggest_indexes
: ์ธ๋ฑ์ค ์์ฑ ์ ์mysql.optimize_tables
: ํ ์ด๋ธ ์ต์ ํ ์ ์
๐ ์์ ๊ฒฐ๊ณผ
์คํค๋ง ์กฐํ
{
"schema": {
"users": {
"columns": [...],
"foreign_keys": [...]
}
}
}
ํ ์ด๋ธ ํต๊ณ
{
"table_name": "users",
"total_rows": 1000,
"column_stats": {
"id": {
"total_rows": 1000,
"null_count": 0,
"null_ratio": 0.0,
"unique_values": 1000
}
}
}
์ฟผ๋ฆฌ ์คํ ๊ณํ
{
"explain_plan": [...],
"handler_stats": {...},
"suggestions": [
{
"type": "index",
"message": "์ ๋ ฌ ์์
์ด ๋ฐ์ํ๊ณ ์์ต๋๋ค. ORDER BY ์ ์ ์ฌ์ฉ๋ ์ปฌ๋ผ์ ๋ํ ์ธ๋ฑ์ค ์ถ๊ฐ๋ฅผ ๊ณ ๋ คํ์ธ์."
}
]
}
์ฑ๋ฅ ๋ถ์
{
"slow_queries": 5,
"bottlenecks": [
{
"type": "large_table",
"table": "orders",
"rows": 1500000,
"message": "ํ
์ด๋ธ 'orders'์ด(๊ฐ) 1,500,000๊ฐ์ ํ์ ๊ฐ์ง๊ณ ์์ต๋๋ค. ํํฐ์
๋์ ๊ณ ๋ คํ์ธ์."
}
],
"recommendations": [...]
}
โ ์๊ตฌ์ฌํญ
- Python 3.8+
- MySQL/MariaDB
๐ ๏ธ Cursor IDE์์ MCP ์๋ฒ ์ฌ์ฉ๋ฒ
Cursor IDE์์ MCP Server๋ฅผ ํ๋ก์ ํธ๋ณ๋ก ๋ฑ๋กํ ๋, ์๋์ ๊ฐ์ด ํ๊ฒฝ๋ณ์๋ฅผ JSON ํํ๋ก ์ ๋ฌํ์ฌ ๊ฐ ํ๋ก์ ํธ๋ณ DB ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ๊ฐ๋ณ์ ์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค.
์์:
{
"mcpServers": {
"db-mcp-server": {
"transport": "stdio",
"command": "/path/to/venv/bin/python",
"args": ["/path/to/db-mcp-server/main.py"],
"env": {
"DB_NAME": "your_db_name"
}
}
}
}
env
ํญ๋ชฉ์ DB ์ฐ๊ฒฐ์ ํ์ํ ํ๊ฒฝ๋ณ์(DB_HOST
,DB_USER
,DB_PASSWORD
,DB_NAME
๋ฑ)๋ฅผ ์์ ๋กญ๊ฒ ์ง์ ํ ์ ์์ต๋๋ค.- ์ด ๋ฐฉ์์ผ๋ก ์ฌ๋ฌ ํ๋ก์ ํธ์์ ๊ฐ๊ธฐ ๋ค๋ฅธ DB์ ์ฐ๊ฒฐํ์ฌ ์ฌ์ฉํ ์ ์์ต๋๋ค.