← Developer

SQL Formatter

Format and beautify SQL queries directly in your browser. No upload required.

Indentation
Keyword case

Use this tool from AI agents

This tool's engine is available to AI agents over MCP as format_sql. Add the Clean.tools server, then your agent can call it directly.

Claude Code
claude mcp add --transport http clean-tools https://mcp.clean.tools/mcp
Claude Desktop (mcpServers)
{"mcpServers":{"clean-tools":{"command":"npx","args":["-y","@clean-tools/mcp"]}}}
Cursor
https://mcp.clean.tools/mcp

Or call it over plain HTTP from any script. Same engine, JSON in and JSON out, no key:

curl
curl -s https://api.clean.tools/v1/format_sql \ -H 'content-type: application/json' \ -d '{"sql":"select u.id, u.name, count(o.id) as order_count from users u left join orders o on o.user_id = u.id where u.active = true group by u.id, u.name having count(o.id) > 3 order by order_count desc limit 10;","keywordCase":"upper","indent":2}'
JavaScript
const res = await fetch("https://api.clean.tools/v1/format_sql", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({"sql":"select u.id, u.name, count(o.id) as order_count from users u left join orders o on o.user_id = u.id where u.active = true group by u.id, u.name having count(o.id) > 3 order by order_count desc limit 10;","keywordCase":"upper","indent":2}) }); const data = await res.json();

How it works

This SQL formatter parses your query with a self-hosted copy of the open source sql-formatter library and re-prints it with consistent indentation, line breaks, and keyword casing. Choose a dialect (Standard SQL, PostgreSQL, MySQL, Transact-SQL, BigQuery, or SQLite) so dialect-specific syntax is understood, then pick 2 spaces, 4 spaces, or tabs for indentation and set keywords to uppercase, lowercase, or preserved. Formatting runs live as you type.

Everything happens on your device. Your queries are never sent to a server, so it is safe for schemas, table names, and query logic you would rather not paste into a website. It works on any modern browser, on both mobile and desktop. If you would rather format SQL from scripts or an AI agent, the same engine is available through the Clean.tools API as format_sql, or you can install the @clean-tools/mcp package from npm.


Frequently asked questions

Which SQL dialects are supported?

Standard SQL, PostgreSQL, MySQL, Transact-SQL (Microsoft SQL Server), BigQuery, and SQLite. Picking the right dialect helps the formatter recognize keywords and syntax unique to that database, such as BigQuery backtick identifiers or T-SQL square brackets.

Does formatting change what my query does?

No. The formatter only adjusts whitespace, line breaks, and the letter case of recognized keywords. String literals, identifiers, and the logic of your query are left exactly as written, so the reformatted statement runs the same as the original.

Why does it say it could not format my SQL?

The formatter parses the query first, so genuinely invalid syntax (an unclosed string, a stray parenthesis, or a truncated statement) is reported as a parse error instead of being reformatted. Fix the reported spot and the output updates automatically.

Is my SQL uploaded anywhere?

No. The formatting library is loaded and runs entirely in your browser. Nothing you type is transmitted, logged, or stored on a server.

Can I use this from the command line or an AI agent?

Yes. Post your query to the REST endpoint https://api.clean.tools/v1/format_sql and you get the formatted SQL back as JSON, no key required. The same engine is exposed as an MCP server you can add to Claude, Claude Code, or Cursor, and the @clean-tools/mcp package from npm runs it as a local stdio server so agents can call it directly.

More tools from Clean.tools

View all tools

Use Clean.tools from your AI agent

This tool is also format_sql on the Clean.tools MCP server — the same engine, callable by your AI agent directly. No key, no signup: requests are processed in memory and request contents are never stored.

Claude Code
claude mcp add --scope user --transport http clean-tools https://mcp.clean.tools/mcp
Any MCP client (streamable HTTP, authless)
https://mcp.clean.tools/mcp

Every tool, the REST API, and setup for Cursor, Claude Desktop, VS Code & more →