How to embed the StackQL MCP server in a Go application
StackQL's MCP server can run inside a compiled Go program with no npx, no separate install, and no runtime dependency. The stackql-mcp-go library spawns the signed StackQL binary over stdio behind the official Go MCP SDK client, so your Go app gets a governed, self-describing SQL interface to every cloud and SaaS provider in the StackQL registry. This is the pattern behind sandboxctl, an on-demand infrastructure concierge shipped as one binary.
Steps
- Add the library:
go get github.com/stackql/stackql-mcp-go
- Start the embedded server and call a tool. The server starts in
read_onlymode by default:
import (
"context"
"github.com/modelcontextprotocol/go-sdk/mcp"
stackqlmcp "github.com/stackql/stackql-mcp-go/embed"
)
func main() {
ctx := context.Background()
client, err := stackqlmcp.StartServer(ctx, stackqlmcp.Options{
Binary: StackqlMCPBinary(),
})
if err != nil {
// handle error
}
defer client.Close()
res, err := client.Session.CallTool(ctx, &mcp.CallToolParams{
Name: "run_select_query",
Arguments: map[string]any{"sql": "SELECT name FROM google.compute.regions WHERE project = 'my-project'"},
})
_ = res
}
- Choose a mode.
Options.Modedefaults toread_only. Set it tosafe,delete_safe, orfull_accessonly when the app needs to provision. Escalation is explicit.
Ship a single binary with go:embed
For a self-contained executable, add a go:generate fetch step that downloads and sha256-verifies the platform binary, then go:embed it into the build:
//go:generate go run github.com/stackql/stackql-mcp-go/cmd/stackql-mcp-fetch -platform auto -package main
At runtime StackqlMCPBinary() returns the embedded binary, so there is no first-run download. Without vendoring, the binary is downloaded and verified into the shared cache at ~/.stackql/mcp-server-bin/ on first run.
Demo app
sandboxctl is an infrastructure concierge: an embedded StackQL MCP server plus a Claude agent loop in one Go binary that plans, cost-checks, and provisions ephemeral cloud sandboxes behind an approval gate.
Related concepts
- Embedded MCP: Go reference - install, API, and modes
- How to use StackQL with AI agents - the MCP model and safety modes
- StackQL MCP Architecture - transports, modes, and audit internals
- What is Agentic Infrastructure? - the pattern this enables