MySQL MCP Server
Enables interaction with MySQL databases through MCP tools for querying table structures, searching data across single or multiple tables, and managing database information. Built with FastMCP framework for secure database operations using environment-based configuration.
README
MySQL MCP Server
MySQL 데이터베이스 관리를 위한 MCP(Model Context Protocol) 서버입니다. FastMCP를 사용하여 개발되었으며, MySQL 데이터베이스의 테이블, 컬럼, 인덱스 정보를 조회하고 데이터를 검색할 수 있습니다.
🚀 주요 기능
📋 테이블 관리
- 테이블 목록 조회: 현재 데이터베이스의 모든 테이블 정보를 표 형태로 표시
- 컬럼 정보 조회: 특정 테이블의 컬럼 상세 정보를 표 형태로 표시
- 인덱스 정보 조회: 테이블에 설정된 인덱스 정보를 표 형태로 표시
🔍 데이터 검색
- 단일 테이블 검색: 특정 테이블에서 조건에 맞는 데이터 검색
- 다중 테이블 검색: 여러 테이블을 조인하여 복합 검색 수행
- 검색 결과 제한: 기본적으로 상위 10개 결과만 표시하여 성능 최적화
⚙️ 시스템 정보
- 데이터베이스 연결 정보: 서버 버전, 현재 데이터베이스, 연결 상태 등
- 환경 변수 기반 설정: 안전한 연결 정보 관리
📦 설치 방법
1. 필요한 모듈 설치
pip install -r requirements.txt
2. 환경 변수 설정
.env 파일을 생성하거나 환경 변수를 설정합니다:
# MySQL 연결 설정
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your_password_here
export MYSQL_DATABASE=your_database_name
# MCP 서버 설정
export MCP_SERVER_NAME=mysql-mcp
export MCP_SERVER_VERSION=1.0.0
또는 env_example.txt 파일을 참고하여 설정하세요.
🎯 사용 방법
1. MCP 서버 실행
python simple_mysql_mcp.py
2. 사용 가능한 도구들
테이블 목록 조회
show_tables()
현재 데이터베이스의 모든 테이블을 표 형태로 표시합니다.
테이블 컬럼 정보 조회
show_table_columns("테이블명")
지정된 테이블의 컬럼 상세 정보를 표 형태로 표시합니다.
테이블 데이터 검색
search_table("테이블명", "검색조건")
예시:
search_table("users")- 전체 데이터 조회search_table("users", "age > 25")- 조건에 맞는 데이터 검색search_table("users", "name = 'John'")- 특정 값 검색
다중 테이블 검색
search_multiple_tables(["테이블1", "테이블2"], "조인조건", "검색조건")
예시:
search_multiple_tables(["users", "orders"], "users.id = orders.user_id")search_multiple_tables(["users", "orders"], "users.id = orders.user_id", "orders.amount > 100")
인덱스 정보 조회
show_table_indexes("테이블명")
지정된 테이블의 인덱스 정보를 표 형태로 표시합니다.
데이터베이스 정보 조회
get_database_info()
현재 연결된 데이터베이스의 서버 정보와 연결 상태를 표시합니다.
🧪 테스트
기능 테스트를 위해 다음 명령어를 실행하세요:
python test_mysql_mcp.py
테스트는 다음 항목들을 확인합니다:
- 환경 변수 설정 상태
- FastMCP 모듈 import
- MySQL Connector 모듈 import
- MCP 서버 생성
- MySQL 연결 상태
🔧 기술 스택
- Python 3.7+: 메인 프로그래밍 언어
- FastMCP: MCP 서버 프레임워크
- MySQL Connector/Python: MySQL 데이터베이스 연결
- Environment Variables: 설정 관리
📁 파일 구조
simple_mysql_mcp/
├── simple_mysql_mcp.py # 메인 MCP 서버 파일
├── requirements.txt # 필요한 Python 모듈 목록
├── env_example.txt # 환경 변수 설정 예시
├── test_mysql_mcp.py # 기능 테스트 파일
└── README.md # 이 파일
🚨 주의사항
- 보안: 데이터베이스 비밀번호를 코드에 하드코딩하지 마세요.
- 권한: MCP 서버가 실행되는 사용자가 MySQL에 접근할 수 있는 권한을 가지고 있어야 합니다.
- 연결: MySQL 서버가 실행 중이어야 합니다.
- 데이터베이스:
MYSQL_DATABASE환경 변수를 설정하여 사용할 데이터베이스를 지정하세요.
🐛 문제 해결
연결 오류
- MySQL 서버가 실행 중인지 확인
- 호스트, 포트, 사용자명, 비밀번호가 올바른지 확인
- 방화벽 설정 확인
권한 오류
- MySQL 사용자가 해당 데이터베이스에 접근 권한을 가지고 있는지 확인
GRANT명령어로 권한 부여
모듈 오류
pip install -r requirements.txt실행- Python 버전이 3.7 이상인지 확인
📝 라이선스
이 프로젝트는 MIT 라이선스 하에 배포됩니다.
🤝 기여
버그 리포트나 기능 제안은 이슈로 등록해주세요. 풀 리퀘스트도 환영합니다.
MySQL MCP Server - MySQL 데이터베이스 관리를 위한 강력한 MCP 도구
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.