add_column
Add a new column to an existing MySQL table by specifying the column name, type, and optional attributes such as length, nullability, and default value.
Instructions
Add a new column to existing table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field | Yes | ||
| table | Yes |
Implementation Reference
- src/index.ts:667-688 (handler)The handler function that implements the add_column tool. It constructs an ALTER TABLE ADD COLUMN SQL statement based on the input arguments and executes it using the shared executeQuery method.private async handleAddColumn(args: any) { if (!args.table || !args.field) { throw new McpError(ErrorCode.InvalidParams, 'Table name and field are required'); } let sql = `ALTER TABLE \`${args.table}\` ADD COLUMN \`${args.field.name}\` ${args.field.type.toUpperCase()}`; if (args.field.length) sql += `(${args.field.length})`; if (args.field.nullable === false) sql += ' NOT NULL'; if (args.field.default !== undefined) { sql += ` DEFAULT ${args.field.default === null ? 'NULL' : `'${args.field.default}'`}`; } await this.executeQuery(sql); return { content: [ { type: 'text', text: `Column ${args.field.name} added to table ${args.table}` } ] }; }
- src/index.ts:489-513 (registration)Registers the 'add_column' tool in the listTools response, including its description and input schema definition.{ name: 'add_column', description: 'Add a new column to existing table', inputSchema: { type: 'object', properties: { table: { type: 'string' }, field: { 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 } }, required: ['name', 'type'] } }, required: ['table', 'field'] } }
- src/index.ts:531-532 (registration)In the CallToolRequest handler switch statement, routes 'add_column' tool calls to the handleAddColumn method.case 'add_column': return await this.handleAddColumn(request.params.arguments);