edit-table-schema
Modify table structure in Xano databases by adding, removing, or renaming columns to adapt data models to changing application requirements.
Instructions
Edit the schema of an existing table (add, remove, or modify columns)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_id | Yes | ID of the table to edit | |
| operation | Yes | Type of schema operation to perform | |
| schema | No | Full schema specification (for 'update' operation) | |
| column | No | Column specification (for 'add_column' operation) | |
| rename | No | Rename specification (for 'rename_column' operation) | |
| column_name | No | Name of the column to remove (for 'remove_column' operation) |
Implementation Reference
- src/index.ts:464-561 (handler)The handler function for 'edit-table-schema' tool. It handles four operations: 'update' (PUT entire schema), 'add_column' (POST to /schema/type/{type}), 'rename_column' (POST to /schema/rename), 'remove_column' (DELETE /schema/{column_name}). Uses makeXanoRequest helper for API calls.async ({ table_id, operation, schema, column, rename, column_name }) => { console.error(`[Tool] Executing edit-table-schema for table ID: ${table_id}, operation: ${operation}`); try { let result; let successMessage = ""; switch (operation) { case 'update': if (!schema || schema.length === 0) { return { content: [{ type: "text", text: "Error: Schema array must be provided for 'update' operation" }], isError: true }; } // PUT request to update the entire schema await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema`, 'PUT', { schema } ); successMessage = `Successfully updated the entire schema for table ID: ${table_id}`; break; case 'add_column': if (!column) { return { content: [{ type: "text", text: "Error: Column specification must be provided for 'add_column' operation" }], isError: true }; } // POST request to add a new column of the specified type await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema/type/${column.type}`, 'POST', column ); successMessage = `Successfully added column '${column.name}' of type '${column.type}' to table ID: ${table_id}`; break; case 'rename_column': if (!rename) { return { content: [{ type: "text", text: "Error: Rename specification must be provided for 'rename_column' operation" }], isError: true }; } // POST request to rename a column await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema/rename`, 'POST', rename ); successMessage = `Successfully renamed column from '${rename.old_name}' to '${rename.new_name}' in table ID: ${table_id}`; break; case 'remove_column': if (!column_name) { return { content: [{ type: "text", text: "Error: Column name must be provided for 'remove_column' operation" }], isError: true }; } // DELETE request to remove a column await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema/${column_name}`, 'DELETE' ); successMessage = `Successfully removed column '${column_name}' from table ID: ${table_id}`; break; } console.error(`[Tool] ${successMessage}`); return { content: [{ type: "text", text: successMessage }] }; } catch (error) { console.error(`[Error] Failed to edit table schema: ${error instanceof Error ? error.message : String(error)}`); return { content: [ { type: "text", text: `Error editing table schema: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:414-463 (schema)Zod input schema defining parameters for edit-table-schema: table_id (string), operation (enum), conditional params like schema (array), column (object), rename (object), column_name (string).{ table_id: z.string().describe("ID of the table to edit"), operation: z.enum(['update', 'add_column', 'rename_column', 'remove_column']).describe("Type of schema operation to perform"), // For updating the entire schema schema: z.array(z.object({ name: z.string().describe("Name of the schema element"), type: z.enum([ "attachment", "audio", "bool", "date", "decimal", "email", "enum", "geo_linestring", "geo_multilinestring", "geo_multipoint", "geo_multipolygon", "geo_point", "geo_polygon", "image", "int", "json", "object", "password", "tableref", "tablerefuuid", "text", "timestamp", "uuid", "vector", "video" ]).describe("Type of the schema element"), description: z.string().optional().describe("Description of the schema element"), nullable: z.boolean().optional().default(false).describe("Whether the field can be null"), required: z.boolean().optional().default(false).describe("Whether the field is required"), access: z.enum(["public", "private", "internal"]).optional().default("public").describe("Access level for the field"), style: z.enum(["single", "list"]).optional().default("single").describe("Whether the field is a single value or a list"), default: z.string().optional().describe("Default value for the field"), config: z.record(z.any()).optional().describe("Additional configuration for specific field types"), children: z.array(z.any()).optional().describe("Nested fields for object types") })).optional().describe("Full schema specification (for 'update' operation)"), // For adding a single column column: z.object({ name: z.string().describe("Name of the column"), type: z.enum([ "attachment", "audio", "bool", "date", "decimal", "email", "enum", "geo_linestring", "geo_multilinestring", "geo_multipoint", "geo_multipolygon", "geo_point", "geo_polygon", "image", "int", "json", "object", "password", "tableref", "tablerefuuid", "text", "timestamp", "uuid", "vector", "video" ]).describe("Type of the column"), description: z.string().optional().describe("Description of the column"), nullable: z.boolean().optional().default(false).describe("Whether the field can be null"), required: z.boolean().optional().default(false).describe("Whether the field is required"), access: z.enum(["public", "private", "internal"]).optional().default("public").describe("Access level for the field"), style: z.enum(["single", "list"]).optional().default("single").describe("Whether the field is a single value or a list"), default: z.string().optional().describe("Default value for the field"), config: z.record(z.any()).optional().describe("Additional configuration for the column") }).optional().describe("Column specification (for 'add_column' operation)"), // For renaming a column rename: z.object({ old_name: z.string().describe("Current name of the column"), new_name: z.string().describe("New name for the column") }).optional().describe("Rename specification (for 'rename_column' operation)"), // For removing a column column_name: z.string().optional().describe("Name of the column to remove (for 'remove_column' operation)") },
- src/index.ts:411-562 (registration)Registration of the 'edit-table-schema' tool using server.tool(), including name, description, input schema, and handler function.server.tool( "edit-table-schema", "Edit the schema of an existing table (add, remove, or modify columns)", { table_id: z.string().describe("ID of the table to edit"), operation: z.enum(['update', 'add_column', 'rename_column', 'remove_column']).describe("Type of schema operation to perform"), // For updating the entire schema schema: z.array(z.object({ name: z.string().describe("Name of the schema element"), type: z.enum([ "attachment", "audio", "bool", "date", "decimal", "email", "enum", "geo_linestring", "geo_multilinestring", "geo_multipoint", "geo_multipolygon", "geo_point", "geo_polygon", "image", "int", "json", "object", "password", "tableref", "tablerefuuid", "text", "timestamp", "uuid", "vector", "video" ]).describe("Type of the schema element"), description: z.string().optional().describe("Description of the schema element"), nullable: z.boolean().optional().default(false).describe("Whether the field can be null"), required: z.boolean().optional().default(false).describe("Whether the field is required"), access: z.enum(["public", "private", "internal"]).optional().default("public").describe("Access level for the field"), style: z.enum(["single", "list"]).optional().default("single").describe("Whether the field is a single value or a list"), default: z.string().optional().describe("Default value for the field"), config: z.record(z.any()).optional().describe("Additional configuration for specific field types"), children: z.array(z.any()).optional().describe("Nested fields for object types") })).optional().describe("Full schema specification (for 'update' operation)"), // For adding a single column column: z.object({ name: z.string().describe("Name of the column"), type: z.enum([ "attachment", "audio", "bool", "date", "decimal", "email", "enum", "geo_linestring", "geo_multilinestring", "geo_multipoint", "geo_multipolygon", "geo_point", "geo_polygon", "image", "int", "json", "object", "password", "tableref", "tablerefuuid", "text", "timestamp", "uuid", "vector", "video" ]).describe("Type of the column"), description: z.string().optional().describe("Description of the column"), nullable: z.boolean().optional().default(false).describe("Whether the field can be null"), required: z.boolean().optional().default(false).describe("Whether the field is required"), access: z.enum(["public", "private", "internal"]).optional().default("public").describe("Access level for the field"), style: z.enum(["single", "list"]).optional().default("single").describe("Whether the field is a single value or a list"), default: z.string().optional().describe("Default value for the field"), config: z.record(z.any()).optional().describe("Additional configuration for the column") }).optional().describe("Column specification (for 'add_column' operation)"), // For renaming a column rename: z.object({ old_name: z.string().describe("Current name of the column"), new_name: z.string().describe("New name for the column") }).optional().describe("Rename specification (for 'rename_column' operation)"), // For removing a column column_name: z.string().optional().describe("Name of the column to remove (for 'remove_column' operation)") }, async ({ table_id, operation, schema, column, rename, column_name }) => { console.error(`[Tool] Executing edit-table-schema for table ID: ${table_id}, operation: ${operation}`); try { let result; let successMessage = ""; switch (operation) { case 'update': if (!schema || schema.length === 0) { return { content: [{ type: "text", text: "Error: Schema array must be provided for 'update' operation" }], isError: true }; } // PUT request to update the entire schema await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema`, 'PUT', { schema } ); successMessage = `Successfully updated the entire schema for table ID: ${table_id}`; break; case 'add_column': if (!column) { return { content: [{ type: "text", text: "Error: Column specification must be provided for 'add_column' operation" }], isError: true }; } // POST request to add a new column of the specified type await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema/type/${column.type}`, 'POST', column ); successMessage = `Successfully added column '${column.name}' of type '${column.type}' to table ID: ${table_id}`; break; case 'rename_column': if (!rename) { return { content: [{ type: "text", text: "Error: Rename specification must be provided for 'rename_column' operation" }], isError: true }; } // POST request to rename a column await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema/rename`, 'POST', rename ); successMessage = `Successfully renamed column from '${rename.old_name}' to '${rename.new_name}' in table ID: ${table_id}`; break; case 'remove_column': if (!column_name) { return { content: [{ type: "text", text: "Error: Column name must be provided for 'remove_column' operation" }], isError: true }; } // DELETE request to remove a column await makeXanoRequest( `/workspace/${XANO_WORKSPACE}/table/${table_id}/schema/${column_name}`, 'DELETE' ); successMessage = `Successfully removed column '${column_name}' from table ID: ${table_id}`; break; } console.error(`[Tool] ${successMessage}`); return { content: [{ type: "text", text: successMessage }] }; } catch (error) { console.error(`[Error] Failed to edit table schema: ${error instanceof Error ? error.message : String(error)}`); return { content: [ { type: "text", text: `Error editing table schema: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );