Skip to main content
Glama
gigapi

GigAPI MCP Server

by gigapi

list_tables

Retrieve all database tables to explore available data structures and identify relevant datasets for analysis.

Instructions

List all tables in a database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYes

Implementation Reference

  • The primary MCP tool handler for 'list_tables'. It invokes the client's list_tables method, formats the response with success status, count, and handles errors.
    def list_tables(self, database: str) -> Dict[str, Any]:
        """List all tables in a database.
    
        Args:
            database: The name of the database
    
        Returns:
            List of tables
        """
        try:
            tables = self.client.list_tables(database)
            return {
                "tables": tables,
                "success": True,
                "database": database,
                "count": len(tables)
            }
        except GigAPIClientError as e:
            logger.error(f"Failed to list tables: {e}")
            return {
                "error": str(e),
                "success": False,
                "database": database,
                "tables": []
            }
  • Registration of the 'list_tables' tool instance using FastMCP's Tool.from_function, binding it to the GigAPITools.list_tables method.
    Tool.from_function(
        tools_instance.list_tables,
        name="list_tables",
        description="List all tables in a database.",
    ),
  • Helper method in GigAPIClient that executes a 'SHOW TABLES' SQL query, parses NDJSON results to extract table names, and returns a list of strings.
    def list_tables(self, database: str) -> List[str]:
        """List all tables in a database.
    
        Args:
            database: Database name
    
        Returns:
            List of table names
        """
        query = "SHOW TABLES"
        response = self.execute_query(query, database)
        logger.debug(f"Raw SHOW TABLES response: {response}")
        if response.error:
            raise GigAPIClientError(f"Failed to list tables: {response.error}")
    
        # Extract table names from NDJSON results
        tables = []
        for result in response.results:
            if "table_name" in result:
                tables.append(result["table_name"])
            elif "name" in result:
                tables.append(result["name"])
            elif "tables" in result:
                tables.extend(result["tables"])
    
        return tables

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/gigapi/gigapi-mcp'

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