Skip to main content
Glama
enemyrr

MCP-MySQL Server

add_column

Add a new column to a MySQL table by specifying the column name, data type, and optional attributes such as length, nullability, and default value.

Instructions

Add a new column to existing table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldYes
tableYes

Implementation Reference

  • The handler function for the 'add_column' tool. It constructs an ALTER TABLE ADD COLUMN SQL statement based on the input arguments and executes it using executeQuery. Returns a success message.
    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}`
          }
        ]
      };
    }
  • The input schema definition for the 'add_column' tool, specifying the expected structure of table name and field properties (name, type, length, nullable, default).
    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',
              description: 'Default value for the column (as string).',
              optional: true
            }
          },
          required: ['name', 'type']
        }
      },
      required: ['table', 'field']
    }
  • src/index.ts:540-565 (registration)
    The tool registration object for 'add_column' in the setTools call, including name, description, and input schema.
    {
      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',
                description: 'Default value for the column (as string).',
                optional: true
              }
            },
            required: ['name', 'type']
          }
        },
        required: ['table', 'field']
      }
    }
  • src/index.ts:583-584 (registration)
    The dispatch case in setRequestHandler that routes 'add_column' tool calls to the handleAddColumn method.
    case 'add_column':
      return await this.handleAddColumn(request.params.arguments);

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

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

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