mcp
Command used to launch StackQL as a Model Context Protocol (MCP) server, enabling AI agents and assistants to interact with cloud infrastructure using StackQL's query capabilities.
The Model Context Protocol (MCP) is an open protocol that standardizes how AI applications interact with external data sources and tools. By running StackQL as an MCP server, you can enable AI agents (Claude, Cursor, Continue, custom agents, etc.) to query and manage cloud infrastructure across multiple providers using natural language.
Syntax
stackql mcp [flags] for a standalone MCP server.
stackql srv [flags] to run the MCP server alongside the PostgreSQL wire-protocol server in the same process.
Deployment modes
StackQL's MCP server can be deployed in three different configurations to suit various architectural requirements. The examples below opt into unauthenticated service with "allow_unauthenticated": true, which suits local development; for anything another process or host can reach, configure a bearer token instead (see HTTP client authentication).
1. Standalone MCP server
Run StackQL as a dedicated MCP server on a specified port.
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true}}'
Use case: when you only need MCP protocol access and don't require PostgreSQL wire protocol compatibility.
2. MCP + PostgreSQL server (in-memory)
Run both MCP and PostgreSQL servers simultaneously with in-memory communication between them.
stackql srv \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true}}' \
--pgsrv.port 5665
Use case: when you need both MCP protocol access for AI agents and PostgreSQL wire protocol for traditional database clients, with maximum performance through in-memory communication.
3. MCP + PostgreSQL server (reverse proxy)
Run both servers with TCP-based communication, supporting distributed deployments and TLS encryption.
stackql srv \
--mcp.server.type=reverse_proxy \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9004", "allow_unauthenticated": true}, "backend": {"dsn": "postgres://stackql:stackql@127.0.0.1:5446?default_query_exec_mode=simple_protocol"}}' \
--pgsrv.port 5446
With TLS encryption:
stackql srv \
--mcp.server.type=reverse_proxy \
--mcp.config '{"server": {"tls_cert_file": "/path/to/server_cert.pem", "tls_key_file": "/path/to/server_key.pem", "transport": "http", "address": "127.0.0.1:9004", "auth_token_env_var": "STACKQL_MCP_TOKEN"}, "backend": {"dsn": "postgres://stackql:stackql@127.0.0.1:5446?default_query_exec_mode=simple_protocol"}}' \
--pgsrv.port 5446
TLS encrypts the transport but does not authenticate the client, so this example also requires the bearer token held in STACKQL_MCP_TOKEN.
Use case: when you need to separate MCP and PostgreSQL workloads across different processes or hosts, or when you require TLS encryption for the MCP endpoint.
Configuration options
MCP server type
| Type | Description |
|---|---|
http | Direct HTTP server mode - MCP requests are handled in-process by the StackQL engine. |
reverse_proxy | Reverse-proxy mode - MCP requests are dispatched to a backing PostgreSQL server via the configured DSN. Used with stackql srv. |
stdio | Standard input/output transport - the server reads requests from stdin and writes responses to stdout. Used by editor-embedded MCP clients (Claude Desktop, Cursor, etc.). |
MCP log format
The --mcp.log.format flag selects the audit log encoding: jsonl (default) or otel (OpenTelemetry OTLP/JSON log records). It overrides server.audit.format in the configuration object. See Log format.
MCP protocol version
The --mcp.protocol.version flag sets the newest protocol revision the server advertises: auto (default, every supported revision), 2026-07-28 (sessionless only) or an older revision such as 2025-11-25 (that revision and earlier). It overrides server.protocol_version in the configuration object. See Pinning the revision.
MCP configuration object
The --mcp.config flag accepts a JSON object with the following structure.
Server configuration
| Field | Description | Required |
|---|---|---|
server.transport | Transport protocol - http or stdio. | Yes |
server.address | Address and port to bind the MCP server (e.g., 127.0.0.1:9912). HTTP transport only. | For http |
server.tls_cert_file | Path to TLS certificate file for HTTPS. | No |
server.tls_key_file | Path to TLS private key file for HTTPS. | No |
server.auth_token_env_var | Name of an environment variable holding a pre-shared bearer token. When set, every HTTP request must carry Authorization: Bearer <token>; the server refuses to start if the variable is unset or empty. See HTTP client authentication. | One of this, oauth or allow_unauthenticated, for http |
server.oauth | OAuth resource-server configuration: every HTTP request must carry a signed JWT from a trusted external authorization server. Cannot be combined with auth_token_env_var or allow_unauthenticated. See OAuth JWT authentication. | One of this, auth_token_env_var or allow_unauthenticated, for http |
server.allow_unauthenticated | Explicit opt-in to serve the HTTP transport with no client authentication. Default false. | One of this, auth_token_env_var or oauth, for http |
server.approval_key_env_var | Name of an environment variable holding the HMAC-SHA256 key that signs the approval request state returned with an approval prompt. The value must hold at least 32 bytes and is never logged or audited. When unset, each process uses a random key, which suits stdio and a single HTTP instance; set the same value on every instance of a sessionless HTTP deployment behind a load balancer. | No |
server.mode | Safety contract that gates mutation and lifecycle operations. One of read_only, safe (default), delete_safe, full_access. See Server modes. | No |
server.read_only | Legacy boolean alias for mode: read_only. When both fields are set, mode wins. | No |
server.max_concurrent_requests | Maximum number of backend calls in flight across all clients of the process; further calls queue. Default 100; 0 or a negative value removes the cap. See Request limits. | No |
server.request_timeout | Budget for one backend call, queue wait included, as a duration string such as "30s" or "2m". Default "30s"; "0s" or a negative value removes the deadline. See Request limits. | No |
server.render | Default rendering of tool result text: markdown (default) or json. A tool call's format argument overrides it. | No |
server.stateless | Serve Streamable HTTP without sessions (no Mcp-Session-Id), which is how protocol revision 2026-07-28 is served over HTTP. Default false. Ignored for stdio. See Protocol revision support. | No |
server.protocol_version | Newest protocol revision advertised: auto (default), 2026-07-28 or an older revision such as 2025-11-25. 2026-07-28 implies stateless for Streamable HTTP. See Pinning the revision. | No |
server.audit | Audit subsystem configuration, including audit.format (jsonl or otel). See Audit log. | No |
server.extensions | Opt-in MCP extensions: skills, tasks and files, each off by default. See MCP extensions. | No |
Backend configuration (reverse-proxy mode only)
| Field | Description | Required |
|---|---|---|
backend.dsn | PostgreSQL connection string for the backend StackQL server. | Yes (for reverse_proxy) |
The backend DSN should include the default_query_exec_mode=simple_protocol parameter for optimal compatibility.
Allowlists
| Field | Description |
|---|---|
enabled_tools | Array of tool names that the server is permitted to publish. When omitted or empty, every built-in tool is registered. Used to expose a narrow subset (e.g., a read-only inventory server). |
enabled_prompts | Array of prompt names. Same semantics as enabled_tools but for the prompt surface. |
enabled_resources | Array of resource names. Same semantics as enabled_tools but for the resource surface. When every resource is filtered out, the resources capability is not declared. |
Example - a server that publishes only server_info and list_providers:
{
"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true},
"enabled_tools": ["server_info", "list_providers"]
}
Other top-level fields
| Field | Description |
|---|---|
disable_instructions | true suppresses the server instructions otherwise returned in the initialize result (and in the stackql://docs/instructions resource). Default false. |
query_library | Where the query_library_search and query_library_get tools read the published query library. Keys: base_url (default https://stackql.io/docs/query-library, or the STACKQL_QUERY_LIBRARY_BASE_URL environment variable), fallback_url (a raw GitHub mirror by default), offline (true serves only the snapshot embedded in the binary; also STACKQL_QUERY_LIBRARY_OFFLINE) and ttl_seconds (manifest cache lifetime, default 300; also STACKQL_QUERY_LIBRARY_TTL). A configuration value wins over the environment variable. When every fetch fails, the tools serve the cached or embedded copy and flag the response stale. |
Protocol revision support
Protocol revision 2026-07-28, server.stateless and the otel audit log format are available in StackQL releases from v0.11.660. server.protocol_version and the --mcp.protocol.version flag are available in StackQL releases from v0.12.732.
The server speaks every revision of the Model Context Protocol supported by the Go MCP SDK and negotiates per client, so a fleet of mixed clients works against one server.
| Revision | Lifecycle | Approval prompt (safe / delete_safe) |
|---|---|---|
2026-07-28 (advertised) | No handshake: server/discover, then every request carries io.modelcontextprotocol/protocolVersion and io.modelcontextprotocol/clientCapabilities in _meta (plus the Mcp-Protocol-Version, Mcp-Method and Mcp-Name headers on HTTP). | input_required result, retried by the client with inputResponses (SEP-2322). |
2025-11-25, 2025-06-18 | initialize / notifications/initialized handshake. | Server-initiated elicitation/create request. |
2025-03-26, 2024-11-05 | As above. | As above. |
stdio serves every revision on one process: a 2026-07-28 client's first request is served without a handshake and an older client's initialize still works. Nothing needs configuring for Claude Desktop, the npm / PyPI launchers or the Docker image.
Streamable HTTP defaults to the stateful, session-per-client model (Mcp-Session-Id), which the SDK serves for revisions up to 2025-11-25. A 2026-07-28 request is answered with JSON-RPC error -32022 (unsupported protocol version; a plain HTTP 400 in releases up to v0.12.718) whose data.supported lists the handshake revisions, and server/discover advertises the same, so the client negotiates down and existing HTTP integrations keep their sessions and their approval prompts unchanged. Set server.stateless (or pin the revision to 2026-07-28, below) to serve 2026-07-28 natively over HTTP:
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true, "stateless": true}}'
A sessionless server issues no Mcp-Session-Id, answers GET and DELETE with 405 (there is no session to tear down), keeps tools/list, prompts/list and resources/list connection-invariant, and runs the approval round trip through input_required. It still accepts an older client's initialize and serves reads to it, but it cannot retain the elicitation capability that client declared at initialization (each request gets an ephemeral session), so older clients cannot approve gated writes on a sessionless server. Choose stateless for current-revision hosts and the default for a fleet that still includes older clients.
The server holds no cross-call state: mode, audit and provider credentials are process-level configuration, so nothing needs to move behind explicit handles.
Pinning the revision
By default the server advertises every supported revision and negotiates per client. The --mcp.protocol.version flag, or server.protocol_version in the configuration object (the flag wins), sets the newest revision advertised:
# sessionless only; stateless Streamable HTTP is implied
stackql mcp \
--mcp.server.type=http \
--mcp.protocol.version=2026-07-28 \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true}}'
# handshake lifecycle only
stackql mcp --mcp.server.type=stdio --mcp.protocol.version=2025-11-25
| Value | Advertised | Effect |
|---|---|---|
auto (default) or absent | Every supported revision. | Negotiation as above: the highest revision both sides speak. |
2026-07-28 | 2026-07-28 only. | Sessionless only, and stateless is implied for Streamable HTTP. An older client's initialize is answered with 2025-11-25, the cue for that client to disconnect rather than read the answer as the new lifecycle. |
2025-11-25 (or any older revision) | That revision and everything before it. | Handshake lifecycle only: a 2026-07-28 request gets JSON-RPC error -32022 with data.supported listing the advertised revisions, so the client can renegotiate. Older handshake clients keep their own revision. |
Any other value fails configuration validation at startup, and the error names the legal values.
Transport limits
Streamable HTTP request bodies are capped at 4 MiB (HTTP 413 beyond it), JSON nested deeper than 1000 levels is rejected before parsing, and a single stdio frame is capped at 8 MiB. None of these limits is configurable; all sit far above any SQL statement the server accepts.
The Streamable HTTP listener also applies fixed connection limits: a 10-second timeout for reading request headers, a 30-second timeout for reading a whole request, a 60-second keep-alive idle timeout and a 1 MiB maximum for request headers. There is no write timeout, because a Streamable HTTP response can stay open while it delivers events. These limits apply independently of the request limits below.
Response cache metadata
On revision 2026-07-28, list results (tools/list, prompts/list, resources/list and the skills list) carry private cache metadata with a 30-second time to live; resource contents and server/discover results are marked private and immediately stale. Query results are never cached.
Request limits
The limits are enforced in StackQL releases from v1.1.959.
server.max_concurrent_requests and server.request_timeout bound the backend work of the server. The defaults are 100 concurrent backend calls and a 30-second timeout, and an omitted setting keeps its default even when the server object sets other fields. An explicit 0 ("0s" for the timeout) or a negative value disables that limit.
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true, "max_concurrent_requests": 8, "request_timeout": "2m"}}'
- The limits apply to backend work (queries, discovery, registry and credential calls) and are shared by every client of the process.
server_infodoes no backend work and is never limited. max_concurrent_requestscaps the calls in flight; further calls queue.request_timeoutis the budget for one call, queue wait included, so set both: without a timeout a queued call waits until its client gives up.- A call that the mode refuses, or that is waiting for the user's approval, holds no slot and spends none of its budget.
- Both outcomes are tool errors that name the setting and are written to the audit log.
server busymeans the call never ran and is safe to retry. A mutation or lifecycle call that timed out may already have taken effect at the provider, so check its state before retrying. - Choose a
request_timeoutabove the slowest call you expect; a call that exceeds it is cancelled. Long native IaC runs can run as tasks, which have their own timeout.
Credential (re)sourcing (--env.file + reload_credentials)
--env.file and the reload_credentials tool are available in StackQL releases after v0.10.542.
A process environment block is fixed at spawn. This creates two problems for MCP servers:
- An MCP
stdioserver spawned by a desktop client (Claude Desktop, Cursor, etc.) without the credential environment variables can never see them - the client passes its own environment to the subprocess. - Rotated short-lived credentials never reach a long-running server session.
The --env.file flag bridges both gaps by nominating a credentials file that acts as a mutable credential store:
stackql mcp --mcp.server.type=stdio --env.file /path/to/stackql-credentials.env
Sourcing semantics
The file is sourced into the process environment at startup for every entrypoint (exec, shell, srv, registry, mcp):
- When the flag is empty or unset, nothing happens - credentials resolve lazily from the process environment at request time, exactly the historical behaviour.
- A missing file is created at startup, empty and in the format its suffix selects (mode
0600on Unix, parent directories included), so packaged installs can pass the flag unconditionally. An existing file is never modified. - A malformed or unreadable file is fatal at startup. In a dotenv file, a line that is not blank, not a comment and has no
=stops startup withexpected KEY=VALUE on line N(releases up tov1.0.888skipped it). - Only keys with non-empty values are set; existing process environment variables are overwritten (the file is the source of truth); nothing is ever unset.
- The flag is command line only - it is not sourced from
.stackqlrc.
The format is chosen by the file suffix. A file ending in .toml, .yaml, .yml or .json must hold one flat mapping of string keys to scalar values (a structured null becomes the text null); the structured formats are available in StackQL releases from v1.1.959. Any other suffix is read as dotenv, one KEY=VALUE per line, where # comments, blank lines, an optional export prefix, optional single or double quotes around the value, and CRLF line endings are all tolerated:
# stackql-credentials.env
export OKTA_SECRET_KEY="00abc...xyz"
STACKQL_GITHUB_USERNAME=myuser
STACKQL_GITHUB_PASSWORD='ghp_mytoken'
The same credentials as YAML, in a file named stackql-credentials.yaml:
OKTA_SECRET_KEY: "00abc...xyz"
STACKQL_GITHUB_USERNAME: myuser
STACKQL_GITHUB_PASSWORD: ghp_mytoken
reload_credentials
The reload_credentials tool re-sources the --env.file file into the process environment mid-session, then reports per-provider credential resolution status. Secret values are never returned, logged, or audited - names and statuses only. Without --env.file configured the tool degrades to a pure status probe.
When a query fails on credential resolution, the MCP error carries a hint directing the agent to call reload_credentials and retry, so agentic clients self-heal: write the credential to the file, ask the agent to reload, and the failed query succeeds on retry - no server restart required.
reload_credentials is not supported in reverse_proxy backend mode - queries execute in the remote stackql server process, so the tool returns an error directing the user to reload on the backing server.
Windows and Claude Desktop
setx writes the registry, not running processes, and Claude Desktop passes its own (stale) environment to MCP subprocesses - so credential changes normally require a full Claude Desktop restart. With --env.file the credentials file can be created or rotated at any time and reload_credentials picks it up without any restart. See Using StackQL with Claude Desktop for a worked configuration.
HTTP client authentication
server.auth_token_env_var and server.allow_unauthenticated are available in StackQL releases from v0.12.742.
The HTTP transport requires client authentication. server.auth_token_env_var names an environment variable holding a pre-shared bearer token; every request must carry Authorization: Bearer <token> or it is answered with 401. The token is read from the environment, so it never appears in --mcp.config or the process arguments.
export STACKQL_MCP_TOKEN="$(openssl rand -hex 32)"
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "auth_token_env_var": "STACKQL_MCP_TOKEN"}}'
Serving without client authentication is an explicit opt-in: set "allow_unauthenticated": true in server. Without auth_token_env_var, oauth or allow_unauthenticated the server exits at startup with a message naming auth_token_env_var and allow_unauthenticated; it also exits if the token variable is unset or empty. As of the v0.12.742 release you must add one of them to server when using the http transport.
TLS (tls_cert_file / tls_key_file) encrypts the transport but does not authenticate the client; combine it with a token for any listener beyond loopback. Cross-origin browser requests (a mismatched Origin, or a cross-site Sec-Fetch-Site) are refused with 403 regardless of authentication. The bundled stackql_mcp_client sends no Authorization header, so a server it drives must opt into unauthenticated service.
From v1.0, starting the server with --access.config replaces the shared token gate with per-caller authentication: each HTTPS request is verified with the configured JWT, static bearer or mutual TLS scheme and authorised against policy rules. Server TLS is mandatory in that case, local_os authentication is refused over HTTP, and a request without credentials never falls back to the server's environment token. Access management is not available with the reverse_proxy server type.
OAuth JWT authentication
server.oauth is available in StackQL releases from v1.1.959.
server.oauth makes the HTTP transport an OAuth resource server: every MCP request must carry a signed JWT, issued by a trusted external authorization server, in an Authorization: Bearer header. StackQL verifies tokens only; it does not acquire tokens or act as an authorization server. Every key except jwks_ca_file, cache_ttl and clock_skew is required:
server:
transport: http
address: 127.0.0.1:9912
tls_cert_file: /etc/stackql/server_cert.pem
tls_key_file: /etc/stackql/server_key.pem
oauth:
issuer: https://auth.example.com/
audience: https://mcp.example.com/
resource: https://mcp.example.com/
jwks_url: https://auth.example.com/.well-known/jwks.json
# jwks_ca_file: /etc/stackql/oauth-issuer-ca.pem
metadata_url: https://mcp.example.com/.well-known/oauth-protected-resource
scopes: [stackql:query]
algorithms: [RS256]
cache_ttl: 5m
clock_skew: 30s
| Key | Description |
|---|---|
issuer | Expected iss claim. |
audience | Expected aud claim. |
resource | The protected resource URI published in the resource metadata. |
jwks_url | Where the authorization server publishes its signing keys. Redirects are not followed. |
jwks_ca_file | Optional PEM CA bundle for a private authorization server; the system trust roots are used when omitted. |
metadata_url | URL of the protected-resource metadata document. Its path, which must not be the root, is served without credentials. |
scopes | Scopes every token must carry. |
algorithms | Accepted signing algorithms, for example RS256. RSA keys must be 2048 to 4096 bits. |
cache_ttl | How long fetched signing keys are cached (bounded). |
clock_skew | Tolerance applied to token time claims (bounded). |
- Tokens must carry the configured issuer and audience, an expiry and every configured scope. The issuer, JWKS, resource and metadata URLs must all be HTTPS.
- An unknown key ID refreshes the key cache at most once per second, so publish a replacement key before retiring the old one.
- An unavailable or invalid JWKS response fails closed as a server error; an invalid token receives an authentication rejection.
oauthis supported only withtransport: httpand cannot be combined withauth_token_env_var,allow_unauthenticatedor client-certificate authentication. Serve the endpoint over HTTPS, including when TLS terminates at a trusted reverse proxy.- Opaque-token introspection, immediate revocation and DPoP or mTLS-bound access tokens are not supported. Without
oauth, the pre-shared bearer token andstdiobehave as before.
Server modes
server.mode chooses one of four safety contracts. All four allow metadata reads and SELECT statements classified as read only; they differ in how they handle mutations, lifecycle operations and statements whose effect cannot be classified.
| Mode | SELECT / metadata | INSERT / UPDATE / REPLACE | DELETE | EXEC (lifecycle) |
|---|---|---|---|---|
read_only | allow | refuse | refuse | refuse |
safe (default) | allow | needs approval | needs approval | needs approval |
delete_safe | allow | allow | needs approval | needs approval |
full_access | allow | allow | allow | allow |
Refuse returns an error immediately to the client.
Needs approval uses the MCP elicitation flow, shaped by the negotiated protocol revision:
- If the client advertised the elicitation capability (at initialization, or in the per-request
_metaclient capabilities on2026-07-28), the server asks the user to approve the action with a short message (tool name, query class, SQL). On2026-07-28the prompt is returned as aninput_requiredresult carrying anelicitation/createinput request under the idstackql_approval, and the client retries the call with the answer ininputResponses; on earlier revisions the server sends theelicitation/createrequest itself mid-call. The user accepts, declines, or cancels. - If the client did not advertise elicitation, the tool is refused with a message that explains the gap and points the operator at
full_accessmode.
Approval is answered by the client, so it guards against an agent acting without its user, not against an untrusted caller. Pair the HTTP transport with client authentication where callers are not trusted.
The mode is global per server. There is no per-tool override.
From v1.0, run_select_query refuses INSERT, UPDATE, REPLACE, DELETE and EXEC in every mode, including full_access; the error names run_mutation_query or run_lifecycle_operation. Every tool also carries a title and the four MCP behavioural hints as explicit booleans (readOnlyHint, destructiveHint, idempotentHint, openWorldHint), derived from the same classification the policy gate enforces. openWorldHint is true for list_registry, pull_provider, run_select_query, run_mutation_query and run_lifecycle_operation, which reach registry or provider endpoints, and false for tools that read local state only. The hints are advisory for client UX; enforcement stays with the policy gate.
From release v0.12.742, a payload holding several statements is gated by its most privileged statement in every mode, so SELECT 1; DELETE ... is treated as a DELETE and the audit record carries query_class mutation_delete. validate_select_query accepts exactly one statement.
Statement classification
The gate classifies SQL from the parsed statement, following subqueries, nested EXEC and the common table expressions defined in the same statement. From v1.1.959, a statement whose effect cannot be established is classified unknown: a SELECT that names a relation without its provider (ec2.instances after USE aws, or a bare name that is not a CTE of the same statement), a WITH RECURSIVE query, an unparseable SELECT or WITH, and any other statement head the gate does not recognise, including SET and UNSET. read_only refuses unknown statements, safe and delete_safe ask for approval, and full_access allows them. Use fully qualified provider.service.resource names for ordinary reads, and expect a batch that starts with SET (for example a provider session configured in the same call) to need approval outside full_access.
The native IaC statements are gated by their SQL verb: INSERT INTO stackql_preview.iac.run, INSERT INTO stackql_preview.iac.plan and UPDATE stackql_preview.iac.recover are mutation_create, DELETE FROM stackql_preview.iac.run is mutation_delete, and a SELECT on stackql_preview.iac.plan or stackql_preview.iac.ledger is a read.
Classification is not a complete effect analysis. A fully qualified name can still resolve to a view, a provider alias or session variable substitution whose effect the gate cannot see, so do not rely on read_only alone as a security boundary for cloud effects: restrict the published tools and the provider credentials as well.
Default-mode behaviour change
Prior releases enforced safety only through a single read_only: true/false flag whose default was "no enforcement". The current default (mode: safe) makes mutations require user approval out of the box. Operators running an elicitation-capable client (Claude Desktop, Cursor, Continue, etc.) will see one approval prompt per mutation. Operators running automation, or the bundled stackql_mcp_client (which does not advertise elicitation), must explicitly opt into a less restrictive mode: mode: delete_safe to run INSERT, UPDATE and REPLACE, or mode: full_access to also run DELETE and lifecycle operations.
The legacy read_only: true JSON / YAML key is still accepted for back-compat and is treated as equivalent to mode: read_only.
Examples
# Read-only: SELECTs proceed; mutations and lifecycle refused immediately.
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true, "mode": "read_only"}}'
# Delete-safe: INSERT/UPDATE/REPLACE proceed; DELETE and EXEC need approval.
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true, "mode": "delete_safe"}}'
# Full access: everything proceeds without prompting. Use only with trusted
# clients and operators.
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true, "mode": "full_access"}}'
Audit log
Every tool call writes one record to the configured audit sink, as JSONL by default or as OpenTelemetry log records (see Log format). Audit is on by default. The audit answers "what did the agent do," not "what did the agent see" - result rows from SELECT statements are intentionally not recorded, in either format.
What gets recorded
| Field | Description |
|---|---|
timestamp | Start-of-call wall clock (RFC3339). |
tool | Tool name (e.g., run_select_query). |
mode | Server mode in effect at call time. |
decision | allow / refuse_immediate / needs_approval_accepted / needs_approval_declined / needs_approval_cancelled / needs_approval_unavailable. |
query_class | select / mutation_create / mutation_delete / lifecycle / unknown. For a payload holding several statements, the class of the most privileged one. |
sql | SQL string for query tools (run_select_query, run_mutation_query, run_lifecycle_operation, validate_select_query). |
args | Hierarchy fields for metadata tools (list_*, describe_method); SQL + row_limit for query tools. For attach_policy_document, only the document's name, media type, size and digest, never its content. |
duration_ms | Wall-clock duration of the gate + handler. |
error | Error message if the tool errored or was refused. |
task_id, task_status | For a call that ran as a task: the task ID, with working on the decision record written when the task starts and the terminal status on the record written when it finishes. |
Result rows from SELECT statements are deliberately excluded - they can be very large and may carry sensitive data.
File sink
The only sink shipped today is file. One JSON object per line, fsynced after each record, lumberjack-style rotation by size / age / backup count.
stackql mcp \
--mcp.server.type=http \
--mcp.config '{
"server": {
"transport": "http",
"address": "127.0.0.1:9912",
"allow_unauthenticated": true,
"audit": {
"file": {
"path": "/var/log/stackql-mcp.log",
"max_size_mb": 100,
"max_backups": 5,
"max_age_days": 30
}
}
}
}'
Two ways to specify the location:
audit.file.path- a complete file path (absolute, or relative to cwd).audit.file.dir- a directory; the sink picks the basenamestackql_mcp_server_<RFC3339-utc-second>.loginside it.
When neither is set in mcp.config, the MCP server defaults dir to cwd so existing operators see the same behaviour as before. The underlying generic sink package itself refuses to silently pick a directory - the "where do logs land" decision is always made by the caller.
The resolved absolute path is logged to stderr at startup as sink file: /path/to/file.log.
Log format
The audit stream has two encodings, written to the same file sink:
stackql mcp --mcp.server.type=stdio --mcp.log.format=jsonl # default, unchanged
stackql mcp --mcp.server.type=stdio --mcp.log.format=otel # OTLP/JSON log records
The flag overrides server.audit.format in mcp.config ("audit": {"format": "otel"}). jsonl is byte-compatible with the records described above. otel writes one OTLP/JSON LogsData object per line, the shape the OpenTelemetry Collector's otlp_json_file receiver ingests as-is (verified against otelcol-contrib 0.160.0), so the stream reaches any OTLP pipeline with no transform processor:
receivers:
otlp_json_file:
include: [/var/log/stackql-mcp.log]
exporters:
debug: {}
service:
pipelines:
logs:
receivers: [otlp_json_file]
exporters: [debug]
Each tool call produces one log record; a call that went through the approval gate produces a second record for the elicitation decision. Records of one call share gen_ai.tool.call.id and a trace id. A W3C traceparent supplied by the caller in params._meta is honoured; otherwise one trace id is generated per MCP session so an agent session's records correlate.
The emitted attribute set is a versioned interface: the instrumentation scope is github.com/stackql/stackql/pkg/mcp_server/audit at version 1.0.0, and schemaUrl pins the stable conventions to https://opentelemetry.io/schemas/1.44.0. The gen_ai.* and mcp.* attributes follow the GenAI and MCP semantic conventions, which are Development status; the scope version is bumped when the set changes.
| Attribute | Record | Value |
|---|---|---|
service.name, service.version | resource | stackql, the StackQL version |
gen_ai.operation.name | tool call | execute_tool |
mcp.method.name | both | tools/call on the tool call record, elicitation/create on the decision record |
gen_ai.tool.name | both | Tool name |
gen_ai.tool.call.id | both | Generated per call, shared by both records |
mcp.protocol.version | both | Negotiated revision |
mcp.session.id | both | Session id (absent for sessionless HTTP requests) |
stackql.mode | both | Server mode |
stackql.decision | both | The decision value from the table above |
stackql.query | tool call | Verbatim SQL, for query tools |
stackql.query_class | tool call | The query_class value |
stackql.provider | tool call | Provider, for metadata tools |
stackql.query.source | tool call | Query library entry id, when supplied |
stackql.duration_ms | tool call | Wall-clock duration |
stackql.rows_returned | tool call | Row count, for row-returning tools |
error.type, error.message | tool call | On failure: the refusing decision, or tool_error past the gate |
Body is execute_tool <tool> / elicitation <tool>; severity is INFO, or ERROR when the call failed or was refused. The redaction contract is identical in both formats: result values are never serialised, only the statement that produced them.
Failure modes
When the sink returns an error, the response behaviour depends on audit.failure_mode.
| failure_mode | Effect |
|---|---|
strict (default) | The tool call returns the audit error to the client even if the underlying tool succeeded. Intentional: better an ambiguous client response than an undetected DELETE. |
strict_mutations | SELECT / metadata reads proceed with a stderr note; mutations and lifecycle ops surface the audit error. |
best_effort | Always log to stderr and proceed. |
Sequencing
The audit write happens after the tool executes (or is gated out) but before the response returns to the client. In strict mode, an audit-write failure on a successful DELETE means the row is gone but the client receives an error - by design, so no mutation slips through unaudited.
Disabling audit
To turn audit off entirely, as in releases before v0.10.474, which had no audit:
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true, "audit": {"disabled": true}}}'
Available MCP tools
When running as an MCP server, StackQL exposes the following tools, subject to the configured enabled_tools allowlist. Each returns both a rendered text view (for the LLM) and a typed structured payload (for programmatic clients). The default text rendering is a markdown table for uniform multi-row results or a markdown KV block for sparse / single-record results. Tools with arguments accept an optional format (markdown or json) override; otherwise the server's render setting is used. The inputs below list task-specific arguments; ? marks optional inputs.
Click any tool name for a full reference page, including inputs, gating behaviour, and an example prompt.
| Tool | Renderer | Description | Inputs |
|---|---|---|---|
server_info | KV | Server identity and runtime: stackql version, backing SQL engine, provider registry location, mode, read-only flag. Call on demand, for example to diagnose a refused or gated operation or to check version-specific behavior. | none |
list_providers | Table | Providers already pulled into the local cache - top of the hierarchy. | none |
list_services | Table | Services under a provider. | provider |
list_resources | Table | Resources under a provider.service. | provider, service |
list_methods | Table | Access methods (HTTP operations) for a resource, with the SQL verb each maps to and its required parameters. Call before writing any query - this is where required WHERE parameters are inferred. | provider, service, resource |
describe_method | KV | Typed I/O contract for one method: required and optional inputs, and the output fields a SELECT can reference. Nested schemas expand one level by default; depth and path drill further. | provider, service, resource, method, depth?, path?, descriptions?, param_type?, include_global? |
query_library_search | Table | Find curated query templates by natural-language intent. Read-only; mutation entries require opt-in and are excluded in read_only mode. | intent, provider?, service?, tags?, include_mutations?, limit? |
query_library_get | KV | Retrieve a template and its parameter declarations. With non-empty params, validate values and return rendered SQL plus next_tool, without executing. | id, params? |
validate_select_query | KV | Parse and plan a single SELECT without executing. Returns {valid, errors}. SELECT only; exactly one statement. | sql |
run_select_query | Table | Execute a SELECT. Returns {rows}, plus {messages} when the engine reported per-statement messages such as a provider 404. Reads only. | sql, row_limit? |
run_mutation_query | KV | Execute INSERT/UPDATE/REPLACE/DELETE against the provider. Real side effects. Returns {messages, timestamp}, plus rows when the statement returns results (for example with RETURNING). Gated by the server mode. | sql |
run_lifecycle_operation | KV | Execute a stackql EXEC lifecycle operation. Returns {messages, timestamp}, plus rows when the statement returns results. Gated by the server mode. | sql |
list_registry | Table | Providers (and their versions) available in the configured registry. Distinct from list_providers, which lists only providers already pulled. | provider? |
pull_provider | KV | Install a single provider from the registry into the local cache. Local cache state only - no cloud control or data plane effect. | provider, version? |
reload_credentials | Table | Re-source credentials from the --env.file file into the process environment and report per-provider resolution status (ok, unresolved, not_checked). Never returns secret values. Allowed in every mode. | provider? |
attach_policy_document | Text + resource link | Published only with the files extension enabled. Accept one policy or compliance document inline and expose it as the resource stackql://policies/<id>. Server memory only. Allowed in every mode. | document, label? |
Consult query_library_search before authoring SQL from scratch, then use query_library_get to inspect and render a matching template. Query tools also accept an optional source containing the library entry ID for attribution only; execution remains subject to the normal server mode and approval policy.
describe_resource was retired in StackQL v0.12.732; MCP clients, prompts or agent instructions that called it should call list_methods followed by describe_method instead. A resource has no single field list, because each access method returns its own shape, so column names come from describe_method for the method a query routes to. The SQL DESCRIBE statement is unchanged.
Available MCP prompts
Seven prompts are published, subject to the configured enabled_prompts allowlist. Each is a guided workflow that an agent runs with the StackQL MCP tools, and none of them changes cloud resources.
| Prompt | Description |
|---|---|
getting_started | Interactive guided tour of StackQL and the StackQL MCP server for new users: concepts, provider discovery, first queries and where to go next. |
cloud_audit | Cross-cloud (AWS, Google Cloud, Azure and Entra ID) security and FinOps audit; returns a findings report. |
cost_cleanup | FinOps cleanup pass that finds idle and orphaned resources, estimates monthly savings and returns a prioritized list of resources that are safe to delete. |
drift_report | Drift report comparing declared infrastructure as code (Terraform state or plan, or a pasted inventory) against live cloud resources; returns a drift table. |
iam_access_review | Identity and access review across AWS IAM, Entra ID, Okta and GitHub; returns an auditor-ready access review (SOC 2 or ISO style). |
public_exposure_scan | Scan for internet-reachable resources (public storage, open security groups, public IP addresses, public database endpoints, exposed Kubernetes services); returns a prioritized exposure table. |
create_deploy_stack | Guides the user through generating a stackql-deploy stack (manifest and .iql resource files) with queries tested live. Mutations are rendered for stackql-deploy, never executed. |
Available MCP resources
Four reference documents are served through resources/list and resources/read, subject to the enabled_resources allowlist.
| Resource | URI | Description |
|---|---|---|
stackql_scope_discovery | stackql://docs/scope_discovery | How to discover the scope of an audit sweep per cloud (regions, projects, subscriptions), with the query library entries that hold the tested queries. |
stackql_server_instructions | stackql://docs/instructions | The server instructions, identical to the initialize payload, for clients that do not pass those instructions to the model. |
stackql_audit_rubric | stackql://docs/audit_rubric | Severity, drift and deletion-confidence definitions shared by the audit prompts, so their reports stay comparable. |
stackql_deploy_stack_authoring | stackql://docs/deploy_stack_authoring | How to author a stackql-deploy stack, used by the create_deploy_stack prompt. |
With the files extension enabled, documents attached with attach_policy_document are also readable as stackql://policies/<id>, and with the skills extension enabled, skill files are readable through the skill://{+path} resource template.
MCP extensions
The MCP extensions are available in StackQL releases from v1.1.975.
The server implements three MCP extensions. Each is off by default and enabled in the server.extensions block of --mcp.config. With all three off, the advertised capabilities, the tool, prompt and resource lists and every result are the same as without the block, so clients without extension support are unaffected.
{"server": {"extensions": {
"skills": {"enabled": false, "enabled_skills": []},
"tasks": {"enabled": false, "timeout": "30m", "retention": "1h", "poll_interval": "5s"},
"files": {"enabled": false, "max_inline_bytes": 1048576}
}}}
| Key | Default | Description |
|---|---|---|
skills.enabled | false | Serve the embedded skills over the skills extension. |
skills.enabled_skills | all | Allowlist of skill names, like enabled_prompts. |
tasks.enabled | false | Run long native IaC calls of run_mutation_query as tasks for clients that declare the extension. |
tasks.timeout | 30m | Wall clock for one task's backend work; replaces server.request_timeout for tasks. |
tasks.retention | 1h | How long a finished task stays readable. |
tasks.poll_interval | 5s | The advertised poll interval. |
files.enabled | false | Advertise inline file transfer and publish the attach_policy_document tool. |
files.max_inline_bytes | 1048576 | Largest accepted file, in bytes; at most 2 MiB, which keeps an encoded file inside the 4 MiB HTTP request limit. |
An enabled extension is advertised under capabilities.extensions in the server/discover and initialize results. A client declares the extensions it supports in its client capabilities (per request on 2026-07-28, in initialize on older revisions). The server implements the initial revision of each extension, so a client declaration that carries a revision field is treated as not declared. stdio serves every protocol revision; on Streamable HTTP, serve 2026-07-28 clients with "stateless": true, since a stateful server negotiates them down to 2025-11-25, where only a client that declares the extension in initialize uses it.
Skills
The skills extension (io.modelcontextprotocol/skills) serves two skills embedded in the binary: stackql-deploy, for authoring stackql-deploy stacks with live-tested queries, and stackql-iac, for the native IaC SQL statements.
stackql mcp --mcp.server.type=stdio \
--mcp.config '{"server": {"transport": "stdio", "extensions": {"skills": {"enabled": true}}}}'
skills/listreturns every enabled skill as one complete entry: its URI (skill://<name>/SKILL.md), its YAML front matter and a manifest of its files, each with asha256:digest and size of the bytes served.skills/gettakes{"uri": ...}and returns that skill's entry; an unknown URI is error-32602.- Skill files are read with
resources/readthrough the resource templateskill://{+path}, soresources/listis unchanged.
Claude Code loads skills from MCP servers from version 2.1.331, on protocol revision 2026-07-28.
Tasks
A long IaC converge would otherwise be cut off by server.request_timeout. With the tasks extension (io.modelcontextprotocol/tasks) enabled, a tools/call becomes a task only when the request declares the extension, the tool is run_mutation_query, and the SQL is a single INSERT or DELETE on stackql_preview.iac.run or an INSERT on stackql_preview.iac.plan. Every other call stays synchronous.
stackql mcp --mcp.server.type=stdio --preview '{"unstable":true}' \
--mcp.config '{"server": {"transport": "stdio", "mode": "safe", "extensions": {"tasks": {"enabled": true, "timeout": "45m"}}}}'
- The mode gate, including the approval round trip, completes first; only a call cleared to run becomes a task.
- The call returns a task (
resultType: "task",taskId,status: "working", a poll interval and a time to live of the timeout plus the retention period). The work runs in the background through the same concurrency slots as synchronous calls, withtasks.timeoutin place ofserver.request_timeout. tasks/getreturns the task; acompletedtask carries the same result a synchronous call would have returned, including a tool error from the provider or the SQL. A task isfailedonly for a protocol error, an internal fault or an audit-write failure under a strict failure mode.tasks/cancelis acknowledged and recorded but does not interrupt the run, because stopping a converge midway can leave a partial deployment.tasks/updateacknowledges a known task.tasks/list,tasks/resultand task notifications are not implemented.- A task belongs to the caller that created it (the OAuth subject, the bearer-token client or the
stdioprocess); another caller's task, or an unknown or expired one, is error-32602. - Tasks are held in memory: they do not survive a restart and are not shared between HTTP instances, so a multi-instance HTTP deployment does not support them.
Claude Code runs MCP tasks from CLI version 2.1.304, in the main conversation.
File uploads
The files extension (io.modelcontextprotocol/files) is implemented for inline transfer only: it is advertised with maxInlineBytes and without upload targets, so a client sends a file base64-encoded inside the tool call. Enabling it publishes one more tool, attach_policy_document, which stores a policy or compliance document (an OPA/Rego policy, a control set or another GRC document as UTF-8 text) in server memory and exposes it as stackql://policies/<id>.
stackql mcp --mcp.server.type=stdio \
--mcp.config '{"server": {"transport": "stdio", "extensions": {"files": {"enabled": true}}}}'
Claude transfers files only for connectors listed in the Connector Directory with approved storage hosts, so a locally run StackQL server does not receive files from Claude yet.
Flags
| Flag | Description |
|---|---|
--mcp.server.type | MCP server type: http, stdio, or reverse_proxy (the latter is used with stackql srv). |
--mcp.config | JSON configuration object for the MCP server. YAML is also accepted. |
--mcp.log.format | Audit log encoding: jsonl (default) or otel (OpenTelemetry OTLP/JSON log records). Overrides server.audit.format. See Log format. |
--mcp.protocol.version | Newest protocol revision advertised: auto (default), 2026-07-28 or an older revision such as 2025-11-25. See Pinning the revision. |
--env.file | Credentials file (dotenv, or TOML, YAML or JSON by suffix) sourced at startup and re-sourced on demand by the reload_credentials tool. See Credential (re)sourcing. |
--pgsrv.port | TCP port for the PostgreSQL wire-protocol server (used with stackql srv). |
-h, --help | Print help information. |
-v, --verbose | Run in verbose mode with additional output. |
see Global Flags for additional options
You need to set environment variables required for provider authentication before starting the MCP server, or nominate a credentials file with --env.file. See Using a Provider for more information.
Examples
Basic standalone MCP server
Launch a standalone MCP server with provider authentication and a bearer token for its clients:
export GOOGLE_CREDENTIALS=$(cat /path/to/google-credentials.json)
export STACKQL_MCP_TOKEN="$(openssl rand -hex 32)"
stackql mcp \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "auth_token_env_var": "STACKQL_MCP_TOKEN"}}' \
--registry='{"url": "https://registry.stackql.app/providers"}' \
--auth='{"google": {"type": "service_account", "credentialsfilepath": "/path/to/google-credentials.json"}}'
MCP server with PostgreSQL server (in-memory)
Run both MCP and PostgreSQL servers for dual-protocol access:
export GOOGLE_CREDENTIALS=$(cat /path/to/google-credentials.json)
stackql srv \
--mcp.server.type=http \
--mcp.config '{"server": {"transport": "http", "address": "127.0.0.1:9912", "allow_unauthenticated": true}}' \
--pgsrv.port 5665 \
--registry='{"url": "https://registry.stackql.app/providers"}' \
--auth='{"google": {"type": "service_account", "credentialsfilepath": "/path/to/google-credentials.json"}}'
Read-only inventory server with audit to a known path
Useful for an inventory-scanning agent that should never mutate:
stackql mcp \
--mcp.server.type=http \
--mcp.config '{
"server": {
"transport": "http",
"address": "127.0.0.1:9912",
"allow_unauthenticated": true,
"mode": "read_only",
"audit": {"file": {"path": "/var/log/stackql-mcp-audit.log"}}
}
}' \
--registry='{"url": "https://registry.stackql.app/providers"}' \
--auth='{"google": {"type": "service_account", "credentialsfilepath": "/path/to/google-credentials.json"}}'
Full-access automation server
For trusted automation pipelines that need mutations and can't respond to elicitation prompts. The pipeline presents the bearer token held in STACKQL_MCP_TOKEN:
stackql mcp \
--mcp.server.type=http \
--mcp.config '{
"server": {
"transport": "http",
"address": "127.0.0.1:9912",
"auth_token_env_var": "STACKQL_MCP_TOKEN",
"mode": "full_access"
}
}' \
--registry='{"url": "https://registry.stackql.app/providers"}' \
--auth='{"google": {"type": "service_account", "credentialsfilepath": "/path/to/google-credentials.json"}}'
Secure MCP server with TLS
Launch an MCP server with TLS encryption in reverse-proxy mode:
First, generate TLS certificates (self-signed for development):
openssl req -x509 -newkey rsa:4096 -keyout server_key.pem -out server_cert.pem -days 365 -nodes
Then start the server:
export STACKQL_MCP_TOKEN="$(openssl rand -hex 32)"
stackql srv \
--mcp.server.type=reverse_proxy \
--mcp.config '{
"server": {
"tls_cert_file": "server_cert.pem",
"tls_key_file": "server_key.pem",
"transport": "http",
"address": "127.0.0.1:9004",
"auth_token_env_var": "STACKQL_MCP_TOKEN"
},
"backend": {
"dsn": "postgres://stackql:stackql@127.0.0.1:5446?default_query_exec_mode=simple_protocol"
}
}' \
--pgsrv.port 5446 \
--registry='{"url": "https://registry.stackql.app/providers"}' \
--auth='{"google": {"type": "service_account", "credentialsfilepath": "/path/to/google-credentials.json"}}'
Testing your MCP server
The repository ships a development MCP client (stackql_mcp_client) for scripting and regression tests. Build it with:
python cicd/python/build.py --build-mcp-client
This produces ./build/stackql_mcp_client.
Note that stackql_mcp_client sends no Authorization header, so the server it targets must set "allow_unauthenticated": true (as the examples above do); a token-protected server answers it with 401. It also does not advertise the MCP elicitation capability - it's for non-interactive scripting. Against a safe server it will receive the "client does not support elicitation" refusal on mutation and lifecycle calls; against a delete_safe server, on DELETE and EXEC calls. For interactive testing with elicitation prompts, use an editor-embedded MCP client (Claude Desktop, Cursor, Continue).
# List all available tools
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912
# Server identity, mode and registry
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action server_info
# Re-source the --env.file credentials file and report per-provider
# credential status - a good first diagnostic when queries fail on auth
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action reload_credentials
# List providers already pulled into the local cache
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action list_providers
# List providers (and versions) available in the registry
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action list_registry
# Install a provider from the registry into the local cache
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action pull_provider \
--exec.args '{"provider": "kafka"}'
# List services for a provider
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action list_services \
--exec.args '{"provider": "google"}'
# List access methods for a resource (this is how an agent finds required
# WHERE parameters before writing a query)
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action list_methods \
--exec.args '{"provider": "google", "service": "compute", "resource": "networks"}'
# Validate a SELECT without executing
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action validate_select_query \
--exec.args '{"sql": "select name from google.compute.networks where project = '"'"'my-project'"'"';"}'
# Execute a SELECT
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action run_select_query \
--exec.args '{"sql": "select name from google.compute.networks where project = '"'"'my-project'"'"';"}'
# Mutation (a DELETE) - succeeds only against a full_access server:
# stackql_mcp_client does not support elicitation, so safe and delete_safe
# servers refuse it.
./build/stackql_mcp_client exec \
--client-type=http \
--url=http://127.0.0.1:9912 \
--exec.action run_mutation_query \
--exec.args '{"sql": "delete from google.compute.firewalls where project = '"'"'my-project'"'"' and firewall = '"'"'old-rule'"'"';"}'
Example responses
server_info (against a default-mode server, StackQL v1.0.888 on Windows over stdio):
{
"version": "1.0.888",
"commit": "f7b4116",
"build_date": "2026-11-05T00:26:03Z",
"platform": "Windows",
"transport": "stdio",
"sql_backend": "sqlite3",
"provider_registry": "https://registry.stackql.app/providers",
"mode": "safe",
"is_read_only": false
}
run_select_query:
{
"rows": [
{"name": "default"},
{"name": "pathfinders-test-01"},
{"name": "returning-test-03"}
]
}
run_mutation_query (against a full_access server):
{
"messages": ["The operation was despatched successfully"],
"timestamp": "2026-05-16T10:47:33+10:00 AEST"
}
Sample audit log line for the same mutation:
{"timestamp":"2026-05-16T00:47:33Z","tool":"run_mutation_query","mode":"full_access","decision":"allow","query_class":"mutation_delete","sql":"delete from google.compute.firewalls where project = 'my-project' and firewall = 'old-rule';","args":{"sql":"delete from google.compute.firewalls where project = 'my-project' and firewall = 'old-rule';","row_limit":0},"duration_ms":42}
Integration with AI assistants
To integrate StackQL's MCP server with an AI assistant, register stackql as an MCP server in the assistant's configuration. Most editor-embedded MCP clients run the server over stdio; for those, use --mcp.server.type=stdio and the assistant launches the process directly. Standalone agents that speak HTTP can connect to a long-running stackql mcp --mcp.server.type=http process.
For Claude Desktop - including the Anthropic Connector Directory listing (the recommended installation method), the downloadable MCP Bundle (.mcpb), and manual configuration - see Using StackQL with Claude Desktop.
Configuration file locations vary by operating system and AI assistant. Consult your AI assistant's documentation for the correct path and format.
Architecture considerations
When choosing a deployment mode, consider:
- Standalone (
stackql mcp): simplest setup, ideal for development and for editor-embedded clients overstdio. - In-memory dual-server (
stackql srvwithmcp.server.type=http): single process serves both MCP and PostgreSQL wire protocols. Best performance, suitable for most production deployments. - Reverse proxy (
stackql srvwithmcp.server.type=reverse_proxy):- enables workload separation across processes or hosts
- supports TLS encryption for secure MCP endpoints
- allows independent scaling of MCP and PostgreSQL interfaces
- provides flexibility for enterprise CA integration (note: enterprise CA support is experimental)
And separately, on safety:
- Start with the default
mode: safe. Elicitation-capable clients (Claude Desktop, Cursor, Continue) will prompt the user before any mutation. - Pin
mode: read_onlyfor inventory or analytics agents that should never write. - Pin
mode: delete_safewhen you want create/update freedom but want a human in the loop for destructive operations. - Reserve
mode: full_accessfor trusted automation pipelines, and only in conjunction with an audit log that someone reviews. - Set
server.auth_token_env_varorserver.oauthon any HTTP listener that other processes or hosts can reach;allow_unauthenticatedis for local development. TLS alone does not authenticate clients. - Set
server.request_timeoutabove the slowest call you expect, and enable tasks for long native IaC runs.
When using TLS with enterprise Certificate Authorities (CAs), additional configuration may be required. This functionality is experimental and may require adjustments based on your specific CA implementation.
Further reading
- The package-developer reference is the
pkg/mcp_serverREADME in the stackql repo. - The contributor-facing technical doc lives at
docs/mcp.mdin the stackql repo and includes worked example responses for every tool.