Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

alter_table

Modify MySQL table structure by adding, dropping, modifying, or renaming columns to adapt database schema to changing requirements.

Instructions

Modify an existing table structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
operationYesType of alteration
columnYesColumn name
definitionNoColumn definition for ADD/MODIFY (e.g., 'VARCHAR(255) NOT NULL')
newNameNoNew name for RENAME operation
databaseNoDatabase name (optional)

Implementation Reference

  • The handler function for the 'alter_table' tool. It constructs and executes an ALTER TABLE SQL statement based on the operation (ADD, DROP, MODIFY, RENAME) using the provided parameters, then returns a success response with structured output.
    async ({ table, operation, column, definition, newName, database }) => {
      const p = await getPool();
    
      const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``;
      let sql: string;
    
      switch (operation) {
        case "ADD":
          sql = `ALTER TABLE ${tableName} ADD COLUMN \`${column}\` ${definition}`;
          break;
        case "DROP":
          sql = `ALTER TABLE ${tableName} DROP COLUMN \`${column}\``;
          break;
        case "MODIFY":
          sql = `ALTER TABLE ${tableName} MODIFY COLUMN \`${column}\` ${definition}`;
          break;
        case "RENAME":
          sql = `ALTER TABLE ${tableName} RENAME COLUMN \`${column}\` TO \`${newName}\``;
          break;
        default:
          throw new Error(`Unknown operation: ${operation}`);
      }
    
      await p.execute(sql);
    
      const output = {
        success: true,
        table,
        operation,
        column,
        newName: newName || null,
        database: database || null,
      };
    
      return {
        content: [
          {
            type: "text" as const,
            text: `Table ${table} altered successfully (${operation} ${column})`,
          },
        ],
        structuredContent: output,
      };
    }
  • Zod schema defining the input parameters for the 'alter_table' tool: table, operation (enum), column, optional definition, newName, and database.
    {
      table: z.string().describe("Table name"),
      operation: z.enum(["ADD", "DROP", "MODIFY", "RENAME"]).describe("Type of alteration"),
      column: z.string().describe("Column name"),
      definition: z.string().optional().describe("Column definition for ADD/MODIFY (e.g., 'VARCHAR(255) NOT NULL')"),
      newName: z.string().optional().describe("New name for RENAME operation"),
      database: z.string().optional().describe("Database name (optional)"),
    },
  • src/index.ts:351-406 (registration)
    Registration of the 'alter_table' tool using server.tool(), including name, description, input schema, and inline handler function.
    server.tool(
      "alter_table",
      "Modify an existing table structure",
      {
        table: z.string().describe("Table name"),
        operation: z.enum(["ADD", "DROP", "MODIFY", "RENAME"]).describe("Type of alteration"),
        column: z.string().describe("Column name"),
        definition: z.string().optional().describe("Column definition for ADD/MODIFY (e.g., 'VARCHAR(255) NOT NULL')"),
        newName: z.string().optional().describe("New name for RENAME operation"),
        database: z.string().optional().describe("Database name (optional)"),
      },
      async ({ table, operation, column, definition, newName, database }) => {
        const p = await getPool();
    
        const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``;
        let sql: string;
    
        switch (operation) {
          case "ADD":
            sql = `ALTER TABLE ${tableName} ADD COLUMN \`${column}\` ${definition}`;
            break;
          case "DROP":
            sql = `ALTER TABLE ${tableName} DROP COLUMN \`${column}\``;
            break;
          case "MODIFY":
            sql = `ALTER TABLE ${tableName} MODIFY COLUMN \`${column}\` ${definition}`;
            break;
          case "RENAME":
            sql = `ALTER TABLE ${tableName} RENAME COLUMN \`${column}\` TO \`${newName}\``;
            break;
          default:
            throw new Error(`Unknown operation: ${operation}`);
        }
    
        await p.execute(sql);
    
        const output = {
          success: true,
          table,
          operation,
          column,
          newName: newName || null,
          database: database || null,
        };
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Table ${table} altered successfully (${operation} ${column})`,
            },
          ],
          structuredContent: output,
        };
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. 'Modify' implies a destructive mutation, but it doesn't disclose critical behavioral traits: whether it requires specific permissions, if changes are reversible, potential data loss risks (e.g., dropping columns), or rate limits. This is a significant gap for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action ('modify') and resource ('table structure'), making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (destructive table alterations with 6 parameters), no annotations, and no output schema, the description is inadequate. It lacks behavioral context (e.g., safety warnings), usage prerequisites, and expected outcomes, leaving significant gaps for an AI agent to operate safely and effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 6 parameters. The description adds no parameter-specific information beyond the generic 'modify table structure,' which aligns with the schema but doesn't provide additional context like examples for complex operations. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('modify') and resource ('existing table structure'), making the purpose evident. It distinguishes from siblings like create_table (new tables) and drop_table (removing tables), though it doesn't explicitly mention these distinctions in the text itself.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing table), exclusions, or comparisons with siblings like execute (for SQL commands) or describe_table (for viewing structure).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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