Skip to main content
Glama

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
NameRequiredDescriptionDefault
databaseNoDatabase name (optional, uses context if not provided)

Implementation Reference

  • 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);
    	}
    },
  • 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)'),
    });
  • 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,
    	},
  • 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,
    		);
    	}
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

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