Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

SQL Script Creation and Execution

Have an AI coding agent write a MariaDB schema create script, run it on a sandbox instance or a configured server, and verify the result with the db and sandbox tools of the mariadb-shell MCP server.

With MariaDB AI Plugins, you can ask a coding agent to write a SQL script that creates a database schema, and then to run the script on a MariaDB server and check the result. The agent writes the script with the help of the SQL skills, and runs and verifies it with the db.* and sandbox.* tools of the MCP server.

This page describes the three steps of this workflow: creating the script, running it, and verifying the result.

Requirements

  • The dev or sql plugin. Both include the skills and the MCP server.

  • A working folder on the allowed-paths list of the MCP server. The agent saves the script there, and the MCP server reads it from there.

  • A MariaDB server to run the script on: either a sandbox instance, which the agent can deploy itself, or a connection that you configured with mcp setup.

Skills and Tools

Skills
Tools

mariadb-schema-create-script, plus the SQL statement skills it refers to, such as mariadb-create-database, mariadb-create-table, mariadb-create-index, and mariadb-create-view

sandbox.deploy, db.list_connections, db.connect, db.execute_sql_script, db.list_schemas, db.list_objects, db.get_object_details, db.execute_sql, db.close

Create the Script

Start the agent in your working folder, and describe the schema and the name of the script file:

Create a MariaDB database schema named notes_app for a note-taking app and
store it in a notes_app.sql file.

This step only creates a file; it doesn't need a database connection. Before it writes the script, the agent reads the mariadb-schema-create-script skill, which is maintained in the MariaDB AI Plugins repository. This skill defines the structure of the script and refers the agent to the SQL statement skills from the MariaDB documentation, such as mariadb-create-database, mariadb-create-table, mariadb-create-index, and mariadb-create-view. These skills describe the MariaDB-specific syntax of each statement.

A script that follows the skill has these characteristics:

  • It starts with a block that saves the current session settings, disables unique and foreign key checks, sets the SQL mode, and switches to utf8mb4. It ends with a block that restores the saved settings.

  • It creates the schema with CREATE SCHEMA IF NOT EXISTS, and the tables with CREATE OR REPLACE TABLE.

  • Tables whose rows are exposed to client applications use the native UUID data type for their primary key, with UUID_v7() as the default value.

  • Each schema object has a comment that describes its purpose.

  • INSERT statements for sample or initial data come after the statements that create the schema objects.

You can refine the script in further requests, for example to add a full-text index or row history for a table. The agent reads the relevant skills again for each change.

If you plan to run the script on a server where the schema has a different name, ask the agent to use fully qualified object names, such as `notes_app`.`note`, so that the script doesn't depend on the current schema of the session.

Run the Script

To run the script, the agent needs a MariaDB server. For development and testing, a sandbox instance on your machine is a good choice:

The agent completes this request with the following tool calls:

  1. sandbox.deploy deploys and starts a MariaDB Server instance on port 3310, and registers the connection root@127.0.0.1:3310 with the MCP server.

  2. db.connect opens this connection and returns a connection ID.

  3. db.execute_sql_script reads notes_app.sql from the working folder and runs its statements in order on the connection.

db.execute_sql_script returns one result for each statement. A statement that fails doesn't raise an error; its result contains the error message, and by default the script stops at the first failed statement. A script isn't a transaction, so statements that ran before the failure keep their effect. The agent checks the results of all statements before it reports that the script ran successfully.

If the working folder isn't on the allowed-paths list, db.execute_sql_script can't read the file. In this case, the agent typically passes the content of the script directly with the sql_script argument instead.

Verify the Result

Ask the agent to check the result on the server rather than to summarize what it ran:

To answer, the agent queries the server with these tools:

  • db.list_schemas lists the schemas, which should include notes_app.

  • db.list_objects lists the tables and views in notes_app.

  • db.get_object_details returns the columns, keys, indexes, and constraints of a table, for example the UUID primary key and the foreign keys of note.

To test the schema with data, ask the agent to insert sample rows and run a query, for example the number of notes per user. The agent runs these statements with db.execute_sql, which returns the result rows.

Clean Up

When you no longer need the sandbox, ask the agent to remove it:

The agent calls db.close, sandbox.stop, and sandbox.delete, in this order. A sandbox can't be deleted while it's running.

The Complete Workflow in One Request

Once you're familiar with the steps, you can combine them in a single request:

Run Scripts on Development and Production Servers

Besides sandbox instances, the agent can run queries and scripts on your existing development and production servers. To give the agent access to a server, add a connection for it, as described in Configuring the MCP Server:

If a server is only reachable through an SSH host, configure the connection with a mariadb+ssh:// URI, as described in Tunnel Database Connections via SSH. The agent finds the configured connections with db.list_connections, and you refer to a connection in your request, for example:

This page is licensed: GPLv2

Last updated

Was this helpful?