Security and access

MCP access

Give AI tools read-only access to StreamQL state and to a read-only SQL tool, with limits per token.

Overview#

StreamQL serves the Model Context Protocol on the admin port at /mcp over Streamable HTTP, never on the PostgreSQL data path. Access is by bearer token, shown once and stored as a SHA-256 digest. Every call is audited.

Enable it#

KeyDefaultMeaning
mcp.enabledfalseServe /mcp
mcp.user, mcp.passwordinsights collector roleLogin role for read-only SQL; each call switches to the token's own role
mcp.max_connections4Concurrent database connections for all tokens
mcp.max_rows_per_call10000Ceiling for every token's rows per call
mcp.max_statement_timeout_ms30000Ceiling for every token's statement timeout
mcp.max_result_bytes1048576Ceiling for result size
mcp.lock_timeout_ms1000Lock timeout for read-only SQL
mcp.allowed_hostsemptyAccepted Host values. Empty accepts loopback and the host of access.public_url; ["*"] accepts any (a token is always required)
mcp.allowed_originsemptyAccepted browser Origin values; empty refuses requests that carry one
mcp.audit_capacity500Recent calls kept for the console

Tokens#

Create tokens in the console (MCP access, New token). A token has a name, access (read or operate), the databases it may reach, the tools it may call, optional sensitive resources (statement text, client addresses, audit log), an expiry and an optional IP allowlist. A token can never do more than the person who created it.

LimitDefaultMeaning
Rows per call1000Rows a SQL call may return
Statement timeout5000 msTime one statement may run
Calls per minute30Rate limit
Database time per hour60000 msRolling budget of database time

Tools#

ToolPurpose
list_databases, list_pools, pool_limitsEstate, pool and limit status
list_clientsLive sessions; client addresses need the resource grant
slow_queries, slow_query_detail, template_plan, list_hintsSlow-query templates, details, plans and hints
capture_plan, update_hintOperate access: queue a plan capture, change hint state
read_audit_logNeeds the audit log resource
queryRead-only SQL, run in a read-only transaction under the token's role; parameters are never returned

Connect a client#

Clients that speak Streamable HTTP connect to https://your-host/mcp with the token in an Authorization: Bearer header. Clients that only launch local commands can use the stdio bridge, which reads the token from the environment:

stdio bridge
export STREAMQL_MCP_TOKEN=...    # the token shown once in the console
streamql mcp --url http://127.0.0.1:9930/mcp