JoyfulSQL_MCP
A Model Context Protocol (MCP) server that allows AI assistants like Cascade to interact with both local and remote MySQL databases.
MySQL MCP Server
A Model Context Protocol (MCP) server that allows AI assistants like Cascade to interact with both local and remote MySQL databases.
Quick Start
Installation
- Clone the repository
- Install dependencies
- Build the server
npm install
npm run build
Features
- Connect to local MySQL databases
- Connect to remote MySQL databases via SSH tunneling (ODI)
- Execute read-only or read-write queries (configurable)
- Secure access through SSH tunneling for remote databases
- Automatic database detection and listing when no database is specified
- Interactive workflow that waits for user to select a database before proceeding
Setup
Prerequisites
- Node.js
- Local MySQL database (optional)
- SSH access to remote MySQL databases (optional)
- SSH client installed on your local machine (for ODI connections)
Usage
Using with Cascade
Cascade can automatically start and manage the server. Configure Cascade by adding this to your MCP configuration:
{
"mcpServers": {
"mysql": {
"command": "node",
"args": [
"/path/to/your/server/build/index.js",
"--env-file",
"/path/to/your/env"
]
},
}
}
Running Locally
You can also run the server directly:
node build/index.js
ENV
LOCAL_HOST=[host]
LOCAL_USER=[user]
LOCAL_PASSWORD=[password]
LOCAL_PORT=[port]
ODI_SSH_KEY=[path/to/ssh/key]
ODI_USER=[user]
ODI_PASSWORD=[password]
ODI_HOST=[host]
ODI_PORT=[port]
ODI_SSH_PORT=[ssh_tunnel_port]
WRITE_ACCESS=[bool]
Available Tools
This MCP server provides two main tools:
-
local_mysql_query - Execute queries on your local MySQL database
Parameters: - sql: SQL query to execute - database: (optional) Database to query - if not specified, will show available databases - params: (optional) Parameters for the SQL query
-
odi_mysql_query - Execute queries on remote MySQL databases via SSH tunnel
Parameters: - sql: SQL query to execute - database: (optional) Database to query - if not specified, will show available databases - sshHost: SSH host to connect through (e.g., "171831.bjoyner.pandasandbox.com") - params: (optional) Parameters for the SQL query
Examples
Interactive Database Selection
When no database is specified, the server will:
- List all available databases on the target MySQL server
- Halt execution and wait for the user to specify a database
- Require the user to run the tool again with the
database
parameter explicitly set
This interactive workflow prevents executing queries without a properly selected database and gives the user clear guidance on how to proceed.
List all available databases
// Using the local_mysql_query tool without specifying a database
sql: "SHOW TABLES;"
// Using the odi_mysql_query tool without specifying a database
sql: "SHOW TABLES;"
sshHost: "your-odi-host.example.com"
List all databases on an ODI server
// Using the odi_mysql_query tool
sql: "SELECT SCHEMA_NAME FROM SCHEMATA;"
database: "information_schema"
sshHost: "your-odi-host.example.com"
Query a specific database on ODI
// Using the odi_mysql_query tool
sql: "SELECT * FROM your_table LIMIT 10;"
database: "your_database_name"
sshHost: "your-odi-host.example.com"
Query a specific database locally
// Using the local_mysql_query tool
sql: "SELECT * FROM your_table LIMIT 10;"
database: "your_database_name"
Security
This server is intended for local development only. Do not expose it to the internet without proper security measures. The SSH tunneling provides an additional layer of security for remote database access.
Notes on SSH Tunneling
When using the odi_mysql_query
tool, the server will establish an SSH tunnel to the remote host. This requires:
- SSH client installed on your local machine
- Proper SSH configuration (keys, known_hosts, etc.)
- SSH access to the remote host
The SSH tunnel will be automatically established when you make a query and closed when the server shuts down.
Related MCP Servers
View all databases servers →mindsdb
by mindsdb
MindsDB is an open-source server that enables seamless interaction with large-scale federated data using the Model Context Protocol (MCP).
prisma
by prisma
Prisma is a next-generation ORM for Node.js and TypeScript, providing tools for data modeling, migrations, and querying databases.
supabase-mcp
by supabase-community
Connect your Supabase projects to AI assistants using the Model Context Protocol (MCP) server.
postgres-mcp
by crystaldba
Postgres MCP Pro is an open-source Model Context Protocol server designed to enhance database performance and management through advanced tools and features.
mariadb-mcp-server
by rjsalgado
This MCP server provides access to MariaDB / MySQL databases, allowing users to list databases, tables, describe table schemas, and execute SQL queries with security features.
genai-toolbox
by googleapis
MCP Toolbox for Databases is an open source MCP server for databases, designed to simplify and secure the development of database tools.
azure-mcp
by Azure
The Azure MCP Server implements the MCP specification to create a seamless connection between AI agents and Azure services.