mcp-trino
Trino MCP 服务器 (Go 版)
一个用 Go 语言实现的高性能 Trino 模型上下文协议 (MCP) 服务器。本项目使 AI 助手能够通过标准化的 MCP 工具与 Trino 分布式 SQL 查询引擎无缝交互。
概述
本项目使用 Go 语言实现了 Trino 的模型上下文协议 (MCP) 服务器。它使 AI 助手能够通过标准化的 MCP 工具访问 Trino 的分布式 SQL 查询引擎。
Trino(前身为 PrestoSQL)是一个功能强大的分布式 SQL 查询引擎,专为对大型数据集进行快速分析而设计。
Related MCP server: mcp-pprof-anaylzer
架构
graph TB
subgraph "AI Clients"
CC[Claude Code]
CD[Claude Desktop]
CR[Cursor]
WS[Windsurf]
CW[ChatWise]
end
subgraph "Authentication (Optional)"
OP[OAuth Provider<br/>Okta/Google/Azure AD]
JWT[JWT Tokens]
end
subgraph "MCP Server (mcp-trino)"
HTTP[HTTP Transport<br/>/mcp endpoint]
STDIO[STDIO Transport]
AUTH[OAuth Middleware]
TOOLS[MCP Tools<br/>• execute_query<br/>• list_catalogs<br/>• list_schemas<br/>• list_tables<br/>• get_table_schema<br/>• explain_query]
end
subgraph "Data Layer"
TRINO[Trino Cluster<br/>Distributed SQL Engine]
CATALOGS[Data Sources<br/>• PostgreSQL<br/>• MySQL<br/>• S3/Hive<br/>• BigQuery<br/>• MongoDB]
end
%% Connections
CC -.->|OAuth Flow| OP
OP -.->|JWT Token| JWT
CC -->|HTTP + JWT| HTTP
CD -->|STDIO| STDIO
CR -->|HTTP + JWT| HTTP
WS -->|STDIO| STDIO
CW -->|HTTP + JWT| HTTP
HTTP --> AUTH
AUTH -->|Validated| TOOLS
STDIO --> TOOLS
TOOLS -->|SQL Queries| TRINO
TRINO --> CATALOGS
%% Styling
classDef client fill:#e1f5fe
classDef auth fill:#f3e5f5
classDef server fill:#e8f5e8
classDef data fill:#fff3e0
class CC,CD,CR,WS,CW client
class OP,JWT auth
class HTTP,STDIO,AUTH,TOOLS server
class TRINO,CATALOGS data关键组件:
AI 客户端:各种兼容 MCP 的应用程序
身份验证:可选的 OAuth 2.0 与 OIDC 提供商
MCP 服务器:基于 Go 的服务器,支持双重传输
CLI 模式:用于直接访问 Trino 的交互式 SQL shell(类似于 psql)
数据层:连接到多个数据源的 Trino 集群
特性
✅ 双重模式:既可作为 MCP 服务器,也可作为交互式 CLI
CLI 模式:类似于 psql 的交互式 SQL shell,用于直接访问 Trino
MCP 模式:用于 AI 助手集成的完整 MCP 服务器
✅ 使用 Go 实现的 MCP 服务器
✅ 通过 MCP 工具执行 Trino SQL 查询
✅ 目录 (Catalog)、模式 (Schema) 和表发现
✅ Docker 容器支持
✅ 支持 STDIO 和 HTTP 传输
✅ 通过 oauth-mcp-proxy 库实现 OAuth 2.1 身份验证
4 种提供商:HMAC、Okta、Google、Azure AD
原生模式:客户端直接处理 OAuth(无需服务器端密钥)
代理模式:服务器为简单客户端代理 OAuth 流程
生产就绪:令牌缓存、PKCE、深度防御安全
可重用:OAuth 库可用于任何 Go MCP 服务器
✅ 支持带有 JWT 身份验证的 StreamableHTTP(从 SSE 升级而来)
✅ 向后兼容 SSE 端点
✅ 兼容 Cursor、Claude Desktop、Windsurf、ChatWise 以及任何兼容 MCP 的客户端。
✅ 用户身份追踪:
查询归属 (自动):通过
X-Trino-Client-Tags/Info标头将查询标记为 OAuth 用户用户模拟 (可选):通过
X-Trino-User标头以 OAuth 用户身份执行查询
安装与快速入门
安装:
# Homebrew
brew install tuannvm/mcp/mcp-trino
# Or one-liner (macOS/Linux)
curl -fsSL https://raw.githubusercontent.com/tuannvm/mcp-trino/main/install.sh | bash运行(本地开发):
export TRINO_HOST=localhost TRINO_USER=trino
mcp-trino如需进行带有 OAuth 的生产部署,请参阅 部署指南 和 OAuth 架构。
CLI 模式
mcp-trino 可用作类似于 psql 或 Trino CLI 的交互式 CLI:
# Interactive REPL mode
mcp-trino --interactive
# Execute a query directly
mcp-trino query "SELECT * FROM my_table LIMIT 10"
# List catalogs, schemas, tables
mcp-trino catalogs
mcp-trino schemas my_catalog
mcp-trino tables my_catalog my_schema
# Describe a table
mcp-trino describe my_catalog.my_schema.my_table
# Explain a query
mcp-trino explain "SELECT COUNT(*) FROM my_table"
# Output formats
mcp-trino --format json query "SELECT 1"
mcp-trino --format csv query "SELECT 1"
mcp-trino --format table query "SELECT 1" # default内置帮助
每个命令都有结构化、对 LLM 友好的帮助输出:
# Main help with all commands, flags, examples, and environment variables
mcp-trino --help
# Per-subcommand help
mcp-trino query --help
mcp-trino describe --help帮助输出遵循 Unix 手册页约定,包含以下部分:名称 (NAME)、概要 (SYNOPSIS)、描述 (DESCRIPTION)、命令 (COMMANDS)、标志 (FLAGS)、示例 (EXAMPLES)、环境 (ENVIRONMENT) 和配置 (CONFIGURATION)。
退出代码
代码 | 含义 |
0 | 成功 |
1 | 运行时错误(连接失败、查询错误等) |
2 | 使用错误(未知命令、无效标志、缺少参数) |
命名配置文件
mcp-trino 支持命名连接配置文件,以便在不同的 Trino 环境之间轻松切换。
配置文件 — 支持 YAML (~/.config/trino/config.yaml) 和 JSON (~/.config/trino/config.json):
# ~/.config/trino/config.yaml
current: prod
profiles:
prod:
host: trino.example.com
port: 443
user: prod_user
password: prod_password
catalog: hive
schema: analytics
ssl:
enabled: true
insecure: false
dev:
host: localhost
port: 8080
user: trino
catalog: memory
schema: default
staging:
host: staging-trino.example.com
port: 443
user: staging_user
output:
format: table或者等效的 JSON 格式:
{
"current": "prod",
"profiles": {
"prod": {
"host": "trino.example.com",
"port": 443,
"user": "prod_user",
"catalog": "hive",
"ssl": { "enabled": true }
},
"dev": {
"host": "localhost",
"port": 8080,
"user": "trino"
}
},
"output": { "format": "table" }
}当两个文件同时存在时,config.json 优先。新配置默认为 JSON。
配置文件管理命令:
# List all profiles
mcp-trino config profile list
# Set default profile
mcp-trino config profile use prod
# Show profile details
mcp-trino config profile show staging
# Use a specific profile (overrides config file)
mcp-trino --profile dev catalogs配置优先级(从高到低):
CLI 标志 (
--host,--port等)--profile标志TRINO_PROFILE环境变量配置文件中的
current字段default配置文件回退环境变量 (
TRINO_HOST等)
环境变量(优先级最低 - 被配置文件和标志覆盖):
export TRINO_HOST=trino.example.com
export TRINO_PORT=443
export TRINO_USER=myuser
export TRINO_PASSWORD=mypass
export TRINO_CATALOG=hive
export TRINO_SCHEMA=analytics
export TRINO_SSL=true密钥管理(推荐):
密钥完全从环境变量加载。使用密钥 CLI 在启动时通过 Unix 管道注入它们 — 应用程序永远不会接触您的保险库:
# 1Password CLI — resolves op:// references in an env file
op run --env-file=.env -- mcp-trino
# Or inline per-variable
TRINO_PASSWORD=$(op read 'op://Engineering/Trino/password') mcp-trino请参阅 docs/secrets.md 了解 1Password、Vault 和 Kubernetes 模式,以及安全细微差别(shell 历史记录、进程列表和环境变量泄露)。
REPL 元命令(在交互模式下):
\help- 显示帮助\quit,\exit,\q- 退出 REPL\history- 显示命令历史记录\catalogs- 列出所有目录\schemas [catalog]- 列出模式\tables [catalog schema]- 列出表\describe <table>- 描述表\format <table|json|csv>- 更改输出格式
使用方法
支持的客户端: Claude Desktop, Claude Code, Cursor, Windsurf, ChatWise
可用工具: execute_query, list_catalogs, list_schemas, list_tables, get_table_schema, explain_query
配置
关键变量: TRINO_HOST, TRINO_USER, TRINO_SCHEME, MCP_TRANSPORT, OAUTH_PROVIDER
密钥管理: 通过进程环境注入密钥 — mcp-trino 直接读取它们。请参阅 docs/secrets.md 了解 1Password、Vault 和 Kubernetes 的配置方法。
# 1Password (biometric-gated, zero disk writes)
op run --env-file=.env -- mcp-trino
# Vault (via vault-agent or CLI)
TRINO_PASSWORD=$(vault kv get -field=password secret/mcp-trino) mcp-trino
# Kubernetes: use standard Secret → envFrom in the Helm chart valuesOAuth 配置:
# Native mode (most secure - zero server-side secrets)
export OAUTH_ENABLED=true OAUTH_MODE=native OAUTH_PROVIDER=okta
export OIDC_ISSUER=https://company.okta.com OIDC_AUDIENCE=https://mcp-server.com
# Proxy mode (centralized credential management)
export OAUTH_MODE=proxy OIDC_CLIENT_ID=app-id OIDC_CLIENT_SECRET=secret
export OAUTH_REDIRECT_URI=https://mcp-server.com/oauth/callback # Fixed mode (localhost-only)
export OAUTH_REDIRECT_URI=https://app1.com/cb,https://app2.com/cb # Allowlist mode
export JWT_SECRET=$(openssl rand -hex 32) # Required for multi-pod deployments性能优化:
# Focus AI on specific schemas only (10-20x performance improvement)
export TRINO_ALLOWED_SCHEMAS="hive.analytics,hive.marts,hive.reporting"用户身份追踪:
# Query Attribution is AUTOMATIC when OAuth is enabled
# Queries are tagged with X-Trino-Client-Tags and X-Trino-Client-Info headers
# For full impersonation (Trino enforces user permissions):
export TRINO_ENABLE_IMPERSONATION=true
export TRINO_IMPERSONATION_FIELD=email # Options: username, email, subject有关完整配置,请参阅 部署指南、OAuth 指南、允许列表指南 和 用户身份指南。
OAuth 实现
mcp-trino 使用 oauth-mcp-proxy - 一个用于 Go MCP 服务器的独立 OAuth 2.1 库。
为什么使用单独的库?
✅ 可在任何 Go MCP 服务器中重用
✅ 独立的测试和版本控制
✅ 专门的文档和示例
✅ 社区维护的 OAuth 实现
有关 OAuth 的详细信息:
oauth-mcp-proxy 文档 - 完整的 OAuth 指南
提供商设置指南 - Okta, Google, Azure AD
安全最佳实践 - 生产环境安全
贡献
欢迎贡献!请随时提交 Pull Request。
许可证
本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。
相关项目
oauth-mcp-proxy - mcp-trino 使用的 OAuth 2.1 身份验证库(可用于任何 Go MCP 服务器)
CI/CD 和发布
本项目使用 GitHub Actions 进行持续集成,使用 GoReleaser 进行自动化发布。
持续集成检查
我们的 CI 流水线会对所有 PR 和提交到主分支的代码执行以下检查:
代码质量
Linting:使用 golangci-lint 检查常见代码问题和风格违规
Go 模块验证:确保 go.mod 和 go.sum 得到妥善维护
格式化:使用 gofmt 验证代码格式是否正确
安全性
漏洞扫描:使用 govulncheck 检查依赖项中的已知漏洞
依赖项扫描:使用 Trivy 扫描依赖项中的漏洞(严重、高和中等)
SBOM 生成:创建软件物料清单以进行依赖项跟踪
SLSA 溯源:创建可验证的构建溯源以确保供应链安全
测试
单元测试:运行带有竞态检测和代码覆盖率报告的测试
构建验证:确保代码库构建成功
CI/CD 安全
最小权限:工作流以最低所需权限运行
固定版本:所有 GitHub Actions 使用特定版本以防止供应链攻击
依赖项更新:通过 Dependabot 进行自动化依赖项更新
发布流程
当更改合并到主分支时:
运行 CI 检查以验证代码质量和安全性
如果成功,将自动创建一个新版本,包含:
基于提交信息的语义化版本控制
针对多个平台的二进制构建
将 Docker 镜像发布到 GitHub Container Registry
SBOM 和溯源证明
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables listing and querying Trino tables using Python, providing access to data resources through the Model-Control-Protocol.18MIT
- AlicenseNot gradedqualityCmaintenanceThis is a Model Context Protocol (MCP) server implemented in Go, providing a tool to analyze Go pprof performance profiles.50MIT
- AlicenseBqualityCmaintenanceA Model Context Protocol server that provides seamless integration with Trino and Iceberg, enabling data exploration, querying, and table maintenance through a standard interface.2225Apache 2.0
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that supports STDIO, SSE and Streamable HTTP protocols for AI model interactions.131MIT
Related MCP Connectors
A Model Context Protocol server for Wix AI tools
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/tuannvm/mcp-trino'
If you have feedback or need assistance with the MCP directory API, please join our Discord server