SQL validation, formatting, parsing, metadata extraction, linting, and security analysis.
MCP Server: io.github.ajitpratap0/gosqlx
The MCP server io.github.ajitpratap0/gosqlx provides SQL-related functionality including validation, formatting, parsing, metadata extraction, linting, and security analysis.
Use this when the user wants a complete review of a SQL query. Runs validate, parse, metadata, security, lint, and format concurrently and returns one composite report; hosts that support MCP Apps render it as an interactive report.
Use this when the user wants the tables, columns, and functions a SQL query references (e.g. for lineage or impact analysis). Returns {tables, columns, functions}.
Use this when the user wants SQL pretty-printed or reformatted: one clause per line, optional upper-case keywords and trailing semicolon. Comments are preserved; unplaceable optimizer hints are refused. Returns {formatted_sql, options}.
Parameters4
add_semicolon
boolean
optional
Append a trailing semicolon (default: false)
indent_size
number
optional
Spaces per indent level for nested blocks such as CREATE TABLE columns; clauses always start at column 0. 0 puts each statement on one line (default: 2)
sql
string
required
The SQL string to format
uppercase_keywords
boolean
optional
true upper-cases all SQL keywords (AND, IN, CASE, ...), but not data type names. false keeps the formatter's casing: clause keywords (SELECT, FROM, WHERE, ...) upper-case, other keywords (e.g. like) may keep their input case (default: false)
Raw schema
{
"type": "object",
"properties": {
"add_semicolon": {
"description": "Append a trailing semicolon (default: false)",
"type": "boolean"
},
"indent_size": {
"description": "Spaces per indent level for nested blocks such as CREATE TABLE columns; clauses always start at column 0. 0 puts each statement on one line (default: 2)",
"type": "number"
},
"sql": {
"description": "The SQL string to format",
"type": "string"
},
"uppercase_keywords": {
"description": "true upper-cases all SQL keywords (AND, IN, CASE, ...), but not data type names. false keeps the formatter's casing: clause keywords (SELECT, FROM, WHERE, ...) upper-case, other keywords (e.g. like) may keep their input case (default: false)",
"type": "boolean"
}
},
"required": [
"sql"
]
}
lint_sql
Use this when the user wants SQL style feedback. Applies the same 10 rules as `gosqlx lint`: L001 trailing whitespace, L002 mixed indentation, L003 consecutive blank lines, L004 indentation depth, L005 line length (>100), L006 column alignment, L007 keyword case (upper), L008 comma placement (trailing), L009 aliasing consistency, L010 redundant whitespace. Returns {violation_count, violations}.
Use this when the user wants to know how SQL parses: returns an AST summary with the statement count and the type of each statement, optionally for a specific dialect. GO batch separators are excluded from the count.
Use this when the user wants SQL checked for injection patterns: tautologies, UNION attacks, stacked queries, comment bypasses, and more. Returns findings with severity counts.
Use this when the user wants to know whether a SQL statement is syntactically valid, optionally for a specific dialect. Returns {valid: bool, error?: string, dialect?: string}.
† Parse stage only (pre-tokenized input to AST), SELECT id, name FROM users, Apple M4, Go 1.27, median of 20 runs of BenchmarkPerformanceBaseline. Complex queries take longer (see performance_baselines.json). Reproduce: go test -run ^$ -bench BenchmarkPerformanceBaseline -benchmem -count=20 ./pkg/sql/parser/.
What is GoSQLX?
GoSQLX is a production-ready SQL parsing SDK for Go. It tokenizes, parses, and generates ASTs from SQL with zero-copy optimizations and intelligent object pooling - parsing a simple SELECT in about 363 ns (~2.8M parses/sec).
Why GoSQLX?
Not an ORM - a parser. You get the AST, you decide what to do with it.
Not slow - zero-copy tokenization, sync.Pool recycling, no allocations on hot paths.
Not limited - PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, ClickHouse. CTEs, window functions, MERGE, set operations.
Not just a library - CLI, VS Code extension, GitHub Action, MCP server, WASM playground, Python bindings.
Install
Go library
bash
go get github.com/ajitpratap0/GoSQLX
CLI
bash
go install github.com/ajitpratap0/GoSQLX/cmd/gosqlx@latest
VS Code
bash
code --install-extension ajitpratap0.gosqlx
The extension bundles the binary, so there is no extra setup. Learn more.
MCP server
bash
claude mcp add --transport http gosqlx https://mcp.gosqlx.dev/mcp
7 SQL tools in Claude, Cursor, or any MCP client. MCP guide.
Claude Code plugin (skills, slash commands, SQL reviewer agent): /plugin marketplace add ajitpratap0/GoSQLX then /plugin install gosqlx@gosqlx - details.
ChatGPT app: add https://mcp.gosqlx.dev/mcp as a connector in developer mode for an interactive analysis widget - details.
package main
import (
"context""errors""fmt""log""github.com/ajitpratap0/GoSQLX/pkg/gosqlx""github.com/ajitpratap0/GoSQLX/pkg/sql/ast"
)
funcmain() {
ctx := context.Background()
// ParseTree is the recommended entry point. It returns an// opaque handle with built-in helpers.
tree, err := gosqlx.ParseTree(ctx, "SELECT id, name FROM users WHERE active = true",
gosqlx.WithDialect("postgresql"))
if err != nil {
// Sentinel errors work with errors.Isif errors.Is(err, gosqlx.ErrSyntax) {
log.Fatalf("syntax error: %v", err)
}
log.Fatal(err)
}
fmt.Println("Tables:", tree.Tables())
fmt.Println(tree.Format(gosqlx.WithIndent(2), gosqlx.WithUppercaseKeywords(true)))
// Walk the AST - typed walkers avoid the type-assertion dance:
tree.WalkSelects(func(s *ast.SelectStatement)bool {
fmt.Printf(" SELECT with %d columns\n", len(s.Columns))
returntrue
})
// The legacy Parse/Format/Validate API still works for v1.x code.// See docs/MIGRATION.md for the Tree migration guide.
}
Output:
text
Tables: [users]
SELECT id, name
FROM users
WHERE active = true
SELECT with 2 columns
Formatting turns one-line SQL into a readable query:
Features
Parser - zero-copy tokenizer, recursive descent parser and full AST generation.
Tooling - AST-based formatter, query transforms API, VS Code extension and GitHub Action.
Syntax highlighting - dialect-aware highlighting for terminals (ANSI), HTML/CSS, JSON spans, LSP semantic tokens and WASM; gosqlx highlight query.sql or gosqlx.HighlightANSI(sql).
Multi-dialect - 8 dialects with dedicated grammar support: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, ClickHouse. The --dialect flag and WithDialect accept 11 names: those 8 (postgresql, mysql, mariadb, sqlserver, oracle, sqlite, snowflake, clickhouse) plus generic, bigquery and redshift. BigQuery and Redshift have no dialect-specific keyword set (they use the generic keywords) and only capability-gated grammar, such as BigQuery's QUALIFY, PIVOT/UNPIVOT, UNNEST in FROM and (struct).field access.
AI-ready - MCP server with 7 tools, public remote endpoint, Streamable HTTP.
Tested - race-detector clean in CI, ~80-85% SQL-99 (estimated).