Skip to content

Commit e073902

Browse files
ajitpratap0Ajit Pratap Singhclaude
authored
feat: add MCP server exposing GoSQLX SQL tools over streamable HTTP (#358)
* chore: add .worktrees/ to .gitignore for git worktree support Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add MCP server exposing GoSQLX SQL tools over streamable HTTP 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> * fix: resolve CI failures — lint and Go 1.21 incompatibility - 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> * chore: remove junk files and outdated archived docs - 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> * docs: add comprehensive MCP server guide (docs/MCP_GUIDE.md) * docs: update README with MCP server feature, installation block, and Go 1.23+ requirement * docs: update Go version to 1.23+ and add MCP link in getting started * docs: add MCP server to architecture diagram and MCP Architecture section * docs: add pkg/mcp to API reference package tree and MCP Package section * docs: add MCP server environment variables to configuration guide * docs: add [Unreleased] MCP server entry to CHANGELOG * test(mcp): comprehensive test suite — 95.8% coverage with race, integration, protocol tests Add 6 test files covering all MCP server code paths: - tools_internal_test.go: 27 direct tests for internal functions - server_integration_test.go: 5 HTTP auth middleware tests - concurrency_test.go: 3 race condition tests (270+ goroutines) - protocol_test.go: 11 MCP protocol round-trip tests via in-process client - tools_test.go: 12 edge-case SQL tests (CTEs, window functions, injections) - server_test.go: 3 server lifecycle tests (start, shutdown, port-in-use) - scripts/mcp-e2e-test.sh: JSON-RPC E2E shell script Also fix go vet in Taskfile to exclude CGo-dependent pkg/cbinding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(mcp): add Mcp-Session-Id header to E2E test script Streamable HTTP transport requires session ID on all requests after initialization. Capture the header from the initialize response and pass it on all subsequent JSON-RPC calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Ajit Pratap Singh <ajitpratapsingh@Ajits-Mac-mini-2655.local> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a524570 commit e073902

34 files changed

Lines changed: 5522 additions & 1020 deletions

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
go-version: ['1.21', '1.24']
14+
go-version: ['1.23', '1.24']
1515

1616
steps:
1717
- uses: actions/checkout@v4
@@ -34,7 +34,7 @@ jobs:
3434
fail-fast: false
3535
matrix:
3636
os: [ubuntu-latest, macos-latest, windows-latest]
37-
go: ['1.21', '1.24']
37+
go: ['1.23', '1.24']
3838
env:
3939
# Prevent Go from auto-downloading toolchain which conflicts with setup-go cache
4040
GOTOOLCHAIN: local

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Built binary executables (only in root directory)
1212
/gosqlx
13+
/gosqlx-mcp
1314

1415
# Output of the go coverage tool, specifically when used with LiteIDE
1516
*.out
@@ -54,3 +55,6 @@ build/
5455
# Python version files (not needed for Go project)
5556
.python-version
5657
sql-validator
58+
59+
# Git worktrees
60+
.worktrees/

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ All notable changes to GoSQLX will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased] — MCP Server
9+
10+
### ✨ New Features
11+
- **MCP Server** (`pkg/mcp/`, `cmd/gosqlx-mcp/`): All GoSQLX SQL capabilities as Model Context Protocol tools over streamable HTTP
12+
- 7 tools: `validate_sql`, `format_sql`, `parse_sql`, `extract_metadata`, `security_scan`, `lint_sql`, `analyze_sql`
13+
- Optional bearer token auth via `GOSQLX_MCP_AUTH_TOKEN`
14+
- `analyze_sql` fans out all 6 tools concurrently via `sync.WaitGroup`
15+
- Multi-dialect validation: postgresql, mysql, sqlite, sqlserver, oracle, snowflake, generic
16+
17+
### 📝 Documentation
18+
- `docs/MCP_GUIDE.md` — comprehensive MCP server guide
19+
- `README.md` — MCP feature bullet, installation block, docs table entry
20+
- `docs/ARCHITECTURE.md` — MCP in application layer diagram, new MCP Architecture section
21+
- `docs/API_REFERENCE.md` — pkg/mcp package docs
22+
- `docs/CONFIGURATION.md` — MCP env vars reference
23+
- Go version references updated from 1.21+ to 1.23+ (required by mark3labs/mcp-go)
24+
25+
### 🔧 Build
26+
- Go minimum bumped to 1.23.0 (required by `github.com/mark3labs/mcp-go v0.45.0`)
27+
- Taskfile: `mcp`, `mcp:build`, `mcp:test`, `mcp:install` tasks added
28+
29+
---
30+
831
## [1.9.3] - 2026-03-08 — License Detection Fix
932

1033
### 🐛 Bug Fixes

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
GoSQLX is a **production-ready**, **race-free**, high-performance SQL parsing SDK for Go that provides lexing, parsing, and AST generation with zero-copy optimizations. The library is designed for enterprise use with comprehensive object pooling for memory efficiency.
88

9-
**Requirements**: Go 1.21+
9+
**Requirements**: Go 1.23+ (upgraded from 1.21 when MCP server was added; `mark3labs/mcp-go` requires 1.23)
1010

1111
**Production Status**: ✅ Validated for production deployment (v1.6.0+, current: v1.9.0)
1212
- Thread-safe with zero race conditions (20,000+ concurrent operations tested)

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<h3>⚡ High-Performance SQL Parser for Go ⚡</h3>
88

9-
[![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=for-the-badge&logo=go)](https://go.dev)
9+
[![Go Version](https://img.shields.io/badge/Go-1.23+-00ADD8?style=for-the-badge&logo=go)](https://go.dev)
1010
[![Release](https://img.shields.io/github/v/release/ajitpratap0/GoSQLX?style=for-the-badge&color=orange)](https://github.com/ajitpratap0/GoSQLX/releases)
1111
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge)](https://www.apache.org/licenses/LICENSE-2.0)
1212
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge)](http://makeapullrequest.com)
@@ -65,6 +65,7 @@ GoSQLX is a high-performance SQL parsing library designed for production use. It
6565
- **Zero-Copy**: Direct byte slice operations, <1μs latency
6666
- **Intelligent Errors**: Structured error codes with typo detection, context highlighting, and helpful hints
6767
- **Python Bindings**: [PyGoSQLX](python/README.md) — use GoSQLX from Python via ctypes FFI, 100x+ faster than pure Python parsers
68+
- **MCP Server** (v1.10.0): `gosqlx-mcp` exposes all 7 SQL tools as [Model Context Protocol](https://modelcontextprotocol.io) tools over streamable HTTP — integrate GoSQLX into Claude, Cursor, and any MCP-compatible AI assistant
6869
- **Production Ready**: Battle-tested with 0 race conditions detected, ~85% SQL-99 compliance, Apache-2.0 licensed
6970

7071
### Performance & Quality Highlights (v1.9.0)
@@ -153,8 +154,19 @@ print(tables) # ['users', 'orders']
153154

154155
See the full [PyGoSQLX documentation](python/README.md) for the complete API.
155156

157+
### MCP Server
158+
159+
Use GoSQLX SQL tools from any MCP-compatible AI assistant (Claude, Cursor, etc.):
160+
161+
```bash
162+
go install github.com/ajitpratap0/GoSQLX/cmd/gosqlx-mcp@latest
163+
gosqlx-mcp # starts on 127.0.0.1:8080
164+
```
165+
166+
See the full [MCP Server Guide](docs/MCP_GUIDE.md) for configuration, authentication, and AI assistant integration.
167+
156168
**Requirements:**
157-
- Go 1.21 or higher
169+
- Go 1.23 or higher
158170
- Python 3.8+ (for Python bindings)
159171
- No external dependencies for the Go library
160172

@@ -402,6 +414,7 @@ func main() {
402414
| [**Usage Guide**](docs/USAGE_GUIDE.md) | Detailed patterns and best practices |
403415
| [**Architecture**](docs/ARCHITECTURE.md) | System design and internal architecture |
404416
| [**Python Bindings**](python/README.md) | PyGoSQLX — Python API, installation, and examples |
417+
| [**MCP Server Guide**](docs/MCP_GUIDE.md) | `gosqlx-mcp` — 7 SQL tools for AI assistant integration |
405418
| [**Troubleshooting**](docs/TROUBLESHOOTING.md) | Common issues and solutions |
406419

407420
### Getting Started

Taskfile.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ tasks:
194194
desc: Run go vet
195195
cmds:
196196
- echo "Running go vet..."
197-
- go vet ./...
197+
- go vet $(go list ./... | grep -v 'pkg/cbinding')
198198

199199
lint:
200200
desc: Run golangci-lint
@@ -298,6 +298,33 @@ tasks:
298298
cmds:
299299
- go run ./cmd/gosqlx lsp --log /tmp/gosqlx-lsp.log
300300

301+
# =============================================================================
302+
# MCP SERVER
303+
# =============================================================================
304+
mcp:
305+
desc: Run the MCP server (env vars GOSQLX_MCP_HOST, GOSQLX_MCP_PORT, GOSQLX_MCP_AUTH_TOKEN)
306+
cmds:
307+
- go run ./cmd/gosqlx-mcp
308+
309+
mcp:build:
310+
desc: Build the MCP server binary to build/gosqlx-mcp
311+
cmds:
312+
- echo "Building MCP server binary..."
313+
- go build -v -o {{.BUILD_DIR}}/gosqlx-mcp ./cmd/gosqlx-mcp
314+
generates:
315+
- '{{.BUILD_DIR}}/gosqlx-mcp'
316+
317+
mcp:test:
318+
desc: Run MCP package tests with race detection
319+
cmds:
320+
- echo "Testing MCP package..."
321+
- go test -race -timeout 60s ./pkg/mcp/... ./cmd/gosqlx-mcp/...
322+
323+
mcp:install:
324+
desc: Install gosqlx-mcp binary globally
325+
cmds:
326+
- go install ./cmd/gosqlx-mcp
327+
301328
# =============================================================================
302329
# EXAMPLES
303330
# =============================================================================

0 commit comments

Comments
 (0)