JM

j4c0bs/mcp-server-sql-analyzer

数据库管理

本页由 AI 翻译,技术细节请以原文为准。 查看原文

32 stars 7 forks 质量 63 趋势 11MIT

用于SQL静态分析的MCP服务器。

概览

一个模型上下文协议(MCP)服务器,提供使用 SQLGlot 进行 SQL 分析、linting 和方言转换功能。 SQL 分析器 MCP 服务器提供分析和处理 SQL 查询的工具。它有助于: - SQL 语法验证与线条处理 - 不同 SQL 方言间查询转换(例如 MySQL 转 PostgreSQL)- 提取和分析表引用及依赖关系 - 识别列使用和关系 - 发现支持的 SQL 方言 作为一名人工智能助手,这台服务器通过以下方式提升了我帮助用户高效操作SQL的能力: 1. : 我可以在向用户建议前即时验证SQL语法,确保提供正确且符合方言的查询。 2. : 当用户需要在不同数据库系统间迁移查询时,我可以在保持查询逻辑的同时准确转换语法。 3.

概述(AI 翻译)

一个模型上下文协议(MCP)服务器,提供使用 SQLGlot 进行 SQL 分析、linting 和方言转换功能。

概述

SQL 分析器 MCP 服务器提供分析和处理 SQL 查询的工具。它有助于:

  • SQL 语法验证与 linting
  • 在不同SQL方言之间转换查询(例如,MySQL转PostgreSQL)
  • 提取和分析表引用及依赖关系
  • 识别列的使用情况及其关系
  • 发现支持的SQL方言

克劳德如何使用这个服务器

作为一名人工智能助手,这台服务器通过以下方式提升了我帮助用户高效操作SQL的能力:

  1. 查询验证:我可以在向用户建议SQL语法前即时验证,确保提供正确且方言合适的查询。

  2. 方言转换:当用户需要在不同数据库系统间迁移查询时,我可以准确转换语法,同时保持查询逻辑。

  3. 代码分析:表列引用分析帮助我理解复杂查询,更容易解释查询结构并提出优化建议。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 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

在 GitHub 查看完整 README

安装

uvx --from git+https://github.com/j4c0bs/mcp-server-sql-analyzer.git mcp-server-sql-analyzer
新手?先看 mcpskill.org 教程 →

配置

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