Skip to main content
Glama

MCP-MongoDB-MySQL-Server

add_column

Add a new column to an existing table in MySQL or MongoDB databases with specified name, type, and optional attributes like length, nullability, and default value.

Instructions

Add a new column to existing table

Input Schema

NameRequiredDescriptionDefault
fieldYes
tableYes

Input Schema (JSON Schema)

{ "properties": { "field": { "properties": { "default": { "optional": true, "type": [ "string", "number", "null" ] }, "length": { "optional": true, "type": "number" }, "name": { "type": "string" }, "nullable": { "optional": true, "type": "boolean" }, "type": { "type": "string" } }, "required": [ "name", "type" ], "type": "object" }, "table": { "type": "string" } }, "required": [ "table", "field" ], "type": "object" }

Implementation Reference

  • The handler function that implements the add_column tool by constructing and executing an ALTER TABLE ADD COLUMN SQL statement with support for column length, nullability, and default values.
    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 defining the parameters for the add_column tool: table name and field specification (name, type, 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)
    Registration of the add_column tool in the server's tool list, including name, description, and input schema for ListTools requests.
    { 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'] } },

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

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