Skip to main content
Glama
j4c0bs

mcp-server-sql-analyzer

by j4c0bs

mcp-server-sql-analyzer

A Model Context Protocol (MCP) server that provides SQL analysis, linting, and dialect conversion capabilities using SQLGlot.

Overview

The SQL Analyzer MCP server provides tools for analyzing and working with SQL queries. It helps with:

  • SQL syntax validation and linting

  • Converting queries between different SQL dialects (e.g., MySQL to PostgreSQL)

  • Extracting and analyzing table references and dependencies

  • Identifying column usage and relationships

  • Discovering supported SQL dialects

How Claude Uses This Server

As an AI assistant, this server enhances my ability to help users work with SQL efficiently by:

  1. Query Validation: I can instantly validate SQL syntax before suggesting it to users, ensuring I provide correct and dialect-appropriate queries.

  2. Dialect Conversion: When users need to migrate queries between different database systems, I can accurately convert the syntax while preserving the query's logic.

  3. Code Analysis: The table and column reference analysis helps me understand complex queries, making it easier to explain query structure and suggest optimizations.

  4. Compatibility Checking: By knowing the supported dialects and their specific features, I can guide users toward database-specific best practices.

This toolset allows me to provide more accurate and helpful SQL-related assistance while reducing the risk of syntax errors or dialect-specific issues.

Tips

Update your personal preferences in Claude Desktop settings to request that generated SQL is first validated using the lint_sql tool.

Related MCP server: mcp-sql-api

Tools

  1. lint_sql

    • Validates SQL query syntax and returns any errors

    • Input:

      • sql (string): SQL query to analyze

      • dialect (string, optional): SQL dialect (e.g., 'mysql', 'postgres')

    • Returns: ParseResult containing:

      • is_valid (boolean): Whether the SQL is valid

      • message (string): Error message or "No syntax errors"

      • position (object, optional): Line and column of error if present

  2. transpile_sql

    • Converts SQL between different dialects

    • Inputs:

      • sql (string): SQL statement to transpile

      • read_dialect (string): Source SQL dialect

      • write_dialect (string): Target SQL dialect

    • Returns: TranspileResult containing:

      • is_valid (boolean): Whether transpilation succeeded

      • message (string): Error message or success confirmation

      • sql (string): Transpiled SQL if successful

  3. get_all_table_references

    • Extracts table and CTE references from SQL

    • Inputs:

      • sql (string): SQL statement to analyze

      • dialect (string, optional): SQL dialect

    • Returns: TableReferencesResult containing:

      • is_valid (boolean): Whether analysis succeeded

      • message (string): Status message

      • tables (array): List of table references with type, catalog, database, table name, alias, and fully qualified name

  4. get_all_column_references

    • Extracts column references with table context

    • Inputs:

      • sql (string): SQL statement to analyze

      • dialect (string, optional): SQL dialect

    • Returns: ColumnReferencesResult containing:

      • is_valid (boolean): Whether analysis succeeded

      • message (string): Status message

      • columns (array): List of column references with column name, table name, and fully qualified name

Resources

SQL Dialect Discovery

dialects://all

Returns a list of all supported SQL dialects for use in all tools.

Configuration

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
      "sql-analyzer": {
          "command": "uvx",
          "args": [
              "--from",
              "git+https://github.com/j4c0bs/mcp-server-sql-analyzer.git",
              "mcp-server-sql-analyzer"
          ]
      }
  }
}

Using uv

After cloning this repo, add this to your claude_desktop_config.json:

{
  "mcpServers": {
      "sql-analyzer": {
          "command": "uv",
          "args": [
              "--directory",
              "/path/to/mcp-server-sql-analyzer",
              "run",
              "mcp-server-sql-analyzer"
          ]
      }
  }
}

Development

To run the server in development mode:

# Clone the repository
git clone git@github.com:j4c0bs/mcp-server-sql-analyzer.git

# Run the server
npx @modelcontextprotocol/inspector uv --directory /path/to/mcp-server-sql-analyzer run mcp-server-sql-analyzer

To run unit tests:

uv run pytest .

License

MIT

Available Tools

4 tools
get_all_column_referencesA
Extract column references from SQL statement with table context

Args:
    sql: SQL statement to analyze
    dialect: Optional SQL dialect (e.g., 'mysql', 'postgres')
Returns:
    JSON object containing column references with table context and any errors
ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYes
dialectNo

TDQS

A3.5/5.0
Behavior3/5

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

With no annotations, description provides return format and mentions errors, but lacks details on side effects, performance, or prerequisites. It does note the dialect parameter influences behavior.

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?

Extremely concise with clear structure: purpose sentence followed by structured Args and Returns. No unnecessary text, every sentence earns its place.

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

Completeness4/5

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

Tool is simple with 2 parameters and no output schema. Description covers purpose, inputs, and output type. Lacks example output but sufficient for basic understanding.

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

Parameters4/5

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

Schema description coverage is 0%, but description adds meaning: 'sql: SQL statement to analyze' and 'dialect: Optional SQL dialect (e.g., 'mysql', 'postgres')', including an example for dialect.

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

Purpose4/5

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

Description clearly states 'Extract column references from SQL statement with table context', which is a specific verb and resource. It implicitly distinguishes from sibling 'get_all_table_references' by focusing on columns, but does not explicitly contrast.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives (e.g., get_all_table_references, lint_sql). Only states its purpose, not when-not or context.

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

get_all_table_referencesA
Extract table and CTE names from SQL statement

Args:
    sql: SQL statement to analyze
    dialect: Optional SQL dialect (e.g., 'mysql', 'postgres')
Returns:
    JSON object containing tables with catalog, database, and alias attributes
    CTEs are returned as "cte" type
ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYes
dialectNo

TDQS

A3.7/5.0
Behavior3/5

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

No annotations provided, so description carries full burden. It explains it extracts table/CTE names and returns JSON with specific attributes. However, it omits details about side effects (none expected), authentication needs, rate limits, or error handling. Adequate but not thorough.

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

Conciseness4/5

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

The description is relatively concise, front-loading the purpose. The 'Args' and 'Returns' structure is clear. A minor improvement could be removing 'Args' and 'Returns' labels to be even more succinct.

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

Completeness4/5

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

Given no output schema, the description adequately explains return format (JSON with catalog, database, alias, and CTEs). It covers both input parameters. Missing details like error conditions or dialect validation, but overall sufficient for a simple extraction tool.

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

Parameters4/5

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

Schema coverage is 0%, so description must add meaning. It describes 'sql' as 'SQL statement to analyze' and 'dialect' as 'Optional SQL dialect (e.g., 'mysql', 'postgres')'. This adds useful context beyond the schema's bare types and defaults.

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 clearly states 'Extract table and CTE names from SQL statement', with a specific verb and resource. It distinguishes from siblings like 'get_all_column_references' which extracts columns, making it clear what this tool does.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool vs alternatives like 'lint_sql' or 'transpile_sql'. The description is purely declarative without usage context or exclusions.

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

lint_sqlB
Lint SQL query and return syntax errors

Some syntax errors are not detected by the parser like trailing commas

Args:
    sql: SQL query to analyze
    dialect: Optional SQL dialect (e.g., 'mysql', 'postgres')

Returns:
    error message or "No syntax errors" if parsing succeeds
ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYes
dialectNo

TDQS

B3.2/5.0
Behavior3/5

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

Discloses a limitation (some errors like trailing commas undetected) which adds value beyond name. However, without annotations, it does not confirm read-only behavior or side effects, leaving some behavioral ambiguity.

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

Conciseness4/5

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

Two sentences plus a bullet-like Args/Returns. First sentence front-loads purpose, second adds a key caveat. No fluff, though integration of Args could be tighter.

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

Completeness3/5

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

Explains return value format, which is helpful. But missing details like what constitutes a syntax error, handling of invalid inputs, or scope (e.g., only syntax, not semantics). Adequate but not comprehensive.

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 0%, so description must compensate. The Args section adds 'SQL query to analyze' for sql and 'Optional SQL dialect (e.g., 'mysql', 'postgres')' for dialect, providing examples. But sql parameter lacks details on input format or constraints.

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

Purpose4/5

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

The description clearly states it lints SQL queries and returns syntax errors, with a specific verb 'Lint' and resource 'SQL query'. It distinguishes from siblings that handle references and transpilation, though not explicitly.

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

Usage Guidelines2/5

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

No guidance on when to use vs alternatives. Only implies use for syntax checking, but no 'when not to use' or comparison with siblings like transpile_sql.

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

transpile_sqlA
Transpile SQL statement to another dialect

Args:
    sql: SQL statement to transpile
    read_dialect: SQL dialect to read from
    write_dialect: SQL dialect to write to

Returns:
    transpiled SQL or syntax error
ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYes
read_dialectYes
write_dialectYes

TDQS

A3.9/5.0
Behavior3/5

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

The description mentions it returns transpiled SQL or a syntax error, indicating a pure transformation. However, it does not disclose potential side effects, error handling details, or whether it modifies anything. With no annotations, this is minimally adequate.

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?

Two short lines with a structured Args/Returns section. No redundant words, front-loads the core purpose.

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?

Given the tool's simplicity (3 string params, no output schema), the description covers the purpose, parameters, and return value adequately. No gaps for this complexity level.

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

Parameters4/5

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

The docstring explains each parameter (sql, read_dialect, write_dialect) with brief descriptions, compensating for the 0% schema description coverage. The meaning is clear but could include dialect format or examples.

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 first line clearly states it transpiles a SQL statement to another dialect, specifying the verb (transpile) and resource (SQL dialect conversion). It is distinct from siblings like lint_sql and get_all_table_references.

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

Usage Guidelines2/5

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

No guidance on when to use this tool vs alternatives (e.g., lint_sql for validation). No mention of prerequisites or conditions that make this tool preferable.

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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 4 tool updatesv0.1.0
    • First observedget_all_column_references
    • First observedget_all_table_references
    • First observedlint_sql
    • First observedtranspile_sql

TDQS

A3.8/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: extracting column references, linting syntax, transpiling dialects, and extracting table references. There is no overlap or ambiguity.

Naming Consistency5/5

All tool names follow a consistent verb_object pattern in snake_case (e.g., get_all_column_references, lint_sql), making them predictable and readable.

Tool Count5/5

With 4 tools, the server is well-scoped for SQL analysis. Each tool serves a core function without being excessive or insufficient.

Completeness4/5

The tool set covers key SQL analysis tasks (extracting references, linting, transpilation). Missing features like formatting or optimization advice are minor gaps.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables natural language database querying through GPT-powered SQL generation and execution with metadata-driven validation and intermediate representation.
    -
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables natural language querying of SQL databases with robust safety guarantees including read-only enforcement, AST validation, and row caps.
    -
  • A
    license
    Not graded
    quality
    A
    maintenance
    Deterministic SQL static analysis and query-equivalence checking for Postgres, MySQL, SQLite, and SQL Server. Tokenizes locally before forwarding to the API.
    6
    Apache 2.0

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/j4c0bs/mcp-server-sql-analyzer'

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