Skip to main content

How to embed the StackQL MCP server in a Rust application

StackQL's MCP server can run inside a Rust binary with no npx, no separate install, and no runtime dependency. The stackql-mcp crate spawns the signed StackQL binary over stdio behind an rmcp client, so your Rust app gets a governed, self-describing SQL interface to every cloud and SaaS provider in the StackQL registry. This is the pattern behind auditron, a terminal compliance copilot shipped as one binary.

Steps

  1. Add the crate to Cargo.toml:
stackql-mcp = "0.1"
  1. Build the server and list tools. The builder defaults to Mode::ReadOnly:
use stackql_mcp::{Mode, StackqlMcp};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = StackqlMcp::builder()
.mode(Mode::ReadOnly)
.auth(serde_json::json!({"github": {"type": "null_auth"}}))
.start()
.await?;
let tools = server.list_all_tools().await?;
println!("{} tools available", tools.len());
server.shutdown().await?;
Ok(())
}

The builder also exposes .binary(), .bundle_path(), .approot(), and .command(). MSRV is Rust 1.88.

  1. Choose a mode. .mode() defaults to Mode::ReadOnly. Set Mode::Safe, Mode::DeleteSafe, or Mode::FullAccess only when the app needs to provision. Escalation is explicit.

Ship a single binary with include_bytes!

Two feature flags control how the binary is sourced:

  • sidecar (default) - download, verify, and cache the signed binary on first run.
  • vendored - embed the binary with include_bytes! for a single self-contained executable.

The vendored binary adds roughly 80 MB to the build.

Demo app

auditron is a terminal compliance copilot: a TUI that streams pass/fail results with the SQL shown and Claude explanations, shipped as an ~80 MB vendored single binary.