drop_table
Delete a table from the SQLite database permanently. Provide the table name to remove the table and all its data irreversibly.
Instructions
Drop (delete) a table from the database. This action is irreversible.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to drop |
Implementation Reference
- src/index.ts:303-308 (handler)The handler for the 'drop_table' tool. Extracts table_name from args, validates it, executes DROP TABLE IF EXISTS, and returns a success message.
case 'drop_table': { const { table_name } = toolArgs as { table_name: string }; validateTableName(table_name); db.run(`DROP TABLE IF EXISTS "${table_name}"`); return { content: [{ type: 'text', text: `Table "${table_name}" dropped successfully` }] }; } - src/index.ts:232-242 (schema)Registration and input schema definition for the 'drop_table' tool. Defines the input schema requiring 'table_name' (a string) and provides the tool description.
{ name: 'drop_table', description: 'Drop (delete) a table from the database. This action is irreversible.', inputSchema: { type: 'object' as const, properties: { table_name: { type: 'string', description: 'Name of the table to drop' }, }, required: ['table_name'], }, }, - src/index.ts:196-274 (registration)Tool registration via ListToolsRequestSchema handler. All tools including 'drop_table' are registered here in the tools array passed to the server.
// ── Tools ── server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'read_query', description: 'Execute a read-only SQL query (SELECT, WITH/CTE, or EXPLAIN). Use this for fetching data.', inputSchema: { type: 'object' as const, properties: { query: { type: 'string', description: 'The SELECT SQL query to execute' }, }, required: ['query'], }, }, { name: 'write_query', description: 'Execute a data modification query (INSERT, UPDATE, DELETE, REPLACE). Returns affected row count.', inputSchema: { type: 'object' as const, properties: { query: { type: 'string', description: 'The SQL modification query to execute' }, }, required: ['query'], }, }, { name: 'create_table', description: 'Create a new table in the database with a full CREATE TABLE SQL statement.', inputSchema: { type: 'object' as const, properties: { query: { type: 'string', description: 'CREATE TABLE SQL statement' }, }, required: ['query'], }, }, { name: 'drop_table', description: 'Drop (delete) a table from the database. This action is irreversible.', inputSchema: { type: 'object' as const, properties: { table_name: { type: 'string', description: 'Name of the table to drop' }, }, required: ['table_name'], }, }, { name: 'list_tables', description: 'List all user-created tables in the database.', inputSchema: { type: 'object' as const, properties: {}, }, }, { name: 'describe_table', description: 'Get the schema of a table: columns, types, constraints, indexes, and foreign keys.', inputSchema: { type: 'object' as const, properties: { table_name: { type: 'string', description: 'Name of the table to describe' }, }, required: ['table_name'], }, }, { name: 'append_insight', description: 'Add a business insight to the insights memo resource. Useful for recording observations from analysis.', inputSchema: { type: 'object' as const, properties: { insight: { type: 'string', description: 'The business insight to record' }, }, required: ['insight'], }, }, ], })); - src/index.ts:30-34 (helper)Validation helper used by drop_table handler. Validates that the table name matches the pattern /^[a-zA-Z_][a-zA-Z0-9_]*$/ to prevent SQL injection.
function validateTableName(name: string): void { if (!VALID_IDENTIFIER.test(name)) { throw new McpError(ErrorCode.InvalidParams, `Invalid table name: "${name}". Use only letters, numbers, and underscores.`); } }