New
Apps 6,221Makers 6,200This week 13
Promote your app−30%
akko-mcp-trino screenshot 1
2views in
the last 30 days

akko-mcp-trino

Read-only MCP server for Trino: six tools, writes refused on the SQL tree

Built with Claude Code

by akko-p · Unclaimed · from FRFrance · added Nov 2, 2026
no ratings0 comments

akko-mcp-trino

English · Français

Give your AI agents read-only access to Trino, and nothing more.

akko-mcp-trino is an MCP server for Trino. It lets an agent find the tables and columns that hold what it is looking for, describe a schema or a table, list catalogs, schemas and tables, explain a query and run it, and it refuses every write it is sent: each statement is parsed, and a write anywhere in it is refused before Trino. By default every query runs as the user the agent acts for. The server verifies the user's token, issued for this server, and obtains from the identity provider a separate token for Trino (OAuth 2.0 Token Exchange): the user's own token never leaves the server. Trino's access control (OPA, Ranger, or Trino's own rules) then decides what that user may read. Results are bounded in rows and in time, and every call leaves one audit line.

Upgrading from 0.6? 0.7.0 removes and renames nothing: it adds search_columns and describe_schema, pages the listings, and gives every error a kind. Let the engine's policy read system.jdbc and system.metadata, which the two new tools read (0.6 advised refusing all of system). Keep MCP_CALL_TIMEOUT_SECONDS at 0 or above MCP_SEARCH_RESERVE_SECONDS (2 by default), or the server refuses to start. A truncated listing is no longer the end: read on with next_offset. Extension authors: one helper changes its signature, and in oauth2 mode the guards run on every request that is not discovery, no longer once at start.

From 0.5? 0.6.0 changed the defaults: a verified caller is required, and the jwt mode exchanges the caller's token instead of passing it on. See MIGRATING.md for both.

Understand in five steps

Carol, an analyst, asks for the list of customers. In an illustrative setup with a service account with broad rights, Trino sees mcp-svc and returns 10 customers with e-mails in clear. With akko-mcp-trino in its default jwt mode, Trino sees carol_analyst and returns 5 European customers with e-mails masked, as in the sandbox.

An agent connected through one service account with broad rights reaches Trino under that account, so the rules written for Carol no longer apply. The left panel is an illustration: the sandbox's policy would refuse such an account. akko-mcp-trino brings Carol's own identity to Trino, and the rules Trino already has do the rest.

The same query by three sandbox users, through the same MCP client. alice_admin gets the 10 customers in clear. carol_analyst gets the 5 European customers with masked e-mails. dave_viewer is refused by Trino: Access Denied: Cannot select from columns [country, full_name, id, email] in table or view demo.crm.customers.

The same query from the three users of the sandbox, through the same MCP client and the same server. Trino answers each of them with the sandbox's OPA policy; the server copies no rule.

A real trial of Mistral on 0.7.0, in six steps. It asks which customer segment holds the largest total account balance, searches with four words and gets matches word by word, joins on a column that does not exist, reads the server's hint, reads the columns of customers with describe_table, fixes the join and gets business, 17620.75.

A real trial, tool call by tool call: Mistral on 0.7.0 looks for the segment with the largest balance. The search matches word by word, the error on a wrong join names the table to read, and the agent fixes its join. Every tool answer shown is the server's, replayed in the sandbox.

Three questions pick an identity mode: token exchange gives jwt, a Trino impersonation rule gives impersonation, a server on one person's machine with Trino's OAuth2 login gives oauth2, otherwise service. The four modes are drawn on the same grid of MCP host, server and Trino; service, one account for everyone, is marked in amber.

Four identity modes, from the safest to the simplest. jwt is the default; service gives every caller the same account and is used only when you name it.

Mistral answers right 62.5% of the time on 0.6.1 and 70% on 0.7.0, Claude 93.3% on both. Mistral goes from 5.8 to 3.0 tool calls per question, Claude from 8.5 to 4.9. Mistral varies more between runs than the gap between versions, and input tokens rise by about 41%.

The same five business questions asked to Mistral and to Claude, on 0.6.1 and on 0.7.0. Mistral varies more from one run to the next than the gap between the versions, and 0.7.0 sends about 41% more input tokens per question, because its tool descriptions are longer. The harness and its reports are in akko-sandbox.

The interactive version of these five steps is on akko-ai.com/en/docs/understand (also en français).

Try it in five minutes

The sandbox starts Keycloak, Trino, OPA and the server on your machine, with the three users above:

git clone https://github.com/AKKO-p/akko-sandbox.git
cd akko-sandbox
docker compose up -d --wait
./demo.sh

Why

An agent that reads a lakehouse needs a small, predictable surface: a few tools whose descriptions a model understands, answers that never run away, and a guarantee that a prompt injection cannot turn a question into a DROP TABLE through it. This server is that surface, and nothing else. It does not decide access: Trino decides for each user with the rules it already has, or, in service mode, for the one identity you give it.

Highlights

  • Read-only by construction, through this server. SQL is parsed into an AST and refused if a write appears anywhere in the tree, CTEs and subqueries included. Table functions (TABLE(...), such as a JDBC connector's system.query) and the system catalog are refused too, including through a name without a catalog when the session catalog is system. What a user may do in Trino by other means is Trino's rules: see What read-only covers.
  • The user's own rights, safe by default. In jwt mode, the default, the server verifies the caller's token (issued for this server, never for Trino), exchanges it at the identity provider for a token whose audience is Trino (RFC 8693), and Trino runs the query as that user. The caller's token is never passed on. A request without a valid token is refused with 401.
  • A fallback without token exchange. In impersonation mode the server authenticates to Trino as its own account (password or client certificate) and Trino runs the query as the verified caller, under an impersonation rule only that account has.
  • One identity, only when named. In service mode every query runs as TRINO_USER. It is never chosen by default, and the server says so at start and to every host in its initialization instructions.
  • Bounded by default. A row cap with a truncated flag (100), a time budget per query cancelled in Trino (60 s), a time budget per tool call (120 s).
  • One audit line per call. Keyed by X-Request-Id, never the token, never the SQL text: who called which tool, with which outcome, for how long.
  • Eight tools, annotated with what they can really do: execute_query is annotated read-only only while TRINO_READ_ONLY is true.
  • A guarded door. Bearer tokens verified against any OIDC provider's JWKS (issuer, audience bound to this server, expiry, clock tolerance), a token issued for Trino refused, protected resource metadata (RFC 9728), a Host header filter.
  • Built to be extended without being forked. Tool plugins and extensions are Python packages named at start: identity modes, guards at the door, audit fields, routes, tools. An extension can only refuse what the core allows, never widen it.
  • Any MCP host, any model. Cursor, Claude Desktop, VS Code, the Python SDK… Mistral, or any OpenAI-compatible model through the example agent.
  • Small and proven. 717 tests at 100 % line and branch coverage, including in-process suites on the real SDK for all three transports, a live run against Keycloak and Trino in CI (integration/), and a product-neutral guard.

Documentation

Contents

  1. How it works
  2. Compatibility
  3. Prerequisites
  4. Install and run
  5. Connect an MCP host
  6. Use it from an agent
  7. The tools
  8. What read-only covers
  9. Extensions
  10. What happens on a request
  11. Configuration
  12. Operations
  13. Development
  14. Design notes
  15. Contributing
  16. About AKKO

How it works

flowchart LR
    Host["MCP host<br/>(Cursor, Claude, VS Code, an agent)"]
    IdP["Identity provider<br/>(OIDC, JWKS, token exchange)"]
    Server["akko-mcp-trino"]
    Trino["Trino"]
    Policy["Policy engine<br/>(OPA, Ranger, built-in)"]
    Data[("Data sources")]

    Host -- "1. tool call + Bearer token<br/>(audience: this server)" --> Server
    Server -. "2. verify signature, issuer,<br/>audience, expiry (JWKS)" .-> IdP
    Server -. "3. exchange it for a token<br/>whose audience is Trino (RFC 8693)" .-> IdP
    Server -- "4. read-only SQL, with that token" --> Trino
    Trino -- "5. may this user read this?" --> Policy
    Trino -- "6. rows, as that user may read them" --> Server
    Server -- "7. result" --> Host
    Trino --> Data

The host calls a tool with the user's access token. The server verifies it (signature against the provider's JWKS, issuer, an audience naming this server, expiry) and refuses a request without a valid one with 401; a token issued for Trino is refused too. The server then checks the statement (read-only, identifiers, table functions, the system catalog) and runs it in Trino under the identity mode TRINO_IDENTITY_MODE names. Trino asks its policy engine and returns what that identity may read, bounded in rows and time.

Mode Who Trino sees How Trino knows When to use it
jwt (default) the caller a token for Trino the server obtained by token exchange (RFC 8693); Trino verifies it with its JWT authenticator the identity provider supports OAuth 2.0 Token Exchange (RFC 8693); tested with Keycloak 26
impersonation the caller the server's own account (password or client certificate) asks Trino to run the query as the caller; Trino allows it under an impersonation rule only that account has the identity provider cannot exchange tokens
oauth2 the local user, checked with SELECT current_user Trino's native OAuth2 browser login; the driver caches tokens and reauthenticates local stdio hosts only, with a Trino coordinator configured for OAuth2
service TRINO_USER, the same for every caller a password, a client certificate, or nothing, locally only when named: one identity for everyone, announced at start and to every host

The caller's own token never leaves the server, in any mode: the MCP authorization specification forbids passing it on ("token passthrough"). The caller's name comes from their verified token, or from Trino's SELECT current_user in oauth2, never from an unverified header. The jwt and impersonation modes refuse to start unless the door requires a valid token. An extension (see Extensions) may add other identity modes.

Compatibility

Supported Tested
Python 3.12, 3.13 3.12, 3.13 (CI)
Trino 351 and later; https with the JWT authenticator for jwt, with a password or certificate authenticator and impersonation rules for impersonation, with OAuth2 for oauth2 (stdio); http (local) or https for service a recent release with the JWT and certificate authenticators, behind OPA and behind file-based rules, with row filters and column masks
Policy engines OPA (trino-opa), Ranger (Trino plugin), Trino file-based access control OPA and file-based rules, with row filters and column masks
Identity providers any OIDC provider publishing a JWKS (the door); OAuth 2.0 Token Exchange, RFC 8693 (jwt mode) Keycloak 26 (standard token exchange)
MCP protocol negotiated by the official mcp SDK 2.2 (initialize handshake revisions 2024-11-05 to 2025-11-25, and the stateless 2026-07-28 revision); transports streamable-http, sse and stdio all three transports, official SDK client at its default revision, in CI
MCP hosts remote: anything that sends a bearer header; local: any stdio host Python SDK, the example agent
Models any, the server never talks to a model Mistral Small 3.2 through OpenRouter, driving the tools

Prerequisites

You need Why Notes
Python 3.12 or later runtime pip and a virtual environment
A reachable Trino coordinator the engine any recent version; https for jwt and impersonation, and whenever a secret is sent
An OIDC provider with a JWKS endpoint the door Keycloak, Entra ID, Okta, Dex… Tokens must carry iss, an aud naming this server, exp, and a subject (preferred_username or sub)
jwt: token exchange at the provider, and Trino's JWT authenticator each user reads with their own rights a confidential client for this server, allowed to exchange a token issued for it for one whose audience is Trino; http-server.authentication.type=JWT with the provider's JWKS and required-audience set to that audience
Or impersonation: an account for this server, and an impersonation rule each user reads with their own rights, without token exchange TRINO_USER with TRINO_PASSWORD or a client certificate; a Trino rule letting that account, and only it, impersonate users
Or service: one Trino identity the rights of every caller TRINO_USER, and TRINO_PASSWORD or a client certificate; give it read rights only on what every caller may read
A policy engine deciding for Trino the governance OPA (opa.policy.uri), Ranger, or Trino file-based rules
An MCP host the client Cursor, Claude Desktop, VS Code, or any client built on the mcp SDK

Optional: a Prometheus to scrape /metrics.

Install and run

pip install akko-mcp-trino        # or: pipx install akko-mcp-trino
uvx akko-mcp-trino --version      # run it without installing, the way most MCP hosts do

Or from source:

git clone https://github.com/AKKO-p/akko-mcp-trino.git
cd akko-mcp-trino
python -m venv .venv && source .venv/bin/activate
pip install -e .

The package installs a Python module (akko_mcp_trino) and a command (akko-mcp-trino); python -m akko_mcp_trino is the same entrypoint.

Point it at your Trino and your identity provider, then serve. The defaults are the safe ones: each query runs as the caller (jwt), and a request without a valid token is refused.

export TRINO_HOST=trino.example.internal
export TRINO_PORT=8443
export TRINO_HTTP_SCHEME=https          # required: a token never travels over http
export TRINO_CATALOG=iceberg

# The door: tokens issued for this server, verified against the provider's JWKS
export MCP_JWKS_URL=https://idp.example.com/realms/data/protocol/openid-connect/certs
export MCP_OIDC_ISSUER=https://idp.example.com/realms/data
export MCP_OIDC_AUDIENCE=akko-mcp        # the audience the provider gives tokens for this server
export MCP_RESOURCE_URL=https://mcp.example.com/mcp   # optional: this server's canonical URL

# A token for Trino, by token exchange (RFC 8693), never the caller's own
export TRINO_TOKEN_EXCHANGE_URL=https://idp.example.com/realms/data/protocol/openid-connect/token
export TRINO_TOKEN_EXCHANGE_CLIENT_ID=akko-mcp
export TRINO_TOKEN_EXCHANGE_CLIENT_SECRET=...
export TRINO_TOKEN_EXCHANGE_AUDIENCE=trino

python -m akko_mcp_trino

Before serving, akko-mcp-trino --check prints the effective configuration (never a secret), any warning, and exits with 2 if something would refuse to start; over stdio it checks that MCP_USER_TOKEN is present, not that it is valid (the real start verifies the token). Then:

INFO:__main__:serving transport=streamable-http port=3000 auth=True strict=True identity=jwt extensions=none

Check it is alive and can reach Trino:

curl -s localhost:3001/health   # {"status":"ok"}       never touches Trino
curl -s localhost:3001/ready    # {"status":"ready"}    jwt: Trino's /v1/info; impersonation and service: a bounded SELECT 1 as the server's account
curl -s localhost:3001/metrics  # Prometheus exposition

Each user with their own rights (jwt, the default)

The caller's token is issued for this server: its audience is MCP_OIDC_AUDIENCE (or MCP_RESOURCE_URL). The server exchanges it at the provider for a token whose audience is `TRINO_T

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#trino · #database · #mcp