mcp-server-sql-analyzer
The mcp-server-sql-analyzer
offers SQL analysis, linting, and dialect conversion for AI models using the Model Context Protocol (MCP).

mcp-server-sql-analyzer Solution Overview
The mcp-server-sql-analyzer
is an MCP server designed to enhance AI models' interaction with SQL databases. It provides powerful SQL analysis, linting, and dialect conversion capabilities using SQLGlot. This server empowers AI models to validate SQL syntax, convert queries between different dialects (like MySQL to PostgreSQL), and extract table/column references.
By offering tools like lint_sql
, transpile_sql
, get_all_table_references
, and get_all_column_references
, it addresses key developer pain points related to SQL syntax errors, dialect compatibility, and query understanding. The server seamlessly integrates with AI models, allowing them to generate, validate, and optimize SQL queries dynamically. This ensures that AI-generated SQL is accurate, dialect-appropriate, and efficient. The core value lies in enabling AI to provide more reliable and helpful SQL-related assistance, reducing the risk of errors and improving overall database interaction. It can be easily integrated using uvx or uv, as outlined in the configuration.
mcp-server-sql-analyzer Key Capabilities
SQL Syntax Validation
The lint_sql
tool is a core feature of the mcp-server-sql-analyzer
, providing real-time SQL syntax validation. It analyzes SQL queries for syntax errors, ensuring that the SQL code adheres to the specified dialect's rules. This tool is crucial for preventing runtime errors and ensuring that SQL queries are correctly formed before execution. The lint_sql
tool accepts an SQL query and an optional dialect parameter as input. It returns a ParseResult
object, which includes a boolean indicating whether the SQL is valid, and an error message if the SQL is invalid. The error message includes the line and column number where the error occurred, facilitating quick debugging.
For example, a developer can use this tool to validate a complex SQL query before deploying it to a production database. By specifying the correct dialect, the developer can ensure that the query is compatible with the target database system, preventing potential issues during runtime. Claude can use this to validate SQL before suggesting it to users, ensuring correctness.
Technically, this feature leverages SQLGlot's parsing capabilities to analyze the SQL syntax. SQLGlot's comprehensive grammar definitions for various SQL dialects enable accurate and reliable syntax validation.
SQL Dialect Conversion
The transpile_sql
tool enables the conversion of SQL queries between different SQL dialects. This feature is essential for organizations migrating databases or working with multiple database systems. The tool takes an SQL query, a source dialect, and a target dialect as input. It then converts the SQL query from the source dialect to the target dialect, ensuring that the converted query is syntactically correct and semantically equivalent to the original query. The transpile_sql
tool returns a TranspileResult
object, which includes a boolean indicating whether the transpilation was successful, an error message if the transpilation failed, and the transpiled SQL query if the transpilation was successful.
Consider a scenario where a company is migrating its database from MySQL to PostgreSQL. The transpile_sql
tool can be used to convert existing MySQL queries to PostgreSQL, reducing the manual effort required for the migration. This ensures that the application continues to function correctly after the migration. Claude can use this to help users migrate queries between different database systems, accurately converting the syntax while preserving the query's logic.
This feature utilizes SQLGlot's transpilation capabilities, which involve parsing the SQL query into an abstract syntax tree (AST) and then generating the equivalent SQL query in the target dialect. SQLGlot's extensive dialect support and transformation rules ensure accurate and reliable dialect conversion.
Table and Column Reference Extraction
The get_all_table_references
and get_all_column_references
tools provide the ability to extract table and column references from SQL queries. These features are valuable for understanding complex SQL queries, analyzing data dependencies, and optimizing query performance. The get_all_table_references
tool extracts all table references from an SQL query, including the table name, alias, and fully qualified name. The get_all_column_references
tool extracts all column references from an SQL query, including the column name, table name, and fully qualified name. Both tools return a TableReferencesResult
or ColumnReferencesResult
object, which includes a boolean indicating whether the analysis was successful, a status message, and a list of table or column references.
For instance, a data analyst can use these tools to understand the data lineage of a complex SQL query. By extracting the table and column references, the analyst can trace the flow of data through the query and identify potential data quality issues. Claude can use this to understand complex queries, making it easier to explain query structure and suggest optimizations.
These features leverage SQLGlot's parsing capabilities to analyze the SQL query and extract the relevant table and column references. SQLGlot's AST representation of the SQL query enables accurate and efficient extraction of these references.