drop_table
Remove a specified table from the MSSQL Database using the "MSSQL MCP Server" tool. Simplify database management by executing table deletion tasks via natural language commands.
Instructions
Drops a table from the MSSQL Database.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | Name of the table to drop |
Input Schema (JSON Schema)
{
"properties": {
"tableName": {
"description": "Name of the table to drop",
"type": "string"
}
},
"required": [
"tableName"
],
"type": "object"
}
Implementation Reference
- src/tools/DropTableTool.ts:16-36 (handler)The main handler function that executes the drop table logic, including validation and MSSQL query execution.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)Input schema defining the required 'tableName' parameter for the tool.inputSchema = { type: "object", properties: { tableName: { type: "string", description: "Name of the table to drop" } }, required: ["tableName"], } as any;
- src/index.ts:109-113 (registration)Registration of dropTableTool in the list of available tools returned by ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: isReadOnly ? [listTableTool, readDataTool, describeTableTool] // todo: add searchDataTool to the list of tools available in readonly mode once implemented : [insertDataTool, readDataTool, describeTableTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool], // add all new tools here }));
- src/index.ts:138-140 (registration)Dispatch to dropTableTool.run() in the CallToolRequestSchema switch statement.case dropTableTool.name: result = await dropTableTool.run(args); break;
- src/index.ts:252-252 (helper)Helper wrapper applied to dropTableTool to ensure SQL connection before execution.[insertDataTool, readDataTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool, describeTableTool].forEach(wrapToolRun);