An embedded StackQL MCP server for Go programs: cloud queries and provisioning over SQL, compiled into your binary. No runtime dependencies, no npx, no separate install.
Your program carries the signed stackql release binary via go:embed. At
startup this module extracts it to a shared on-disk cache (verifying its
sha256), spawns it as an MCP stdio server, and hands you a connected client
from the official
modelcontextprotocol/go-sdk.
Add the module:
go get github.com/stackql/stackql-mcp-goAdd a go:generate directive where you want the server embedded:
//go:generate go run github.com/stackql/stackql-mcp-go/cmd/stackql-mcp-fetch -platform auto -package maingo generate downloads the release .mcpb bundle for your platform,
verifies it against the published sha256 pin, extracts the server binary,
and writes the go:embed glue (a StackqlMCPBinary() function). Use
-platform all to generate for every supported platform behind build tags;
the binaries belong in .gitignore, regenerate them in CI.
Then start the server and use the MCP session directly:
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(), // generated
})
if err != nil {
// ...
}
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'"},
})
// ...
}The server starts in read_only mode by default: metadata and SELECT
tools work, mutations are refused at call time. Escalation is an explicit
caller decision:
client, err := stackqlmcp.StartServer(ctx, stackqlmcp.Options{
Binary: StackqlMCPBinary(),
Mode: stackqlmcp.ModeSafe, // or ModeDeleteSafe, ModeFullAccess
})| Mode | Allows |
|---|---|
read_only (default) |
metadata, SELECT |
safe |
+ non-destructive mutations (INSERT/UPDATE) |
delete_safe |
+ DELETE |
full_access |
everything |
- Binaries come from the official release
.mcpbbundles on stackql/stackql releases, built and signed by stackql/stackql-mcpb-packaging stackql-mcp-fetchverifies the downloaded bundle against the published per-version sha256 pin before extracting, and records the extracted binary's sha256 in the generated code- At runtime, extraction re-verifies that sha256 before the binary is executed; a tampered or corrupted cache entry is replaced
Supported platforms: linux-x64, linux-arm64, windows-x64,
darwin-universal (both Mac architectures).
The extraction cache is ~/.stackql/mcp-server-bin/<version>/<platform>/,
shared with the StackQL npm and pypi MCP wrappers, so multiple embedders on
one machine extract once. Launch arguments are cwd-independent: the server
only touches its approot (~/.stackql by default), never the working
directory.
cmd/sandboxctl is the demo app: an on-demand infrastructure concierge in a single compiled binary, combining the embedded stackql MCP server with a Claude agent loop (anthropic-sdk-go).
export ANTHROPIC_API_KEY=...
export GOOGLE_CREDENTIALS="$(cat service-account-key.json)"
sandboxctl request "a small linux vm and a bucket in sydney for 2 days" --project my-projectThe flow:
- The agent plans with a
read_onlyserver: resolves regions and machine types, checks quotas, estimates cost, and prints a plan with the exact SQL it intends to run - Nothing is created until you approve (interactive y/N, or
--approve) - On approval, a fresh server starts in
safemode and the agent provisions, labelling everything withsandboxctl-expires=<unix-ts> sandboxctl reap --project my-projectfinds expired sandboxes and tears them down (delete_safemode, same approval gate;--approvemakes it cron-able)
Every SQL statement the agent runs is printed. sandboxctl tools lists
the embedded server's MCP tools and needs no credentials.
Build it:
go generate ./cmd/sandboxctl
go build ./cmd/sandboxctlgo generate ./cmd/sandboxctl # once per clone: fetches the demo's
# embedded binary (gitignored)
go test -short ./... # unit tests
go test ./embed/ # + conformance tests (downloads the release bundle,
# spawns it, exercises the github provider with no
# credentials; ports the packaging repo smoke test)CI runs both on Linux, macOS, and Windows.
- In-process mode: when stackql core exposes a public
pkg/mcpserverAPI, this module gainsStartInProcesswith the same options surface and no embedded binary. The proposal is drafted in docs/upstream-mcpserver-proposal.md.
MIT. MCP registry name: io.github.stackql/stackql-mcp.