get_table_sample
Extract a sample of data from a specified table in Snowflake databases. Define table name and optional row limit to preview data efficiently.
Instructions
Get a sample of data from a table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| table_name | Yes |
Implementation Reference
- src/main.py:205-230 (registration)MCP tool registration for get_table_sample. This is the entry point decorated with @mcp.tool(), which wraps the SnowflakeClient method and handles MCP context.@mcp.tool() async def get_table_sample(table_name: str, limit: int = 10, ctx: Context = None) -> QueryResult: """Get a sample of data from a table""" await ctx.info(f"Getting sample data from table: {table_name} (limit: {limit})") try: client = await get_snowflake_client() result = await client.get_table_sample(table_name, limit) if result.success: await ctx.info(f"Retrieved {result.row_count} sample rows") else: await ctx.error(f"Failed to get sample: {result.error}") return result except Exception as e: logger.error(f"Error getting table sample: {str(e)}") await ctx.error(f"Failed to get table sample: {str(e)}") return QueryResult( success=False, data=[], columns=[], row_count=0, error=str(e) )
- src/snowflake_client.py:183-186 (handler)Core handler logic in SnowflakeClient class. Constructs a SELECT * LIMIT query and delegates to execute_query method.async def get_table_sample(self, table_name: str, limit: int = 10) -> QueryResult: """Get a sample of data from a table""" query = f"SELECT * FROM {table_name} LIMIT {limit}" return await self.execute_query(query)
- src/models.py:44-53 (schema)Pydantic model defining the output schema for QueryResult returned by get_table_sample.class QueryResult(BaseModel): """Result of a SQL query execution""" success: bool data: List[Dict[str, Any]] columns: List[str] row_count: int execution_time_ms: Optional[int] = None query_id: Optional[str] = None warehouse_used: Optional[str] = None error: Optional[str] = None