describe_table
Retrieve the schema of a table, including columns, types, constraints, indexes, and foreign keys.
Instructions
Get the schema of a table: columns, types, constraints, indexes, and foreign keys.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to describe |
Implementation Reference
- src/index.ts:319-328 (handler)The handler for the 'describe_table' tool: validates the table name, then queries PRAGMA table_info, index_list, and foreign_key_list to return the table schema.
case 'describe_table': { const { table_name } = toolArgs as { table_name: string }; validateTableName(table_name); const columns = db.all(`PRAGMA table_info("${table_name}")`); const indexes = db.all(`PRAGMA index_list("${table_name}")`); const foreignKeys = db.all(`PRAGMA foreign_key_list("${table_name}")`); return { content: [{ type: 'text', text: JSON.stringify({ columns, indexes, foreign_keys: foreignKeys }, null, 2) }], }; } - src/index.ts:251-261 (schema)The tool registration/schema definition: defines 'describe_table' with a required 'table_name' string parameter.
{ 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'], }, }, - src/index.ts:197-274 (registration)Registration of all tools via ListToolsRequestSchema handler, including 'describe_table' in the tools list.
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 the describe_table handler to ensure the table name is a valid SQL identifier.
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.`); } }