generate_table_insights
Analyze table data to uncover patterns, trends, and key statistics using AI-powered analysis for informed decision-making.
Instructions
Generate AI-powered insights about a table's data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | ||
| sample_limit | No |
Implementation Reference
- src/main.py:371-399 (handler)The core handler function for the 'generate_table_insights' MCP tool. Decorated with @mcp.tool() for automatic registration and schema inference from type hints and docstring. Fetches table schema and sample data from Snowflake, then generates AI insights using OpenAI.@mcp.tool() async def generate_table_insights(table_name: str, sample_limit: int = 20, ctx: Context = None) -> str: """Generate AI-powered insights about a table's data""" await ctx.info(f"Generating insights for table: {table_name}") try: snowflake = await get_snowflake_client() # Get table schema columns = await snowflake.describe_table(table_name) # Get sample data sample_result = await snowflake.get_table_sample(table_name, sample_limit) if not sample_result.success: await ctx.error(f"Failed to get sample data: {sample_result.error}") return f"Failed to get sample data: {sample_result.error}" # Generate insights openai = await get_openai_client() insights = await openai.generate_data_insights(table_name, columns, sample_result.data) await ctx.info(f"Generated insights for table {table_name}") return insights except Exception as e: logger.error(f"Error generating table insights: {str(e)}") await ctx.error(f"Failed to generate table insights: {str(e)}") raise