mcp-server-sql-analyzer
by: j4c0bs
MCP server for SQL static analysis.
📌Overview
Purpose: The SQL Analyzer MCP server aims to provide efficient SQL analysis, linting, and dialect conversion to assist users in working with SQL queries effectively.
Overview: The SQL Analyzer MCP server offers a suite of tools for comprehensive SQL query handling, including syntax validation, dialect conversion, and extraction of table and column references. This enables both developers and their AI assistants to manage SQL queries more effectively while ensuring accuracy and compatibility across different database systems.
Key Features:
-
SQL Syntax Validation and Linting: Validates SQL queries to identify syntax errors, ensuring user queries are correct and compliant before execution.
-
Dialect Conversion: Supports automatic conversion of SQL queries between various database dialects, facilitating seamless transitions and migrations between systems like MySQL and PostgreSQL.
-
Table and Column Reference Extraction: Analyzes SQL queries to extract table and column references, aiding in understanding complex queries and enhancing the ability to optimize them.
-
Compatibility Checking: Provides information on supported SQL dialects and their features, guiding best practices for specific database systems.
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:
- Query Validation: Instantly validate SQL syntax before suggesting it to users, ensuring correct and dialect-appropriate queries.
- Dialect Conversion: Accurately convert the syntax when users migrate queries between different database systems while preserving query logic.
- Code Analysis: Table and column reference analysis helps understand complex queries, making it easier to explain query structure and suggest optimizations.
- Compatibility Checking: Knowing supported dialects and features guides users toward database-specific best practices.
This toolset allows for more accurate and helpful SQL-related assistance while reducing 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
-
lint_sql
Validates SQL query syntax and returns any errors.
Inputs:sql
(string): SQL query to analyzedialect
(string, optional): SQL dialect (e.g., 'mysql', 'postgresql')
Returns:is_valid
(boolean): Whether the SQL is validmessage
(string): Error message or "No syntax errors"position
(object, optional): Line and column of error if present
-
transpile_sql
Converts SQL between different dialects.
Inputs:sql
(string): SQL statement to transpileread_dialect
(string): Source SQL dialectwrite_dialect
(string): Target SQL dialect
Returns:is_valid
(boolean): Whether transpilation succeededmessage
(string): Error message or success confirmationsql
(string): Transpiled SQL if successful
-
get_all_table_references
Extracts table and CTE references from SQL.
Inputs:sql
(string): SQL statement to analyzedialect
(string, optional): SQL dialect
Returns:is_valid
(boolean): Whether analysis succeededmessage
(string): Status messagetables
(array): List of table references with type, catalog, database, table name, alias, and fully qualified name
-
get_all_column_references
Extracts column references with table context.
Inputs:sql
(string): SQL statement to analyzedialect
(string, optional): SQL dialect
Returns:is_valid
(boolean): Whether analysis succeededmessage
(string): Status messagecolumns
(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
:
{
"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