Skip to main content
Glama
kevinbin

MCP MySQL Server

by kevinbin

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
NameRequiredDescriptionDefault
fieldYes
tableYes

Implementation Reference

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

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