mcp-server-sql-analyzer

mcp-server-sql-analyzer

MCP server for SQL analysis, linting, and dialect conversion.

26
Stars
5
Forks
26
Watchers
0
Issues
Provides standardized MCP server capabilities for analyzing, linting, and converting SQL queries across multiple dialects using SQLGlot. Supports syntactic validation, dialect transpilation, extraction of table and column references, and offers tools for understanding query structures. Facilitates seamless workflow integration with AI assistants through a set of MCP tools.

Key Features

SQL syntax validation and linting
Conversion between SQL dialects
Extraction of table references, CTEs, and dependencies
Column usage and relationship analysis
Discovery of supported SQL dialects
Standardized MCP server implementation
Integration-ready tools for AI assistants
Detailed error reporting with position data
Fine-grained analysis of query structure
Support for multiple SQL dialects using SQLGlot

Use Cases

Validating SQL query syntax before execution or suggestion
Translating queries between MySQL, PostgreSQL, and other dialects
Analyzing complex SQL to extract used tables and columns
Assisting with database migration by converting SQL syntax
Providing dialect-specific SQL linting in development tools
Improving AI assistant responses for SQL-related questions
Automating extraction of table and column dependencies for documentation
Checking SQL compatibility across multiple database platforms
Supporting SQL query refactoring and optimization suggestions
Integrating with model-assisted SQL generation and validation workflows

README

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.

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

Using uvx (recommended)

Add this to your claude_desktop_config.json:

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:

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:

bash
# 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:

bash
uv run pytest .

License

MIT

Star History

Star History Chart

Repository Owner

j4c0bs
j4c0bs

User

Repository Details

Language Python
Default Branch main
Size 38 KB
Contributors 2
License MIT License
MCP Verified Nov 12, 2025

Programming Languages

Python
100%

Tags

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • Zaturn

    Zaturn

    Your Co-Pilot For Data Analytics & Business Insights

    Zaturn enables AI models to interact with multiple data sources and generate analytics without requiring users to write SQL or Python code. It supports SQL databases and file formats, providing visual and tabular summaries and offering an interactive web interface similar to Jupyter Notebook. Zaturn can function both as a standalone platform or as a Model Context Protocol (MCP) compliant tool, allowing seamless context management for AI-driven data analysis.

    • 66
    • MCP
    • kdqed/zaturn
  • GIS MCP Server

    GIS MCP Server

    Empower AI with advanced geospatial operations via Model Context Protocol.

    GIS MCP Server provides a Model Context Protocol (MCP) server implementation that enables Large Language Models to access and perform sophisticated GIS operations. It bridges AI assistants with Python geospatial libraries such as Shapely, GeoPandas, PyProj, Rasterio, and PySAL. The server supports a wide range of spatial analysis, coordinate transformations, raster and vector data processing, and geospatial intelligence tasks. By integrating with MCP-compatible clients, it enhances AI tools with precise and extensible spatial capabilities.

    • 70
    • MCP
    • mahdin75/gis-mcp
  • Pydantic Logfire MCP Server

    Pydantic Logfire MCP Server

    Enables LLMs to access and analyze application telemetry data through standardized MCP tools.

    Pydantic Logfire MCP Server provides an MCP-compatible interface to access, analyze, and query telemetry data sent to Pydantic Logfire. It allows LLMs to retrieve distributed traces, perform SQL queries on telemetry databases, and generate links for trace inspection. The server can be integrated with well-known MCP clients and supports configuration for secure access with read tokens.

    • 124
    • MCP
    • pydantic/logfire-mcp
  • Panther MCP Server

    Panther MCP Server

    Natural language and IDE-powered server for detection, alert triage, and data lake querying in Panther.

    Panther MCP Server enables interactive management of security alerts, data lake queries, and scheduled reporting using natural language and integrated tools. It allows users to write and tune detections from an IDE, triage and comment on alerts, and execute advanced queries against security logs. The system provides a wide range of operations including alert investigation, bulk updates, AI-powered triage insight generation, and data lake schema exploration. Integration with the Model Context Protocol ensures standardized and extensible interactions for security operations.

    • 32
    • MCP
    • panther-labs/mcp-panther
  • MCP 数据库工具 (MCP Database Utilities)

    MCP 数据库工具 (MCP Database Utilities)

    A secure bridge enabling AI systems safe, read-only access to multiple databases via unified configuration.

    MCP Database Utilities provides a secure, standardized service for AI systems to access and analyze databases like SQLite, MySQL, and PostgreSQL using a unified YAML-based configuration. It enforces strict read-only operations, local processing, and credential protection to ensure data privacy and integrity. The tool is suitable for entities focused on data privacy and minimizes risks by isolating database connections and masking sensitive data. Designed for easy integration, it supports multiple installation options and advanced capabilities such as schema analysis and table browsing.

    • 85
    • MCP
    • donghao1393/mcp-dbutils
  • AI Distiller (aid)

    AI Distiller (aid)

    Efficient codebase summarization and context extraction for AI code generation.

    AI Distiller enables efficient distillation of large codebases by extracting essential context, such as public interfaces and data types, discarding method implementations and non-public details by default. It helps AI agents like Claude, Cursor, and other MCP-compatible tools understand project architecture more accurately, reducing hallucinations and code errors. With configurable CLI options, it generates condensed contexts that fit within AI model limitations, improving code generation accuracy and integration with the Model Context Protocol.

    • 106
    • MCP
    • janreges/ai-distiller
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results