MCP cover image
See in Github
2025-03-09

使用Python构建的MySQL的轻巧MCP服务器

1

Github Watches

1

Github Forks

0

Github Stars

Simple MCP MySQL Server

A lightweight Model Context Protocol (MCP) server that enables secure interaction with MySQL databases. This server allows AI assistants like Claude to list tables, read data, and execute SQL queries through a controlled interface.

Features

  • List all MySQL tables in the database
  • Retrieve detailed schema information for all tables
  • Execute read-only SQL queries with proper error handling
  • Secure database access through environment variables
  • Simple configuration and deployment

Installation

# Clone the repository
git clone git@github.com:alexcc4/mcp-mysql-server.git
cd mysql-mcp-server

# Install dependencies using uv (recommended)
uv sync

Configuration

Set the following environment variables:

  • export DB_HOST=localhost # Database host
  • export DB_PORT=3306 # Database port (defaults to 3306 if not specified)
  • export DB_USER=your_username # Database username
  • export DB_PASSWORD=your_password # Database password
  • export DB_NAME=your_database # Database name

Usage

Manual Start

uv run main.py

With Claude Desktop

Add this to your Claude Desktop configuration file:

Mac Claude Desktop config: ~/Library/Application Support/Claude/claude_desktop_config.json (create it if it doesn't exist)

{
    "mcpServers": {
        "sql": {
            "command": "/path/uv",
            "args": [
                "--directory",
                "code_path",
                "run",
                "main.py"
            ],
            "env": {
                "DB_HOST": "127.0.0.1",
                "DB_PORT": "3306",
                "DB_USER": "your_user",
                "DB_PASSWORD": "your_password",
                "DB_NAME": "your_database"
           }
        }
    }
}

Example Queries

Once configured, you can ask Claude questions like:

"Show me all tables in the database"
"Top 10 rows from users table"
"Find all orders placed in the last 30 days"
"Count of users by country"
"Show me the schema of the products table"

Available Resources

The server provides the following resources:

  • mysql://schema - Complete database structure information including all tables and columns
  • mysql://tables - List of all tables in the database

Available Tools

The server provides the following tools:

  • query_data - Execute read-only SQL queries and return results

Requirements

  • uv (recommended)
  • Python 3.12.2+
  • MySQL server

Security Considerations

  • Use a database user with minimal required permissions (read-only)
  • Never use root credentials for production environments
  • Consider implementing query whitelisting for sensitive databases
  • Monitor and log all database operations

License

MIT

Reference

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • modelcontextprotocol
  • 模型上下文协议服务器

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

    Reviews

    5 (1)
    Avatar
    user_q0yOQji3
    2025-04-15

    UML-MCP: A Diagram Generation Server with MCP Interface is a fantastic tool for developers and designers who need to create UML diagrams effortlessly. The integration with MCP makes the whole process swift and efficient, and the server's reliability is top-notch. Antoinebou12 has done an excellent job with this tool, and I highly recommend checking it out! Here's the link: https://mcp.so/server/uml-mcp/antoinebou12.