Documentation
¶
Overview ¶
Package mcp provides a Model Context Protocol (MCP) server for GoSQLX. It exposes SQL parsing, validation, formatting, linting, and security scanning as MCP tools accessible over streamable HTTP transport.
Quick start ¶
cfg, err := mcp.LoadConfig()
if err != nil {
log.Fatal(err)
}
srv := mcp.New(cfg)
srv.Start(context.Background())
Environment variables ¶
GOSQLX_MCP_HOST bind host (default: 127.0.0.1) GOSQLX_MCP_PORT bind port (default: 8080) GOSQLX_MCP_AUTH_TOKEN bearer token; empty disables auth
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BearerAuthMiddleware ¶
BearerAuthMiddleware returns an http.Handler that enforces bearer token authentication when cfg.AuthEnabled() is true. When auth is disabled it passes all requests through unchanged. On failure it responds 401 with a WWW-Authenticate header.
func NewRateLimiter ¶ added in v1.12.0
func NewRateLimiter() *rateLimiter
NewRateLimiter creates a new rateLimiter, initializes all shards, and starts the background cleanup goroutine.
func RateLimitMiddleware ¶ added in v1.12.0
RateLimitMiddleware creates a rate limiter and returns an http.Handler that enforces the three-layer rate limiting strategy. Requests that exceed limits receive an HTTP 200 response with a JSON-RPC error (MCP clients expect JSON-RPC responses, not HTTP 429).
Types ¶
type Config ¶
type Config struct {
// Host is the interface to bind to.
// Source: GOSQLX_MCP_HOST (default: "127.0.0.1")
Host string
// Port is the TCP port to listen on (1–65535).
// Source: GOSQLX_MCP_PORT (default: 8080)
Port int
// AuthToken is the optional bearer token for request authentication.
// When non-empty every request must carry "Authorization: Bearer <token>".
// Source: GOSQLX_MCP_AUTH_TOKEN (default: "" - auth disabled)
AuthToken string
}
Config holds all MCP server configuration loaded from environment variables. Use LoadConfig or DefaultConfig to obtain a valid Config; the zero value is not valid.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with all defaults applied (auth disabled).
func LoadConfig ¶
LoadConfig reads configuration from environment variables, applying defaults for any variables that are unset or empty.
func (*Config) AuthEnabled ¶
AuthEnabled reports whether bearer token authentication is configured.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps the MCP server with all GoSQLX tools registered.