Skip to main content
Glama
sqlfluff-mcp-server

sqlfluff-mcp-server

by gswartwood

sqlfluff-mcp-server

PyPI Python versions CI License: MIT

An MCP server that exposes SQLFluff's linting, fixing, and parsing over the Model Context Protocol, so any MCP-aware client (Claude, other agents, IDE integrations) can lint and fix SQL directly.

This project is independent of the SQLFluff maintainers — it's a thin wrapper around the public sqlfluff Python package.

Tools

Tool

Input

Config resolution

lint_file

path on disk

walks up from the file for .sqlfluff / pyproject.toml / etc.

fix_file

path on disk (+ write flag)

same directory walk

parse_file

path on disk

same directory walk

lint_sql

raw SQL text + dialect

none — dialect supplied explicitly

fix_sql

raw SQL text + dialect

none — dialect supplied explicitly

parse_sql

raw SQL text + dialect

none — dialect supplied explicitly

list_dialects

—

lists supported dialect names

clear_config_cache

—

clears SQLFluff's cached config-file contents

The *_file tools honor project config the same way the sqlfluff CLI does (via FluffConfig.from_path, which walks up the directory tree looking for .sqlfluff, pyproject.toml, setup.cfg, or tox.ini). The *_sql tools are for content that hasn't been written to disk (e.g. streamed from an editor buffer) and require you to pass dialect explicitly since there's no file location to resolve config from.

Config caching

SQLFluff caches the contents of config files it reads while walking a directory tree, for the lifetime of the process. Because this server is long-running (unlike the sqlfluff CLI, which is a fresh process per invocation), editing a .sqlfluff file after the server has started won't be picked up by lint_file / fix_file / parse_file until you call clear_config_cache. Call it whenever config on disk changes, or just proactively before a lint/fix/parse call if you're unsure.

Related MCP server: dbt-mcp

Requirements

  • Python 3.10+

  • uv (recommended) or pipx/pip

  • mcp >=2.0.0,<3.0.0 and sqlfluff >=3.0.0 (installed automatically as dependencies — see Notes on dependencies)

Registering with an MCP client

This package is published on PyPI, so there's nothing to clone or install ahead of time. Point your MCP client's config (e.g. .claude.json / .mcp.json for Claude Code, or Claude Desktop's config file) at it via uvx, and it's fetched into an isolated cache and launched on demand:

{
  "mcpServers": {
    "sqlfluff": {
      "command": "uvx",
      "args": ["sqlfluff-mcp-server"]
    }
  }
}

No uv? pipx run sqlfluff-mcp-server as the command/args works the same way.

For stdio-based servers like this one, the client itself launches the process — automatically, when the client session starts, not when a prompt first needs it. Once it's registered, just ask the client to lint or fix a SQL file; the server is already running in the background and the tools are already available. If the server process crashes, the client restarts it for you.

Running it manually (for local testing/debugging)

uvx sqlfluff-mcp-server

This starts the server over stdio and blocks, waiting for an MCP client to speak the protocol to it on stdin/stdout — it's not something you'd run interactively day to day, just useful for sanity-checking the install or piping through the MCP Inspector.

Development

Clone the repo to work on the server itself (rather than just consuming it via uvx):

git clone <this-repo-url>
cd sqlfluff-mcp-server
uv sync --extra dev
uv run pytest
uv run ruff check .

To point an MCP client at your local checkout instead of the PyPI release (e.g. to test unreleased changes):

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

Notes on dependencies

  • mcp is pinned to >=2.0.0,<3.0.0. The SDK's 2.0 line renamed mcp.server.fastmcp.FastMCP to mcp.server.mcpserver.MCPServer and moved transport selection to run(transport=...); the @mcp.tool() decorator API is unchanged.

  • sqlfluff is left unpinned above 3.0.0 — SQLFluff releases fairly often and this server only depends on its stable Linter / FluffConfig API.

License

MIT — see LICENSE.

Available Tools

8 tools
clear_config_cacheA

Clear SQLFluff's internal config-file cache.

SQLFluff caches the contents of .sqlfluff / pyproject.toml / setup.cfg / tox.ini files it reads while walking up a directory tree (keyed by file path, for the lifetime of this server process). If you edit a config file on disk while this server is running, the *_file tools may keep returning results based on the old contents until this cache is cleared. Call this tool after editing any SQLFluff config file to force the next lint_file / fix_file / parse_file call to re-read it from disk.

Inputs: no named parameters. Returns: object

fix_fileA

Fix a SQL file on disk, honoring discovered .sqlfluff config.

Args: path: Path to the SQL file to fix. write: If True, overwrite the file in place with the fixed SQL. If False (default), just return the fixed SQL without touching the file. config_path: Optional path to an extra config file to layer on top of whatever is discovered by walking the directory tree.

Inputs: path (required), write, config_path. Returns: object

fix_sqlA

Fix a raw SQL string using an explicitly specified dialect and return the fixed SQL text (does not touch any file).

Args: sql: The SQL text to fix. dialect: SQLFluff dialect name, e.g. "ansi", "bigquery", "snowflake", "postgres". rules: Optional list of rule codes/names to restrict fixing to.

Inputs: sql (required), dialect (required), rules. Returns: object

lint_fileA

Lint a SQL file on disk, honoring any .sqlfluff / pyproject.toml config found by walking up from the file's directory.

Args: path: Path to the SQL file to lint. config_path: Optional path to an extra config file to layer on top of whatever is discovered by walking the directory tree.

Inputs: path (required), config_path. Returns: object

lint_sqlA

Lint a raw SQL string using an explicitly specified dialect.

Args: sql: The SQL text to lint. dialect: SQLFluff dialect name, e.g. "ansi", "bigquery", "snowflake", "postgres". See sqlfluff.list_dialects() for the full set. rules: Optional list of rule codes/names to restrict linting to.

Inputs: sql (required), dialect (required), rules. Returns: object

list_dialectsA

List the SQL dialects SQLFluff supports (for use with lint_sql / fix_sql / parse_sql).

Inputs: no named parameters. Returns: result

parse_fileA

Parse a SQL file on disk and return its parse tree, honoring discovered .sqlfluff config.

Args: path: Path to the SQL file to parse. config_path: Optional path to an extra config file to layer on top of whatever is discovered by walking the directory tree.

Inputs: path (required), config_path. Returns: object

parse_sqlA

Parse a raw SQL string using an explicitly specified dialect and return its parse tree.

Args: sql: The SQL text to parse. dialect: SQLFluff dialect name, e.g. "ansi", "bigquery", "snowflake", "postgres".

Inputs: sql (required), dialect (required). Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool has a clear, distinct purpose: the three file-based tools operate on paths, the three SQL-based tools operate on raw strings, and list_dialects/clear_config_cache serve separate helper roles. No two tools overlap in a way that would confuse an agent.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern: lint/fix/parse paired with file/sql, plus list_dialects and clear_config_cache. The style is uniform (lowercase with underscores) with no mixed conventions.

    Tool Count5/5

    Eight tools is well-scoped for a SQLFluff wrapper: it covers the core operations (lint, fix, parse) for both file and string inputs, plus a dialect listing and cache-clearing utility. No redundancy and no missing essential operation.

    Completeness4/5

    The tool surface covers the main SQLFluff functionality comprehensively—lint, fix, and parse for both files and raw SQL. A few advanced capabilities like rendering or rule-specific configuration are absent, but core workflows are fully supported.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers