Sponsored by Deepsite.site

MySQL MCP Server

Created By
sajithamma7 months ago
Content

MySQL MCP Server

A powerful database management tool built with FastMCP that provides an interactive interface for managing SQLite databases. This project includes both a server component and a client interface for easy database operations.

Features

  • List all tables in the database
  • Get detailed schema information for any table
  • Execute SQL queries with formatted results
  • Interactive client interface for database operations

Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)

Setup

  1. Clone the repository:
git clone git@github.com:sajithamma/mysql-mcp-server.git
cd mysql-mcp-server
  1. Create and activate a virtual environment:
# Create virtual environment
python3.12 -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the fixture to create the database:
python sqlite_fixture.py

Project Structure

The project consists of two main components:

  1. mcpserver.py - The MCP server implementation
  2. mcpclient.py - The client interface

Server Component

The server provides the following tools:

@mcp.tool()
def list_tables() -> List[str]:
    """List all tables in the SQLite database."""
    # Implementation details...

@mcp.tool()
def describe_table(table_name: str) -> Dict[str, Any]:
    """Get the schema information for a specific table."""
    # Implementation details...

@mcp.tool()
def run_query(query: str) -> Dict[str, Any]:
    """Execute a SQL query and return the results."""
    # Implementation details...

Client Component

The client provides an interactive interface for database operations:

async def main():
    server = MCPServerSse(
        name="SQLite Database Manager",
        params={
            "url": "http://localhost:8000/sse",
        },
    )
    # Client implementation...

Running the Application

  1. Start the MCP server:
fastmcp run mcpserver.py:mcp --transport sse --host 127.0.0.1 --port 8000
  1. In a separate terminal, run the client:
python mcpclient.py

Usage

Once both the server and client are running, you can interact with the database using natural language commands. The client supports the following operations:

  1. List all tables in the database
  2. Get detailed schema information for any table
  3. Execute SQL queries to retrieve or modify data

Example commands:

  • "Show me all tables in the database"
  • "Describe the structure of the users table"
  • "Run a query to select all records from the users table"

Environment Variables

Create a .env file in the project root with the following variables:

# Add any required environment variables here

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
WindsurfThe new purpose-built IDE to harness magic
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
DeepChatYour AI Partner on Desktop
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Serper MCP ServerA Serper MCP Server
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
CursorThe AI Code Editor
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Playwright McpPlaywright MCP server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.