drop_table
Remove a table from a Microsoft SQL Server database to manage schema changes or delete obsolete data structures.
Instructions
Drops a table from the MSSQL Database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | Name of the table to drop |
Implementation Reference
- src/tools/DropTableTool.ts:16-36 (handler)The `run` method implements the core logic of the drop_table tool: extracts tableName, validates it to prevent SQL injection, executes the DROP TABLE query using mssql, and returns a success or error response.async run(params: any) { try { const { tableName } = params; // Basic validation to prevent SQL injection if (!/^[\w\d_]+$/.test(tableName)) { throw new Error("Invalid table name."); } const query = `DROP TABLE [${tableName}]`; await new sql.Request().query(query); return { success: true, message: `Table '${tableName}' dropped successfully.` }; } catch (error) { console.error("Error dropping table:", error); return { success: false, message: `Failed to drop table: ${error}` }; } }
- src/tools/DropTableTool.ts:8-14 (schema)Defines the input schema for the drop_table tool, requiring a 'tableName' string parameter.inputSchema = { type: "object", properties: { tableName: { type: "string", description: "Name of the table to drop" } }, required: ["tableName"], } as any;
- src/index.ts:112-112 (registration)The dropTableTool instance is included in the array of tools advertised via ListToolsRequestHandler (non-readonly mode).: [insertDataTool, readDataTool, describeTableTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool], // add all new tools here
- src/index.ts:138-140 (registration)Switch case in CallToolRequestHandler that dispatches calls to drop_table by invoking dropTableTool.run().case dropTableTool.name: result = await dropTableTool.run(args); break;
- src/index.ts:252-252 (helper)dropTableTool is wrapped with ensureSqlConnection before its run method is called.[insertDataTool, readDataTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool, describeTableTool].forEach(wrapToolRun);