Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

add_column

Add a new column to an existing table in MySQL or MongoDB databases through the MCP server, specifying column name, data type, and optional constraints like length, nullability, or default values.

Instructions

Add a new column to existing table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes
fieldYes

Implementation Reference

  • The handler function that executes the add_column tool. It validates inputs, constructs an ALTER TABLE ADD COLUMN SQL statement based on the field definition, executes it, and returns success or error message.
    private async handleAddColumn(args: any) { await this.ensureConnection(); 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}'`}`; } try { await this.connection!.query(sql); return { content: [ { type: 'text', text: `Column ${args.field.name} added to table ${args.table}` } ] }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to add column: ${getErrorMessage(error)}` ); } }
  • Input schema definition for the add_column tool, specifying required table name and field object with name, type, and optional 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', 'number', 'null'], optional: true } }, required: ['name', 'type'] } }, required: ['table', 'field'] }
  • src/index.ts:373-397 (registration)
    Tool registration in the ListTools response, 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', 'number', 'null'], optional: true } }, required: ['name', 'type'] } }, required: ['table', 'field'] } },
  • src/index.ts:549-550 (registration)
    Dispatch case in the CallToolRequestHandler switch statement that routes add_column calls to the handler method.
    case 'add_column': return await this.handleAddColumn(request.params.arguments);

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

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