Documentation
¶
Overview ¶
Package sqlmcp provides a SQL MCP server: a relationally complete data access surface for AI agents over PostgreSQL, MySQL, and OceanBase, modeled on Microsoft's Data API Builder SQL MCP Server.
Design pillars:
- Relational algebra IR (core/relalg + core/codegen) — dialect-neutral, mathematically complete; new databases plug in through core/provider.
- Defense-in-depth cost & resource gate — EXPLAIN is one optional layer, not a leash; deterministic LIMIT/timeout and DB-native resource limits backstop unreliable estimates.
- Enterprise safety — RBAC with row-level security, non-blocking audit, and field masking.
- Bounded concurrency with backpressure — no unbounded goroutines.
The core packages depend only on the standard library. External dependencies (the MCP SDK, database drivers, OpenTelemetry, YAML) live under x/ and depend on core, never the reverse. See CONTRIBUTING.md for the coding standard.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
sql-mcp-server
command
Command sql-mcp-server is the entry point.
|
Command sql-mcp-server is the entry point. |
|
core
|
|
|
audit
Package audit defines a best-effort, non-blocking audit sink.
|
Package audit defines a best-effort, non-blocking audit sink. |
|
budget
Package budget provides role/tenant scoped execution budgets.
|
Package budget provides role/tenant scoped execution budgets. |
|
cache
Package cache defines a generic read-result cache with per-table invalidation.
|
Package cache defines a generic read-result cache with per-table invalidation. |
|
codegen
Package codegen renders a relalg.Expr (logical plan) into dialect-specific, fully parameterized SQL.
|
Package codegen renders a relalg.Expr (logical plan) into dialect-specific, fully parameterized SQL. |
|
config
Package config defines the runtime configuration model: database, entities, per-tool toggles, cost thresholds, cache, rate limits, and audit.
|
Package config defines the runtime configuration model: database, entities, per-tool toggles, cost thresholds, cache, rate limits, and audit. |
|
cost
Package cost implements the defense-in-depth cost & resource gate.
|
Package cost implements the defense-in-depth cost & resource gate. |
|
dialect
Package dialect abstracts SQL dialect differences: identifier quoting, parameter placeholders, EXPLAIN wrapping, and capability negotiation.
|
Package dialect abstracts SQL dialect differences: identifier quoting, parameter placeholders, EXPLAIN wrapping, and capability negotiation. |
|
engine
Package engine enforces bounded concurrency with backpressure, request deduplication (singleflight), and integration with adaptive limiting and the circuit breaker.
|
Package engine enforces bounded concurrency with backpressure, request deduplication (singleflight), and integration with adaptive limiting and the circuit breaker. |
|
entity
Package entity defines the entity abstraction layer: configured tables, views, and procedures exposed to MCP tools, with aliases, field projection, masking, descriptions, role permissions, row-level security, and keys.
|
Package entity defines the entity abstraction layer: configured tables, views, and procedures exposed to MCP tools, with aliases, field projection, masking, descriptions, role permissions, row-level security, and keys. |
|
hook
Package hook defines nil-safe lifecycle callbacks for observability.
|
Package hook defines nil-safe lifecycle callbacks for observability. |
|
introspect
Package introspect defines schema introspection: discovering entity metadata from a live database, and detecting drift between configured and discovered schemas.
|
Package introspect defines schema introspection: discovering entity metadata from a live database, and detecting drift between configured and discovered schemas. |
|
mask
Package mask defines field masking for sensitive data.
|
Package mask defines field masking for sensitive data. |
|
provider
Package provider defines the database adapter contract consumed by the application assembly layer.
|
Package provider defines the database adapter contract consumed by the application assembly layer. |
|
ratelimit
Package ratelimit provides adaptive concurrency control (AIMD) and a circuit breaker.
|
Package ratelimit provides adaptive concurrency control (AIMD) and a circuit breaker. |
|
rbac
Package rbac defines authorization with row-level security.
|
Package rbac defines authorization with row-level security. |
|
relalg
Package relalg defines a dialect-neutral relational algebra intermediate representation (IR).
|
Package relalg defines a dialect-neutral relational algebra intermediate representation (IR). |
|
store
Package store defines the database execution abstraction used by core tools.
|
Package store defines the database execution abstraction used by core tools. |
|
tool
Package tool defines the DML tool components and their registry.
|
Package tool defines the DML tool components and their registry. |
|
eval
|
|
|
runner
command
Command runner executes the Agent Eval pilot: a fixed task set (eval/tasks.yaml) against a deterministic fixture, driven by any OpenAI-compatible chat-completions endpoint with tool calling.
|
Command runner executes the Agent Eval pilot: a fixed task set (eval/tasks.yaml) against a deterministic fixture, driven by any OpenAI-compatible chat-completions endpoint with tool calling. |
|
internal
|
|
|
benchoverhead
command
Command benchoverhead measures the data-plane overhead of the governed tool path against a direct database query on the same connection pool and fixture.
|
Command benchoverhead measures the data-plane overhead of the governed tool path against a direct database query on the same connection pool and fixture. |
|
coveragecheck
command
|
|
|
fmtcheck
command
|
|
|
modelscopesmoke
command
|
|
|
protocolsmoke
command
Command protocolsmoke verifies the two supported MCP transports against a real database: it runs the server binary over stdio and over streamable HTTP, and asserts initialize, tools/list, one allowed read (with masking), and one machine-readable denial on each.
|
Command protocolsmoke verifies the two supported MCP transports against a real database: it runs the server binary over stdio and over streamable HTTP, and asserts initialize, tools/list, one allowed read (with masking), and one machine-readable denial on each. |
|
quickstartsmoke
command
|
|
|
testdialect
Package testdialect provides dialect implementations for core package tests.
|
Package testdialect provides dialect implementations for core package tests. |
|
Package version exposes build metadata shared by every server surface.
|
Package version exposes build metadata shared by every server surface. |
|
x
|
|
|
bootstrap
Package bootstrap loads configuration and assembles the application: it resolves secret placeholders, opens the database provider, converts config entities to the core entity model, and wires the registry, authorizer, cost gate, engine, and tools.
|
Package bootstrap loads configuration and assembles the application: it resolves secret placeholders, opens the database provider, converts config entities to the core entity model, and wires the registry, authorizer, cost gate, engine, and tools. |
|
configyaml
Package configyaml decodes YAML runtime configuration.
|
Package configyaml decodes YAML runtime configuration. |
|
mcpserver
Package mcpserver bridges core DML tools to the MCP go-sdk.
|
Package mcpserver bridges core DML tools to the MCP go-sdk. |
|
otel
Package otel adapts the core hook.Hooks callbacks to OpenTelemetry spans and attributes.
|
Package otel adapts the core hook.Hooks callbacks to OpenTelemetry spans and attributes. |
|
providerregistry
Package providerregistry maps database driver names to provider factories.
|
Package providerregistry maps database driver names to provider factories. |
|
providers/all
Package all registers every database provider built into the server binary.
|
Package all registers every database provider built into the server binary. |
|
providers/mysql
Package mysql adapts a MySQL database to the core interfaces.
|
Package mysql adapts a MySQL database to the core interfaces. |
|
providers/oceanbase
Package oceanbase adapts an OceanBase database (MySQL protocol) to the core interfaces.
|
Package oceanbase adapts an OceanBase database (MySQL protocol) to the core interfaces. |
|
providers/postgres
Package postgres adapts a PostgreSQL database to the core interfaces: store.DB/Tx, dialect.Dialect, cost.Explainer, and introspect.Introspector.
|
Package postgres adapts a PostgreSQL database to the core interfaces: store.DB/Tx, dialect.Dialect, cost.Explainer, and introspect.Introspector. |
|
telemetry
Package telemetry provides the minimal metrics set for tool calls: a call counter labeled by tool and outcome, a per-tool duration histogram, and an audit-drop counter, served in Prometheus text exposition format.
|
Package telemetry provides the minimal metrics set for tool calls: a call counter labeled by tool and outcome, a per-tool duration histogram, and an audit-drop counter, served in Prometheus text exposition format. |
Click to show internal directories.
Click to hide internal directories.