list_tables
Retrieve all tables in a specified or contextual database using the MCP server mcp-turso-cloud. Simplify database management and query operations with this tool.
Instructions
Lists all tables in a database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional, uses context if not provided) |
Implementation Reference
- src/tools/handler.ts:190-200 (handler)Handler function for the list_tables tool that resolves the database context, calls the database client helper, and formats the response.async ({ database }) => { try { const database_name = resolve_database_name(database); if (database) set_current_database(database); const tables = await database_client.list_tables(database_name); return create_tool_response({ database: database_name, tables }); } catch (error) { return create_tool_error_response(error); } },
- src/tools/handler.ts:32-34 (schema)Zod input schema used by the list_tables tool: optional database name (uses current context if omitted).const DatabaseOnlySchema = z.object({ database: z.string().optional().describe('Database name (optional, uses context if not provided)'), });
- src/tools/handler.ts:184-189 (registration)Registration of the list_tables tool with MCP server, specifying name, description, and input schema.server.tool( { name: 'list_tables', description: 'Lists all tables in a database', schema: DatabaseOnlySchema, },
- src/clients/database.ts:88-115 (helper)Core helper function that creates a read-only database client and queries sqlite_schema to retrieve non-system table names.export async function list_tables( database_name: string, ): Promise<string[]> { try { const client = await get_database_client( database_name, 'read-only', ); // Query the sqlite_schema table to get all tables const result = await client.execute({ sql: `SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name`, }); // Extract table names from the result return result.rows.map((row) => row.name as string); } catch (error) { throw new TursoApiError( `Failed to list tables for database ${database_name}: ${ (error as Error).message }`, 500, ); } }