ST

stinkgen/trino_mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

10 stars 6 forks 质量 49 趋势 18MIT

MCP Server for Trino

概览

Model Context Protocol server for Trino, providing AI models with structured access to Trino's distributed SQL query engine. ⚠️ ⚠️ This project is stabilizing with core features working and tested. Feel free to fork and contribute! - ✅ Fixed Docker container API initialization issue! (reliable server initalization) - ✅ Exposes Trino resources through MCP protocol - ✅ Enables AI tools to query and analyze data in Trino - ✅ Provides transport options (STDIO transport works reliably; SSE transport has issues) - ✅ Fixed catalog handling for proper Trino query execution - ✅ Both Docker container API and standalone Python API server options Need a non-containerized version? Run the standalone API: Want to give an LLM direct access to query your Trino instance? We've created simple tools for that!

README

以下为原文 README 节选,完整内容请查看原文。

Trino MCP Server

Model Context Protocol server for Trino, providing AI models with structured access to Trino’s distributed SQL query engine.

⚠️ BETA RELEASE (v0.1.2) ⚠️
This project is stabilizing with core features working and tested. Feel free to fork and contribute!

Features

  • ✅ Fixed Docker container API initialization issue! (reliable server initalization)
  • ✅ Exposes Trino resources through MCP protocol
  • ✅ Enables AI tools to query and analyze data in Trino
  • ✅ Provides transport options (STDIO transport works reliably; SSE transport has issues)
  • ✅ Fixed catalog handling for proper Trino query execution
  • ✅ Both Docker container API and standalone Python API server options

Quick Start

# Start the server with docker-compose
docker-compose up -d

# Verify the API is working
curl -X POST "http://localhost:9097/api/query" \
     -H "Content-Type: application/json" \
     -d '{"query": "SELECT 1 AS test"}'

Need a non-containerized version? Run the standalone API:

# Run the standalone API server on port 8008
python llm_trino_api.py

LLM Integration

Want to give an LLM direct access to query your Trino instance? We’ve created simple tools for that!

Command-Line LLM Interface

The simplest way to let an LLM query Trino is through our command-line tool:

# Simple direct query (perfect for LLMs)
python llm_query_trino.py "SELECT * FROM memory.bullshit.real_bullshit_data LIMIT 5"

# Specify a different catalog or schema
python llm_query_trino.py "SELECT * FROM information_schema.tables" memory information_schema

REST API for LLMs

We offer two API options for integration with LLM applications:

1. Docker Container API (Port 9097)

The Docker container exposes a REST API on port 9097:

# Execute a query against the Docker container API
curl -X POST "http://localhost:9097/api/query" \
     -H "Content-Type: application/json" \
     -d '{"query": "SELECT 1 AS test"}'

2. Standalone Python API (Port 8008)

For more flexible deployments, run the standalone API server:

# Start the API server on port 8008
python llm_trino_api.py

This creates endpoints at:

  • GET http://localhost:8008/ - API usage info
  • POST http://localhost:8008/query - Execute SQL queries

You can then have your LLM make HTTP requests to this endpoint:

# Example code an LLM might generate
import requests

def query_trino(sql_query):
    response = requests.post(
        "http://localhost:8008/query",
        json={"query": sql_query}
    )
    return response.json()

# LLM-generated query
results = query_trino("SELECT job_title, AVG(salary) FROM memory.bullshit.real_bullshit_data GROUP BY job_title ORDER BY AVG(salary) DESC LIMIT 5")
print(results["formatted_results"])

This approach allows LLMs to focus on generating SQL, while our tools handle all the MCP protocol complexity!

Demo and Validation Scripts 🚀

在 GitHub 查看完整 README

安装

docker exec -i trino_mcp_trino-mcp_1 python -m trino_mcp.server --transport stdio --debug --trino-host trino --trino-port 8080 --trino-user trino --trino-catalog memory
新手?先看 mcpskill.org 教程 →