How to setup and use a Mysql MCP server in Cline

This comprehensive tutorial guides developers through the complete process of setting up and integrating a MySQL Model Context Protocol (MCP) server with the Cline AI coding agent in Visual Studio Code. The MCP server acts as a bridge that enables Cline to directly interact with MySQL databases through natural language queries, eliminating the need for manual SQL coding. By following this step-by-step guide, you'll learn how to download and build the MCP server from GitHub, configure it within your Cline environment, and establish secure database connections. Once configured, you can leverage Cline's AI capabilities to query, analyze, and manipulate database information using conversational commands, significantly streamlining database development workflows.

Overview
Overview

Install MCP server

To begin the MCP server installation, navigate to the GitHub repository page for the MySQL MCP server project. Locate the recent download history section on the right side of the repository page where you'll find the download options. Click on the highlighted download button to obtain the MCP server files from the repository.

Download MCP server from github
Figure 1 - Download MCP server from github

After downloading the MySQL MCP server archive from GitHub, locate the downloaded ZIP file in your downloads folder. Right-click on the archive file and select "Extract here" or "Extract to" from the context menu to unpack the contents. This will create a new folder containing all the necessary MCP server files including the source code and configuration files.

Extract mcp server folder
Figure 2 - Extract mcp server folder

Open a terminal or command prompt window and navigate to the extracted MySQL MCP server folder directory. Execute the "npm install" command to install all the required dependencies and packages for the MCP server. The installation process will download and configure all necessary Node.js modules as specified in the package.json file.

Npm install MCP server
Figure 3 - Npm install MCP server

After successfully installing the npm dependencies, run the "npm run build" command in the terminal within the MCP server directory. This command compiles the TypeScript source code and creates the production-ready build files in the appropriate directories. The build process ensures all modules are properly compiled and ready for use with Cline.

Build MCP server
Figure 4 - Build MCP server

Set MCP server in Cline

Open Visual Studio Code with the Cline extension installed and access the Cline interface from the sidebar. Click on the MCP server management icon located at the bottom right corner of the Cline panel to access server configuration options. This opens the MCP servers settings panel where you can add and configure new Model Context Protocol servers.

Manage MCP server in Cline
Figure 5 - Manage MCP server in Cline

In the MCP server configuration dialog, add a new server entry by specifying the MySQL MCP server details in JSON format. Enter the server configuration including the "mcpServers" object with the MySQL server details, command path pointing to the built server files, and necessary environment variables. Provide the database connection parameters such as host, port, user, password, and database name in the configuration file.

Configure MCP server
Figure 6 - Configure MCP server

Once the MCP server is configured in Cline, you can interact with your MySQL database through natural language queries in the chat interface. Type your database-related question or request in the Cline chat, such as asking about data in specific tables or requesting information from the database. Cline will process your request and use the MCP server to execute the appropriate SQL queries against your MySQL database.

Query database with AI
Figure 7 - Query database with AI

After submitting your database query through Cline, the MCP server connects to MySQL and executes the necessary SQL statements to retrieve the requested information. The results are processed and returned through the MCP protocol, and Cline displays a completion message confirming the task was successful. You'll see the query results and database information presented in a user-friendly format within the Cline chat interface.

Answer base on database
Figure 8 - Answer base on database

More information