Skip to main content
Glama
kevinbin

MCP MySQL Server

by kevinbin

create_table

Define and generate a new table in a MySQL database by specifying table name, fields, data types, indexes, and other properties using the MCP MySQL Server interface.

Instructions

Create a new table in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsYes
indexesNo
tableYesTable name

Implementation Reference

  • The handler function for create_table tool. It constructs the CREATE TABLE SQL statement from the provided table name, fields, and optional indexes, then executes it using executeQuery.
    private async handleCreateTable(args: any) { const fields = args.fields.map((field: SchemaField) => { let def = `\`${field.name}\` ${field.type.toUpperCase()}`; if (field.length) def += `(${field.length})`; if (field.nullable === false) def += ' NOT NULL'; if (field.default !== undefined) { def += ` DEFAULT ${field.default === null ? 'NULL' : `'${field.default}'`}`; } if (field.autoIncrement) def += ' AUTO_INCREMENT'; if (field.primary) def += ' PRIMARY KEY'; return def; }); const indexes = args.indexes?.map((idx: IndexDefinition) => { const type = idx.unique ? 'UNIQUE INDEX' : 'INDEX'; return `${type} \`${idx.name}\` (\`${idx.columns.join('`, `')}\`)`; }) || []; const sql = `CREATE TABLE \`${args.table}\` ( ${[...fields, ...indexes].join(',\n ')} )`; await this.executeQuery(sql); return { content: [ { type: 'text', text: `Table ${args.table} created successfully` } ] }; }
  • Input schema for the create_table tool, defining the structure for table name, fields (with name, type, etc.), and optional indexes.
    inputSchema: { type: 'object', properties: { table: { type: 'string', description: 'Table name', }, fields: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, type: { type: 'string' }, length: { type: 'number', optional: true }, nullable: { type: 'boolean', optional: true }, default: { type: ['string', 'number', 'null'], optional: true }, autoIncrement: { type: 'boolean', optional: true }, primary: { type: 'boolean', optional: true } }, required: ['name', 'type'] } }, indexes: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, columns: { type: 'array', items: { type: 'string' } }, unique: { type: 'boolean', optional: true } }, required: ['name', 'columns'] }, optional: true } }, required: ['table', 'fields']
  • src/index.ts:440-488 (registration)
    Registration of the create_table tool in the ListTools response, including name, description, and input schema.
    { name: 'create_table', description: 'Create a new table in the database', inputSchema: { type: 'object', properties: { table: { type: 'string', description: 'Table name', }, fields: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, type: { type: 'string' }, length: { type: 'number', optional: true }, nullable: { type: 'boolean', optional: true }, default: { type: ['string', 'number', 'null'], optional: true }, autoIncrement: { type: 'boolean', optional: true }, primary: { type: 'boolean', optional: true } }, required: ['name', 'type'] } }, indexes: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, columns: { type: 'array', items: { type: 'string' } }, unique: { type: 'boolean', optional: true } }, required: ['name', 'columns'] }, optional: true } }, required: ['table', 'fields'] } },
  • src/index.ts:529-530 (registration)
    Registration of the create_table handler in the CallToolRequest switch statement dispatcher.
    case 'create_table': return await this.handleCreateTable(request.params.arguments);

Other Tools

Related Tools

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/kevinbin/mcp-mysql-server'

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