Skip to content

Commit 8122805

Browse files
Ajit Pratap SinghAjit Pratap Singh
authored andcommitted
docs: add pkg/mcp to API reference package tree and MCP Package section
1 parent 6da3a99 commit 8122805

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

docs/API_REFERENCE.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ github.com/ajitpratap0/GoSQLX/
3737
│ ├── metrics/ # Performance monitoring (73.9% coverage)
3838
│ ├── linter/ # SQL linting rules engine (96.7% coverage)
3939
│ ├── lsp/ # Language Server Protocol (70.2% coverage)
40+
│ ├── mcp/ # MCP server — 7 SQL tools over streamable HTTP
4041
│ ├── config/ # Configuration management (81.8% coverage)
4142
│ └── gosqlx/testing/ # Testing utilities (95.0% coverage)
4243
```
@@ -1844,6 +1845,56 @@ func main() {
18441845

18451846
---
18461847

1848+
## MCP Package
1849+
1850+
### Package: `github.com/ajitpratap0/GoSQLX/pkg/mcp`
1851+
1852+
MCP server exposing all GoSQLX capabilities as Model Context Protocol tools over streamable HTTP.
1853+
1854+
### Types
1855+
1856+
#### `Config`
1857+
```go
1858+
type Config struct {
1859+
Host string // GOSQLX_MCP_HOST (default "127.0.0.1")
1860+
Port int // GOSQLX_MCP_PORT (default 8080, range 1–65535)
1861+
AuthToken string // GOSQLX_MCP_AUTH_TOKEN (default "" = auth disabled)
1862+
}
1863+
```
1864+
1865+
### Functions
1866+
1867+
#### `LoadConfig() (*Config, error)`
1868+
Load from env vars. Returns error only if `GOSQLX_MCP_PORT` is non-integer or out of range.
1869+
1870+
#### `DefaultConfig() *Config`
1871+
Returns `Config{Host: "127.0.0.1", Port: 8080}` with auth disabled.
1872+
1873+
#### `New(cfg *Config) *Server`
1874+
Create server with all 7 tools registered. Registers tools once at construction — no dynamic registration.
1875+
1876+
#### `(s *Server) Start(ctx context.Context) error`
1877+
Bind to `cfg.Addr()`, serve streamable HTTP. Blocks until ctx cancelled or fatal error. Graceful shutdown on context cancellation.
1878+
1879+
#### `BearerAuthMiddleware(cfg *Config, next http.Handler) http.Handler`
1880+
Returns `next` unchanged when `cfg.AuthEnabled()` is false. When enabled, enforces `Authorization: Bearer <token>` on all requests; returns HTTP 401 on failure.
1881+
1882+
### Registered Tools
1883+
1884+
| Tool | Description |
1885+
|------|-------------|
1886+
| `validate_sql` | SQL syntax validation with optional dialect |
1887+
| `format_sql` | SQL formatting (indent, keyword case, semicolon) |
1888+
| `parse_sql` | AST summary — statement count and types |
1889+
| `extract_metadata` | Tables, columns, functions referenced |
1890+
| `security_scan` | Injection pattern detection with severity |
1891+
| `lint_sql` | Style rule enforcement (L001–L010) |
1892+
| `analyze_sql` | Concurrent composite of all 6 above |
1893+
1894+
See [MCP Server Guide](MCP_GUIDE.md) for complete tool schemas and JSON response formats.
1895+
1896+
---
1897+
18471898
## Configuration Package
18481899

18491900
### Package: `github.com/ajitpratap0/GoSQLX/pkg/config`
@@ -2267,6 +2318,7 @@ GoSQLX achieves **~80-85% SQL-99 compliance** with comprehensive support for:
22672318
- **GitHub Repository**: https://github.com/ajitpratap0/GoSQLX
22682319
- **Documentation**: See `/docs` directory
22692320
- `GETTING_STARTED.md` - Quick start guide
2321+
- `MCP_GUIDE.md` - MCP server and AI assistant integration
22702322
- `USAGE_GUIDE.md` - Comprehensive usage guide
22712323
- `LSP_GUIDE.md` - LSP server and IDE integration
22722324
- `LINTING_RULES.md` - All 10 linting rules reference

0 commit comments

Comments
 (0)