Skip to main content
Glama

analyze_sql_source

Read-onlyIdempotent

Audits Databricks SQL and DLT SQL source code offline to detect quality expectation risks, Cartesian joins, schema drift traps, and optimization opportunities, returning remediation advice.

Instructions

Audit Databricks SQL or Delta Live Tables (DLT) SQL source code for quality expectation risks, Cartesian joins, schema drift traps, and optimization opportunities.

Usage Guidelines:

  • Use for individual SQL (.sql) query text or DLT SQL statements (e.g., CREATE STREAMING TABLE, expect_or_drop).

  • For PySpark Python pipelines, use analyze_pyspark_source instead.

  • For scanning an entire repository or folder of mixed SQL and Python files, use scan_pipeline_directory instead.

Behavior:

  • Pure offline static AST parsing via sqlglot. Does NOT execute queries, access databases, or connect to Databricks SQL warehouses.

  • Deterministic and idempotent. Returns a structured diagnostic report with violation counts and remediation advice.

  • Syntax errors are surfaced as structured diagnostic findings.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "sql_code": "<sql_code>"
    },
    "name": "analyze_sql_source"
  }
}

Input Schema

NameRequiredDescriptionDefault
sql_codeYesDatabricks SQL / DLT SQL query text to audit.

Output Schema

NameRequiredDescriptionDefault
findingsYesList of SQL quality and performance findings.
finding_countYesTotal number of SQL diagnostic findings discovered.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.1.1
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "properties": {
      +    "finding_count": {
      +      "description": "Total number of SQL diagnostic findings discovered.",
      +      "type": "integer"
      +    },
      +    "findings": {
      +      "description": "List of SQL quality and performance findings.",
      +      "items": {
      +        "properties": {
      +          "line_number": {
      +            "description": "Line number where the SQL construct was detected.",
      +            "type": "integer"
      +          },
      +          "message": {
      +            "description": "Description of the anti-pattern or risk.",
      +            "type": "string"
      +          },
      +          "remediation": {
      +            "description": "Actionable SQL fix recommendation.",
      +            "type": "string"
      +          },
      +          "rule_id": {
      +            "description": "Rule identifier (e.g., PLAN-001, DD001).",
      +            "type": "string"
      +          },
      +          "rule_name": {
      +            "description": "Diagnostic rule name.",
      +            "type": "string"
      +          },
      +          "severity": {
      +            "description": "Diagnostic severity level.",
      +            "enum": [
      +              "HIGH",
      +              "MEDIUM",
      +              "LOW",
      +              "INFO"
      +            ],
      +            "type": "string"
      +          }
      +        },
      +        "required": [
      +          "rule_id",
      +          "severity",
      +          "message"
      +        ],
      +        "type": "object"
      +      },
      +      "type": "array"
      +    }
      +  },
      +  "required": [
      +    "finding_count",
      +    "findings"
      +  ],
      +  "type": "object"
      +}
  2. First observedv0.1.0

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The annotations already declare readOnlyHint, openWorldHint=false, and idempotentHint, and the description adds real behavioral context beyond them: pure offline static AST parsing via sqlglot with no query execution or warehouse connection, and syntax errors surfaced as structured findings rather than thrown. It mildly restates idempotence and does not mention size or time limits on the input, which keeps it short of a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The single lead sentence front-loads purpose and risk categories, then labeled Usage Guidelines and Behavior blocks make scanning trivial. Every sentence earns its place, and the exclusions are placed immediately after the purpose rather than buried.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return-value detail is not required, and the description still characterizes the report as structured diagnostics with violation counts and remediation advice. For a one-parameter, offline, read-only analyzer, the safety profile, input scope, and alternatives are all covered.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% and the single parameter already carries the description "Databricks SQL / DLT SQL query text to audit." The description's phrasing "individual SQL (.sql) query text" slightly reinforces that the parameter is one file's text rather than a path or directory, but adds no syntax, size, or format detail. Baseline 3 is appropriate when the schema does the work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource ("Audit Databricks SQL or Delta Live Tables (DLT) SQL source code") and enumerates the exact risk classes checked: Cartesian joins, schema drift traps, and optimization opportunities. An agent can distinguish it from analyze_pyspark_source and scan_pipeline_directory without opening any schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives an explicit when-to-use condition (individual .sql query text or DLT SQL statements such as CREATE STREAMING TABLE or expect_or_drop) and names two alternatives with the conditions that select them: analyze_pyspark_source for PySpark and scan_pipeline_directory for whole repos or mixed folders. Nothing about tool selection is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.