Skip to main content
Glama
MySQL MCP Server

MySQL MCP Server

by xiangma9712

Servidor MySQL MCP

Un servidor MCP para interactuar con bases de datos MySQL.

Este servidor admite la ejecución de consultas de solo lectura (consulta) y consultas de escritura que finalmente se revierten (test_execute).

Configuración

Variables de entorno

Agregue las siguientes variables de entorno a ~/.mcp/.env :

MYSQL_HOST=host.docker.internal  # Hostname to access host services from Docker container
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password

Nota : host.docker.internal es un nombre DNS especial para acceder a los servicios del equipo host desde contenedores Docker. Use esta configuración al conectarse a un servidor MySQL que se esté ejecutando en su equipo host. Si se conecta a otro servidor MySQL, cambie al nombre de host correspondiente.

Configuración de mcp.json

{
  "mcpServers": {
    "mysql": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--add-host=host.docker.internal:host-gateway",
        "--env-file",
        "/Users/username/.mcp/.env",
        "ghcr.io/xiangma9712/mcp/mysql"
      ]
    }
  }
}

Related MCP server: MCP MySQL Server

Uso

Iniciando el servidor

docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysql

Nota : Si usa OrbStack, host.docker.internal se admite automáticamente, por lo que puede omitir la opción --add-host . Aunque Docker Desktop también suele admitirlo automáticamente, se recomienda agregar la opción --add-host para una mayor fiabilidad.

Comandos disponibles

1. Ejecutar consulta de solo lectura

{
  "type": "query",
  "payload": {
    "sql": "SELECT * FROM your_table"
  }
}

Respuesta:

{
  "success": true,
  "data": [
    {
      "id": 1,
      "name": "example"
    }
  ]
}

2. Ejecución de la consulta de prueba

{
  "type": "test_execute",
  "payload": {
    "sql": "UPDATE your_table SET name = 'updated' WHERE id = 1"
  }
}

Respuesta:

{
  "success": true,
  "data": "The UPDATE SQL query can be executed."
}

3. Tablas de listas

{
  "type": "list_tables"
}

Respuesta:

{
  "success": true,
  "data": ["table1", "table2", "table3"]
}

4. Describir la tabla

{
  "type": "describe_table",
  "payload": {
    "table": "your_table"
  }
}

Respuesta:

{
  "success": true,
  "data": [
    {
      "Field": "id",
      "Type": "int(11)",
      "Null": "NO",
      "Key": "PRI",
      "Default": null,
      "Extra": ""
    },
    {
      "Field": "name",
      "Type": "varchar(255)",
      "Null": "YES",
      "Key": "",
      "Default": null,
      "Extra": ""
    }
  ]
}

Detalles de implementación

  • Implementado en TypeScript

  • Utiliza el paquete mysql2

  • Se ejecuta como un contenedor Docker

  • Acepta comandos JSON a través de la entrada estándar

  • Devuelve respuestas JSON a través de la salida estándar

  • Utiliza host.docker.internal para conectarse al host MySQL (compatible con OrbStack y Docker Desktop)

Consideraciones de seguridad

  • Utiliza variables de entorno para la gestión de información confidencial

  • La prevención de inyecciones SQL es responsabilidad del implementador

  • Se requiere una configuración de red adecuada para el uso en producción

  • Se necesitan configuraciones de firewall adecuadas al conectarse a los servicios de la máquina host

Available Tools

4 tools
describe_tableC

Retrieves column information for a table.

Inputs: tableName (required).

list_tablesB

Retrieves a list of tables in the database.

queryB

Executes a read-only SQL query.

Inputs: sql (required).

test_executeB

Checks if an SQL query can be executed and rolls back afterward.

Inputs: sql (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: describe_table for column metadata, list_tables for table enumeration, query for read-only SQL execution, and test_execute for query validation with rollback. There is no overlap in functionality, making tool selection straightforward for an agent.

    Naming Consistency4/5

    The naming follows a consistent verb_noun pattern (describe_table, list_tables, query, test_execute), with 'query' as a minor deviation as it lacks a noun suffix. Overall, the pattern is predictable and readable, though not perfectly uniform.

    Tool Count4/5

    With 4 tools, the count is reasonable for a database server, covering essential operations like listing tables, describing schema, querying, and testing queries. It is slightly lean but well-scoped, lacking only advanced features like write operations or transaction management.

    Completeness3/5

    The toolset covers basic read and validation operations but has notable gaps: there are no tools for data manipulation (e.g., insert, update, delete), schema modification (e.g., create_table), or transaction control. This limits the server to read-only and diagnostic tasks, which may cause agent failures for write workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI models to interact with MySQL databases through standardized operations including querying, executing commands, listing tables, and describing table structures with secure prepared statement support.
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables querying local MySQL databases and managing Docker containers (listing, logs) through natural language via the Model Context Protocol.
      4
      55 npm
      ISC