How to set up an MCP Server in Open Code
This guide demonstrates how to integrate a MySQL MCP server with Open Code, enabling the AI assistant to read and write to your MySQL database through natural language commands. You will build the server, add it to the Open Code configuration, and verify the connection by running a series of database operations.
What is an MCP server?
An MCP (Model Context Protocol) server exposes a set of callable tools to an AI model during a session. The MySQL MCP server used in this guide provides tools for querying data, creating tables, and inserting records. Open Code invokes the server as a local subprocess, passing your database credentials as environment variables defined in the configuration file.
Steps to follow
We assume Open Code is already installed on your system. If you haven't installed Open Code, check out our How to run OpenCode with Ozeki AI Gateway guide.
- Download and build the MySQL MCP server
- Configure the MCP server in Open Code
- Test the database tools
Quick reference
# Install dependencies and build the MCP server
npm install
npm run build
# Open Code configuration file location
C:\Users\{User}\.config\opencode\opencode.json
# MCP server configuration block to add to opencode.json
{
"mcp": {
"mysql-mcp-server": {
"type": "local",
"command": [
"node",
"C:\\path\\to\\mysql-mcp-server\\build\\index.js"
],
"environment": {
"MYSQL_HOST": "your-mysql-host",
"MYSQL_PORT": "your-mysql-port",
"MYSQL_USER": "your-mysql-user",
"MYSQL_PASSWORD": "your-mysql-password",
"MYSQL_DATABASE": "your-database-name"
}
}
}
}
How to install the MySQL MCP server video
The following video shows how to download, build, and prepare the MySQL MCP server for use with Open Code. The video covers downloading the repository, extracting the files, and compiling the server with npm.
Step 1 - Download and build the MySQL MCP server
Go to the MySQL MCP server repository on GitHub, click the Code button, and select Download ZIP to save the repository to your machine (Figure 1).
Extract the ZIP file to a location of your choice. The folder will contain the TypeScript source code and project configuration files needed to build the server (Figure 2).
Open a terminal in the extracted folder. Right-click inside the folder and choose Open in Terminal, or navigate to it manually from an existing terminal window (Figure 3).
Run npm install to fetch and install all required packages.
Wait for the installation to complete before proceeding (Figure 4).
npm install
Run npm run build to compile the project. The resulting
build/index.js file is what Open Code will execute as the MCP server
process (Figure 5).
npm run build
Step 2 - Configure the MCP server in Open Code
The following video shows how to add the MySQL MCP server to the Open Code configuration and verify the database tools are working correctly.
Navigate to C:\Users\{User}\.config\opencode\ and open or create the
opencode.json configuration file in a text editor. (Figure 6).
Add the MySQL MCP server entry to the mcp block. Note that Open Code
uses a slightly different schema from other tools - the server is defined with a
type field set to "local" and the command is specified as
an array rather than separate command and args properties.
Replace the path and database credentials with your own values, then save the file (Figure 7).
{
"mcp": {
"mysql-mcp-server": {
"type": "local",
"command": [
"node",
"C:\\path\\to\\mysql-mcp-server\\build\\index.js"
],
"environment": {
"MYSQL_HOST": "your-mysql-host",
"MYSQL_PORT": "your-mysql-port",
"MYSQL_USER": "your-mysql-user",
"MYSQL_PASSWORD": "your-mysql-password",
"MYSQL_DATABASE": "your-database-name"
}
}
}
}
Launch Open Code from your terminal. It will load the configuration file, start the MySQL MCP server as a subprocess, and make its tools available for the current session (Figure 8).
Step 3 - Test the database tools
Begin by asking Open Code to retrieve records from your database. The assistant will invoke the query tool from the MySQL MCP server and display the results (Figure 9).
Show me all users from the database.
The returned results confirm that Open Code has successfully connected to your MySQL database through the MCP server and can execute read operations (Figure 10).
Next, ask Open Code to create a new table in your database. It will use the MCP
server to generate and execute the appropriate CREATE TABLE statement (Figure 11).
Create a table called "employees" in the database with columns for id, name, position, and salary.
Ask the assistant to populate the table with sample records. Describe the data in natural language and Open Code will translate it into the correct INSERT statements and execute them through the MCP server (Figure 12).
Insert these three rows into the employees table: Alice - Developer - 850000, Bob - Designer - 720000, Charlie - Manager - 950000.
Complete the test by running a filtered query. The response will confirm that the full workflow is functioning correctly end to end (Figure 13).
Query the database and show me all employees who earn more than 800000.
To sum it up
You have successfully configured a MySQL MCP server in Open Code and verified that all database tools are working. With this integration in place, Open Code can now interact with your MySQL database directly through natural language, executing queries, creating tables, and managing data without requiring any manual SQL input.