Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

create_table

Define a new database table structure by specifying column names, data types, and optional constraints like primary keys or nullability.

Instructions

Create a new table with specified columns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
columnsYesColumn definitions
databaseNoDatabase name (optional)

Implementation Reference

  • The anonymous async handler function for the create_table tool. It builds the column definitions string, constructs the CREATE TABLE SQL query, executes it on the MySQL pool, and returns a success response with structured output.
    async ({ table, columns, database }) => { const p = await getPool(); const columnDefs = columns.map((col) => { let def = `\`${col.name}\` ${col.type}`; if (col.nullable === false) def += " NOT NULL"; if (col.autoIncrement) def += " AUTO_INCREMENT"; if (col.default !== undefined) def += ` DEFAULT ${col.default}`; if (col.primaryKey) def += " PRIMARY KEY"; return def; }); const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; const sql = `CREATE TABLE ${tableName} (${columnDefs.join(", ")})`; await p.execute(sql); const output = { success: true, table, database: database || null }; return { content: [ { type: "text" as const, text: `Table ${table} created successfully`, }, ], structuredContent: output, }; }
  • Zod schema defining the structure of a single column for use in the create_table tool's input parameters.
    const columnSchema = z.object({ name: z.string().describe("Column name"), type: z.string().describe("Column type (e.g., VARCHAR(255), INT, TEXT)"), nullable: z.boolean().optional().describe("Whether column can be null"), primaryKey: z.boolean().optional().describe("Whether this is the primary key"), autoIncrement: z.boolean().optional().describe("Whether to auto increment"), default: z.string().optional().describe("Default value"), });
  • src/index.ts:311-348 (registration)
    Registration of the 'create_table' tool on the MCP server, including the tool name, description, Zod input schema (referencing columnSchema), and inline handler function.
    server.tool( "create_table", "Create a new table with specified columns", { table: z.string().describe("Table name"), columns: z.array(columnSchema).describe("Column definitions"), database: z.string().optional().describe("Database name (optional)"), }, async ({ table, columns, database }) => { const p = await getPool(); const columnDefs = columns.map((col) => { let def = `\`${col.name}\` ${col.type}`; if (col.nullable === false) def += " NOT NULL"; if (col.autoIncrement) def += " AUTO_INCREMENT"; if (col.default !== undefined) def += ` DEFAULT ${col.default}`; if (col.primaryKey) def += " PRIMARY KEY"; return def; }); const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; const sql = `CREATE TABLE ${tableName} (${columnDefs.join(", ")})`; await p.execute(sql); const output = { success: true, table, database: database || null }; return { content: [ { type: "text" as const, text: `Table ${table} created successfully`, }, ], structuredContent: output, }; } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nilsir/mcp-server-mysql'

If you have feedback or need assistance with the MCP directory API, please join our Discord server