Trino MCP Server

Trino MCP Server

Enables querying Trino with SSO via OAuth2 external authentication, compatible with Cursor.

Category
访问服务器

README

Trino MCP Server

Python MCP server for querying Trino with SSO via OAuth2 external authentication. It uses trino-python-client, launches the browser on first authenticated query, and communicates with MCP clients over stdio.

This repository is intended to be simple, local-first, and compatible with Cursor.

Features

  • Python 3.10+
  • trino-python-client with OAuth2Authentication()
  • MCP server built with @modelcontextprotocol/python-sdk
  • stdio transport for Cursor compatibility
  • Reusable Trino connection
  • JSON-compatible responses for every tool
  • Simple logging to stderr
  • Safer identifier handling for catalog, schema, and table names

Project structure

trino_mcp/
├── server.py
└── requirements.txt

Requirements

  • Python 3.10+
  • Network access to the target Trino cluster
  • A Trino environment configured for OAuth2 / external authentication

Quick start

Install directly from GitHub:

pip install "git+https://github.com/ThainaJardim/trino-mcp-python.git"

Then create a local .cursor/mcp.json like this:

{
  "mcpServers": {
    "trino": {
      "command": "/absolute/path/to/python",
      "args": ["-m", "trino_mcp.server"],
      "env": {
        "TRINO_HOST": "your-trino-host.example.com",
        "TRINO_PORT": "443",
        "TRINO_USER": "your-user",
        "TRINO_CATALOG": "hive",
        "TRINO_SCHEMA": "default",
        "TRINO_HTTP_SCHEME": "https"
      }
    }
  }
}

After reloading Cursor, test with:

  • list_catalogs
  • execute_query with { "sql": "SELECT 1 AS ok" }

Expected behavior:

  • the MCP server starts over stdio
  • the first real query opens the browser for OAuth2 / SSO login
  • after login, the query result returns as structured JSON

Installation from source

pip install -r trino_mcp/requirements.txt

Or install the project itself:

pip install .

Configuration

The server can be configured with environment variables.

Variable Default
TRINO_HOST trino.example.com
TRINO_PORT 443
TRINO_USER current OS user
TRINO_CATALOG hive
TRINO_SCHEMA default
TRINO_HTTP_SCHEME https
LOG_LEVEL INFO

Example:

export TRINO_HOST=trino.example.com
export TRINO_PORT=443
export TRINO_USER="$USER"
export TRINO_CATALOG=hive
export TRINO_SCHEMA=default
export TRINO_HTTP_SCHEME=https

Run locally

python trino_mcp/server.py

Or, after pip install .:

trino-mcp

Expected behavior:

  • The server starts and waits for MCP requests over stdio
  • The browser does not open immediately
  • The OAuth2 login flow starts only when a tool executes the first real query

Cursor setup

Create a local .cursor/mcp.json file like this:

{
  "mcpServers": {
    "trino": {
      "command": "/absolute/path/to/python",
      "args": ["-m", "trino_mcp.server"],
      "env": {
        "TRINO_HOST": "your-trino-host.example.com",
        "TRINO_PORT": "443",
        "TRINO_USER": "your-user",
        "TRINO_CATALOG": "hive",
        "TRINO_SCHEMA": "default",
        "TRINO_HTTP_SCHEME": "https"
      }
    }
  }
}

Why use this format:

  • command should point to the exact Python where trino-mcp was installed
  • -m trino_mcp.server avoids depending on the shell PATH
  • env keeps the Trino connection settings local to the MCP server

If you are developing from a local checkout instead of installing from GitHub, this also works:

{
  "mcpServers": {
    "trino": {
      "command": "/absolute/path/to/python",
      "args": ["./trino_mcp/server.py"],
      "env": {
        "TRINO_HOST": "your-trino-host.example.com",
        "TRINO_PORT": "443",
        "TRINO_USER": "your-user",
        "TRINO_CATALOG": "hive",
        "TRINO_SCHEMA": "default",
        "TRINO_HTTP_SCHEME": "https"
      }
    }
  }
}

The .cursor/ directory is intentionally ignored by Git because it contains machine-specific local configuration.

Available tools

Tool Description Input
execute_query Execute an arbitrary SQL query { "sql": "SELECT 1" }
list_catalogs Run SHOW CATALOGS {}
list_schemas Run SHOW SCHEMAS FROM <catalog> { "catalog": "hive" }
list_tables Run SHOW TABLES FROM <catalog>.<schema> { "catalog": "hive", "schema": "default" }
describe_table Run DESCRIBE <catalog>.<schema>.<table> { "catalog": "hive", "schema": "default", "table": "my_table" }
sample_table Run SELECT * FROM <catalog>.<schema>.<table> LIMIT <limit> { "catalog": "hive", "schema": "default", "table": "my_table", "limit": 20 }

Response format

Successful tool calls return a JSON-compatible object like:

{
  "ok": true,
  "sql": "SHOW CATALOGS",
  "columns": ["Catalog"],
  "row_count": 2,
  "rows": [
    { "Catalog": "hive" },
    { "Catalog": "system" }
  ]
}

Errors are returned in a structured format:

{
  "ok": false,
  "sql": "SHOW CATALOGS",
  "error": "..."
}

How OAuth2 login works

This project relies on OAuth2Authentication() from trino-python-client, which supports external browser login flows. In practice:

  1. Cursor calls a tool such as list_catalogs
  2. The server opens a Trino connection
  3. trino-python-client launches the browser for the OAuth2 login if needed
  4. After authentication, the query is executed and the response is returned to Cursor

This is different from adding OAuth to the MCP server itself. The OAuth flow here is specifically for the Trino connection.

Troubleshooting

Cursor says the MCP server errored

The most common cause is an interpreter mismatch:

  • python in your shell has mcp and trino
  • Cursor starts the server with another interpreter such as system python3

Check both:

python -c "import sys; print(sys.executable); import mcp, trino; print('ok')"
python3 -c "import sys; print(sys.executable); import mcp, trino; print('ok')"

If only one of them works, use that exact interpreter in .cursor/mcp.json.

The browser does not open

  • Make sure the first tool call actually reached Trino
  • Check that the environment has a GUI/browser available
  • Confirm the Trino cluster is configured for OAuth2 external authentication

Authentication keeps repeating

OAuth token caching behavior depends on the trino-python-client process lifetime. If the MCP process is restarted frequently, the login flow may repeat.

Manual test

You can test the server with the MCP Inspector:

npx -y @modelcontextprotocol/inspector /absolute/path/to/python -m trino_mcp.server

Then call list_catalogs and verify that:

  • the browser login opens
  • the query succeeds
  • the response returns structured JSON

Development

Install development dependencies:

pip install .[dev]

Run tests:

pytest

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选