mysql-mcp-server

mysql-mcp-server

7

The MySQL MCP Service is an API designed for direct MySQL database access by Cursor AI, utilizing the MCP protocol to facilitate SQL operations and data retrieval. Notable features include real-time data access, secure connections, and standardized API responses for seamless integration.

MySQL MCP Service Overview

MySQL MCP Service is an API service developed using Node.js, designed to provide the Cursor AI with the ability to access MySQL databases directly. The service follows the Model Control Platform (MCP) protocol, allowing the AI to execute SQL queries, retrieve table structure information, and perform data operations via a standardized interface.

Features

  • SQL Query Execution: Supports execution of SQL statements (SELECT, INSERT, UPDATE, DELETE, etc.)
  • Table Structure Inquiries: Retrieves detailed database table structures
  • Real-time Data Access: Allows AI real-time database access
  • Secure Connection: Configurable database connection parameters
  • Cross-Domain Support: Built-in CORS for easy front-end integration
  • Standardized Response: Unified API response format
  • MCP Protocol Support: Fully implements MCP protocol for easy integration with Cursor AI

Technology Stack

  • Node.js environment
  • Express.js framework
  • mysql2 database driver
  • dotenv for environment variables
  • cors for cross-origin support

Installation and Deployment

Prerequisites
  • Node.js 14.x or higher
  • MySQL database connection
  • Git (optional)
Installation Steps
  1. Clone the repository and navigate to the directory
  2. Install dependencies
  3. Configure environment variables in a .env file
  4. Start the service in development or production mode

API Documentation

Main Endpoints
  • MCP Manifest: /manifest.json
  • OpenAPI Specification: /openapi.yaml
  • SQL Query: /api/mysql/query
  • Table Structure Query: /api/mysql/schema
  • DDL Query: /api/mysql/ddl

Usage in Cursor

  1. Open the Cursor editor
  2. Add a new MCP service
  3. Enter the service URL
  4. Save and activate the service

Troubleshooting

  • Service not starting: Check the port, Node.js version, or logs
  • Database connection failed: Verify connection information and firewall settings
  • API request failure: Check request format and server logs