Skip to main content
Glama

describe_table

Retrieve schema details for a specified table in a Turso database, enabling users to view structure and properties directly from the MCP server.

Instructions

Gets schema information for a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNoDatabase name (optional, uses context if not provided)
tableYesTable name

Implementation Reference

  • The MCP tool handler for describe_table. It resolves the database name from context if not provided, calls the underlying database client function, transforms the column data for better readability (e.g., boolean flags for nullable and primary key), and returns a formatted JSON response.
    async ({ table, database }) => { try { const database_name = resolve_database_name(database); if (database) set_current_database(database); const columns = await database_client.describe_table( database_name, table, ); return create_tool_response({ database: database_name, table, columns: columns.map((col) => ({ name: col.name, type: col.type, nullable: col.notnull === 0, default_value: col.dflt_value, primary_key: col.pk === 1, })), }); } catch (error) { return create_tool_error_response(error); } },
  • Zod schema for validating input to the describe_table tool: requires table name, optional database name (falls back to context).
    const DescribeTableSchema = z.object({ table: z.string().describe('Table name'), database: z.string().optional().describe('Database name (optional, uses context if not provided)'), });
  • Registration of the describe_table tool with the MCP server via server.tool(), providing name, description, input schema, and the handler function.
    server.tool( { name: 'describe_table', description: 'Gets schema information for a table', schema: DescribeTableSchema, }, async ({ table, database }) => { try { const database_name = resolve_database_name(database); if (database) set_current_database(database); const columns = await database_client.describe_table( database_name, table, ); return create_tool_response({ database: database_name, table, columns: columns.map((col) => ({ name: col.name, type: col.type, nullable: col.notnull === 0, default_value: col.dflt_value, primary_key: col.pk === 1, })), }); } catch (error) { return create_tool_error_response(error); } }, );
  • Helper function in the database client that connects to the database, executes PRAGMA table_info(table_name) to get column schema, and returns typed column information. Called by the tool handler.
    export async function describe_table( database_name: string, table_name: string, ): Promise< { name: string; type: string; notnull: number; dflt_value: string | null; pk: number; }[] > { try { const client = await get_database_client( database_name, 'read-only', ); // Query the table info const result = await client.execute({ sql: `PRAGMA table_info(${table_name})`, }); // Return the column definitions return result.rows.map((row) => ({ name: row.name as string, type: row.type as string, notnull: row.notnull as number, dflt_value: row.dflt_value as string | null, pk: row.pk as number, })); } catch (error) { throw new TursoApiError( `Failed to describe table ${table_name} for database ${database_name}: ${ (error as Error).message }`, 500, ); } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/spences10/mcp-turso-cloud'

If you have feedback or need assistance with the MCP directory API, please join our Discord server