feat: add MCP server exposing GoSQLX SQL tools over streamable HTTP#358
feat: add MCP server exposing GoSQLX SQL tools over streamable HTTP#358ajitpratap0 wants to merge 11 commits intomainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a Model Context Protocol server that wraps GoSQLX's SQL processing capabilities as MCP tools accessible to AI assistants and MCP clients. ## New packages - `pkg/mcp/` — importable library (Config, Server, 7 tool handlers) - `cmd/gosqlx-mcp/` — standalone binary with graceful shutdown ## Tools - validate_sql — syntax validation with optional dialect (7 dialects) - format_sql — formatting with indent/case/semicolon options - parse_sql — AST summary (statement count + types) - extract_metadata — extract tables, columns, functions - security_scan — SQL injection pattern detection (8 pattern types) - lint_sql — style rules L001–L010 - analyze_sql — concurrent fan-out across all 6 tools ## Transport & auth - Streamable HTTP transport (mark3labs/mcp-go v0.45.0) - Optional bearer token auth via GOSQLX_MCP_AUTH_TOKEN env var ## Tasks added - task mcp — run server - task mcp:build — build binary - task mcp:test — race-detected tests - task mcp:install — install globally Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @ajitpratap0's task —— View job Code Review CompleteI've thoroughly reviewed the MCP server implementation. Here's my detailed analysis: Overall Assessment ⭐⭐⭐⭐⭐This is a high-quality implementation that follows Go best practices and integrates well with the existing GoSQLX codebase. The code is production-ready with excellent test coverage and proper error handling. ✅ StrengthsArchitecture & Design
Code Quality
Security Implementation
Performance Design
Repository Integration
🔍 Detailed Code Reviewpkg/mcp/config.go:95-102 ✅Configuration management is excellent:
pkg/mcp/middleware.go:30-37 ✅Auth middleware is clean and secure: if extractBearerToken(r) != cfg.AuthToken {
w.Header().Set("WWW-Authenticate", `Bearer realm="gosqlx-mcp"`)
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}pkg/mcp/tools.go:337-391 ⭐ OutstandingThe concurrent
pkg/mcp/server.go:45-66 ✅Server lifecycle management:
🚀 Performance ConsiderationsConcurrent Analysis: The Memory Efficiency: By using existing GoSQLX APIs, this leverages all the object pooling optimizations already in place (ast.NewAST/ReleaseAST, tokenizer pools, etc.). 🔐 Security Analysis
🧪 Test CoverageExcellent test suite with 22 test functions covering:
📋 Minor SuggestionsEnhancement Opportunities
DocumentationThe inline documentation is excellent. Consider adding examples to the package-level docs showing typical MCP client integration. ✅ Final VerdictApprove with confidence. This implementation:
The PR delivers exactly what it promises: a clean, well-tested MCP server exposing GoSQLX functionality with zero new business logic. Ready for merge! |
- cmd/gosqlx-mcp/main.go: extract run() helper so os.Exit is not called after defer stop() — fixes gocritic exitAfterDefer lint error - .github/workflows/test.yml: bump minimum Go from 1.21 to 1.23 since mark3labs/mcp-go requires go 1.23.0 - CLAUDE.md: document new minimum Go version requirement Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @ajitpratap0's task —— View job MCP Server Implementation ReviewI'll conduct a thorough code review of the MCP server implementation focusing on: Review Checklist:
Overall Assessment ⭐⭐⭐⭐⭐This is a high-quality implementation that follows Go best practices and integrates excellently with the existing GoSQLX codebase. The code is production-ready with comprehensive test coverage and proper error handling. ✅ StrengthsArchitecture & Design
Code Quality
Security Implementation
Performance Design
Repository Integration
🔍 Detailed Code Review
|
- Delete local artifacts: binaries (gosqlx, gosqlx-mcp), test binaries (parser.test, tokenizer.test), .out files, coverage files, .sarif - Remove .worktrees/feature-mcp-server (PR #358 already pushed) - git rm archive/ — explicitly labeled "should not be considered current" and "OUTDATED"; adds noise with no current value - git rm docs/plans/ — LLM internal planning artifact, not user-facing doc Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @ajitpratap0's task —— View job MCP Server Implementation ReviewI'll conduct a thorough code review of the MCP server implementation focusing on: Review Checklist:
Overall Assessment ⭐⭐⭐⭐⭐This is a high-quality implementation that follows Go best practices and integrates excellently with the existing GoSQLX codebase. The code is production-ready with comprehensive test coverage and proper error handling. ✅ StrengthsArchitecture & Design
Code Quality
Security Implementation
Performance Design
Repository Integration
🔍 Detailed Code Review
|
…Go 1.23+ requirement
|
Claude finished @ajitpratap0's task —— View job MCP Server Code ReviewReview Checklist:
Overall Assessment ⭐⭐⭐⭐⭐This is a high-quality implementation that follows Go best practices and integrates excellently with the existing GoSQLX codebase. The code is production-ready with comprehensive test coverage and proper error handling. ✅ StrengthsArchitecture & Design
Code Quality
Security Implementation
Performance Design
Repository Integration
🔍 Detailed Code Review
|
Summary
pkg/mcp/as an importable library andcmd/gosqlx-mcp/as a standalone binary with graceful shutdownTools
validate_sqlgosqlx.Validate/ParseWithDialectformat_sqlgosqlx.Formatparse_sqlgosqlx.Parseextract_metadatagosqlx.ExtractMetadatasecurity_scansecurity.Scanner.ScanSQLlint_sqllinter.Linter.LintStringanalyze_sqlConfiguration
Usage
Test Plan
pkg/mcp/— all pass with-race -count=1go test -race ./...(full suite, zero failures)go fmt,go vet, short tests🤖 Generated with Claude Code