Skip to content

Commit 256dbbf

Browse files
committed
Init
1 parent c8bc555 commit 256dbbf

File tree

18 files changed

+1304
-1
lines changed

18 files changed

+1304
-1
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/
8+
9+
# Test binary, built with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool, specifically when used with LiteIDE
13+
*.out
14+
15+
# Dependency directories (remove the comment below to include it)
16+
vendor/
17+
18+
# IDE files
19+
.idea/
20+
.vscode/
21+
*.swp
22+
*.swo
23+
24+
# Logs
25+
*.log
26+
27+
# OS-specific files
28+
.DS_Store

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM golang:1.21-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
# Copy go mod and sum files
6+
COPY go.mod go.sum ./
7+
8+
# Download dependencies
9+
RUN go mod download
10+
11+
# Copy source code
12+
COPY . .
13+
14+
# Build the application
15+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o trino-mcp ./cmd/server
16+
17+
# Use a small image for the final container
18+
FROM alpine:latest
19+
20+
RUN apk --no-cache add ca-certificates
21+
22+
WORKDIR /root/
23+
24+
# Copy the binary from the builder stage
25+
COPY --from=builder /app/trino-mcp .
26+
27+
# Default environment variables
28+
ENV TRINO_HOST="trino"
29+
ENV TRINO_PORT="8080"
30+
ENV TRINO_USER="trino"
31+
ENV TRINO_CATALOG="memory"
32+
ENV TRINO_SCHEMA="default"
33+
ENV MCP_TRANSPORT="http"
34+
ENV MCP_PORT="9097"
35+
36+
# Expose the port
37+
EXPOSE ${MCP_PORT}
38+
39+
# Run the application
40+
CMD ["./trino-mcp"]

PROMPT.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
Certainly! Here's the complete document with the incorporated entity-relationship diagram information:
2+
3+
---
4+
5+
**Title:** GitHub - stinkgen/trino_mcp: MCP Server for Trino
6+
7+
**URL Source:** [GitHub Repository](https://github.com/stinkgen/trino_mcp)
8+
9+
**Objective:** Reimplement the Trino MCP Server in Go using the MCP SDK.
10+
11+
**Overview:**
12+
13+
The Trino MCP Server provides a Model Context Protocol (MCP) server for Trino, enabling AI models to access Trino's distributed SQL query engine. Trino, formerly known as PrestoSQL, is a powerful distributed SQL query engine designed for fast analytics on large datasets, particularly beneficial in the adtech industry. The current implementation is in Python, and the goal is to reimplement it in Go using the MCP SDK from [mark3labs/mcp-go](https://github.com/mark3labs/mcp-go).
14+
15+
**Key Features to Implement:**
16+
17+
1. **Server Initialization:**
18+
- Create an MCP server using Go.
19+
- Ensure compatibility with Trino's distributed SQL query engine.
20+
21+
2. **API Exposure:**
22+
- Implement REST API endpoints for querying Trino.
23+
- Support both Docker container API and standalone server options.
24+
25+
3. **LLM Integration:**
26+
- Enable LLMs to query and analyze data in Trino.
27+
- Provide command-line and REST API interfaces for LLMs.
28+
29+
4. **Transport Options:**
30+
- Implement reliable STDIO transport.
31+
- Address known issues with SSE transport.
32+
33+
5. **Testing and Validation:**
34+
- Develop comprehensive test scripts to validate API functionality.
35+
- Ensure robust error handling and query execution.
36+
37+
**Adtech Data Exploration with Trino:**
38+
39+
- **Types of Data:**
40+
- Impression, Click, Conversion, User, Campaign Performance, Publisher, Bid, Geolocation, Device, and Browser Data.
41+
42+
- **Trends and Insights:**
43+
- Audience Segmentation, Ad Performance Analysis, Attribution Modeling, Fraud Detection, Real-Time Bidding Efficiency, Cross-Channel Analysis, Seasonal Trends, User Engagement Trends, Geographical Performance, Device, and Platform Trends.
44+
45+
**What LLMs Can Achieve with Trino:**
46+
47+
- **Scalable Data Analysis:** LLMs can leverage Trino's ability to handle large datasets across distributed systems, enabling comprehensive analysis of vast adtech data.
48+
- **Real-Time Insights:** By utilizing Trino's fast query capabilities, LLMs can provide real-time analytics and insights, facilitating immediate decision-making.
49+
- **Unified Data Access:** LLMs can query data from multiple sources through Trino, offering a cohesive view of diverse datasets such as Hadoop, S3, and various databases.
50+
- **SQL-Based Interactions:** With Trino's SQL compatibility, LLMs can easily generate and execute complex queries, making data exploration intuitive and efficient for data analysts.
51+
52+
**Entity-Relationship Diagram:**
53+
54+
```mermaid
55+
erDiagram
56+
idsp_deliveries }|--|| idsp_metrics_derived_report : feeds
57+
idsp_tpats_start_hbp_enriched }|--|| idsp_metrics_derived_report : feeds
58+
idsp_tpats_start_enriched }|--|| idsp_metrics_derived_report : feeds
59+
idsp_metrics_derived_report }|--|| publisher_report : generates
60+
idsp_metrics_derived_report }|--|| advertiser_report : generates
61+
edsp_metrics_derived_report }|--|| publisher_report : generates
62+
edsp_metrics_derived_report }|--|| edsp_report : generates
63+
as_tpats }|--|| idsp_tpats_start_enriched : links
64+
as_tpats }|--|| idsp_tpats_complete_enriched : links
65+
as_tpats }|--|| edsp_tpats_start_enriched : links
66+
as_tpats }|--|| edsp_tpats_complete_enriched : links
67+
hb_notifications }|--|| hbp_wins : triggers
68+
hbp_wins }|--|| edsp_tpats_start_hbp_enriched : triggers
69+
idsp_tpats_complete_enriched }|--|| idsp_metrics_derived_report : feeds
70+
idsp_tpats_click_enriched }|--|| idsp_metrics_derived_report : feeds
71+
idsp_installs_enriched }|--|| idsp_metrics_derived_report : feeds
72+
edsp_deliveries }|--|| edsp_metrics_derived_report : feeds
73+
edsp_tpats_start_hbp_enriched }|--|| edsp_metrics_derived_report : feeds
74+
edsp_tpats_start_enriched }|--|| edsp_metrics_derived_report : feeds
75+
edsp_tpats_complete_enriched }|--|| edsp_metrics_derived_report : feeds
76+
edsp_tpats_click_enriched }|--|| edsp_metrics_derived_report : feeds
77+
hb_transactions }|--|| hbp_auctions_served : triggers
78+
hb_notifications }|--|| hbp_notifications_enriched : transforms
79+
hbp_auctions_served }|--|| hbp_notifications_enriched : enriches
80+
ex_jaeger_transaction }|--|| edsp_deliveries : informs
81+
as_tpats }|--|| edsp_tpats_start_hbp_enriched : links
82+
edsp_deliveries }|--|| hbp_report : generates
83+
hbp_notifications_enriched }|--|| hbp_report : generates
84+
hbp_notifications_enriched }|--|| hbp_notifications_enriched_compact_hourly : compacts
85+
edsp_deliveries }|--|| edsp_deliveries_compact_hourly : compacts
86+
idsp_installs_enriched }|--|| ltv_report : contributes
87+
advertiser_user_events }|--|| ltv_report : contributes
88+
idsp_installs_enriched }|--|| ltv_pie_stats : contributes
89+
advertiser_user_events }|--|| ltv_pie_stats : contributes
90+
as_tpats }|--|| idsp_tpats_click_enriched : links
91+
as_tpats }|--|| edsp_tpats_click_enriched : links
92+
as_tpats }|--|| idsp_tpats_start_hbp_enriched : links
93+
currency_exchange_rates }|--|| ltv_report : enhances
94+
currency_exchange_rates }|--|| ltv_pie_stats : enhances
95+
in_eventdatainfo }|--|| advertiser_user_events : populates
96+
in_eventdatainfo }|--|| advertiser_user_events_complete : populates
97+
in_eventdatainfo }|--|| advertiser_user_events_non_vungle : populates
98+
coba2_vcl_cip_info }|--|| vcl_cip_info : joins
99+
edsp_deliveries }|--|| device_profile_derived_metrics : feeds
100+
edsp_deliveries }|--|| edsp_tpats_start_enriched : triggers
101+
edsp_deliveries }|--|| edsp_tpats_click_enriched : triggers
102+
edsp_deliveries }|--|| edsp_tpats_complete_enriched : triggers
103+
as_tpats }|--|| edsp_tpats_reattribute : feeds
104+
edsp_deliveries }|--|| edsp_tpats_reattribute : feeds
105+
edsp_tpats_start_enriched }|--|| edsp_tpats_start_reattribute : starts
106+
hbp_wins }|--|| edsp_tpats_start_reattribute : starts
107+
edsp_tpats_reattribute }|--|| edsp_tpats_start_enriched : backfills
108+
edsp_tpats_start_reattribute }|--|| edsp_tpats_start_hbp_enriched : follows
109+
edsp_tpats_reattribute }|--|| edsp_tpats_click_enriched : triggers
110+
edsp_tpats_start_enriched }|--|| edsp_tpats_start_hbp_enriched : follows
111+
edsp_tpats_start_reattribute }|--|| edsp_tpats_complete_enriched : triggers
112+
idsp_deliveries }|--|| hbp_report : supports
113+
as_installpostbacks }|--|| install_postbacks : triggers
114+
as_deliveries }|--|| idsp_deliveries : maps
115+
as_installpostbacks }|--|| idsp_installs_enriched : maps
116+
idsp_deliveries }|--|| idsp_installs_enriched : maps
117+
ex_jaeger_transaction_noserv }|--|| publisher_report : contributes
118+
hb_transactions_noserv }|--|| hbp_report : contributes
119+
ex_jaeger_auction_report_az }|--|| ex_jaeger_auction_report_sample : samples
120+
```
121+
122+
**Development Steps:**
123+
124+
1. **Setup Go Environment:**
125+
- Install Go and clone the MCP SDK repository.
126+
- Familiarize yourself with the MCP SDK's core concepts and examples.
127+
128+
2. **Server Implementation:**
129+
- Use the MCP SDK to create a new MCP server in Go.
130+
- Implement the necessary tools and resources to interact with Trino.
131+
132+
3. **API Development:**
133+
- Develop REST API endpoints for executing SQL queries.
134+
- Ensure the API supports both Docker and standalone deployments.
135+
136+
4. **Testing and Debugging:**
137+
- Write and run tests to ensure the server's functionality.
138+
- Address any issues related to transport methods and API responses.
139+
140+
5. **Documentation:**
141+
- Document the Go implementation, including setup instructions and usage examples.
142+
- Provide clear guidelines for integrating with LLMs.
143+
144+
**Resources:**
145+
146+
- [Trino MCP Server Documentation](https://github.com/stinkgen/trino_mcp)
147+
- [MCP Go SDK Documentation](https://github.com/mark3labs/mcp-go)
148+
149+
**Future Enhancements:**
150+
151+
- Integrate with newer MCP versions to resolve transport issues.
152+
- Expand support for additional data types and Trino features.
153+
- Enhance error handling and user authentication mechanisms.
154+
155+
---
156+
157+
This document provides a comprehensive guide for reimplementing the Trino MCP Server in Go, highlighting the benefits of Trino in the adtech industry, outlining the development process, and illustrating the relationships between different data entities.

README.md

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,115 @@
1-
init
1+
# Trino MCP Server in Go
2+
3+
Model Context Protocol (MCP) server for Trino, reimplemented in Go.
4+
5+
## Overview
6+
7+
This project is a reimplementation of the Trino MCP Server in Go using the MCP SDK from [mark3labs/mcp-go](https://github.com/mark3labs/mcp-go). It enables AI models to access Trino's distributed SQL query engine through the Model Context Protocol.
8+
9+
Trino (formerly known as PrestoSQL) is a powerful distributed SQL query engine designed for fast analytics on large datasets, particularly beneficial in the adtech industry.
10+
11+
## Features
12+
13+
- ✅ MCP server implementation in Go
14+
- ✅ Trino SQL query execution through MCP tools
15+
- ✅ Catalog, schema, and table discovery
16+
- ✅ Docker container support
17+
- ✅ Reliable STDIO transport for LLM integration
18+
- ✅ HTTP API endpoints for querying
19+
20+
## Prerequisites
21+
22+
- Go 1.19 or later
23+
- Docker and Docker Compose (for containerized usage)
24+
- A running Trino server (or use the provided Docker setup)
25+
26+
## Installation
27+
28+
1. Clone the repository:
29+
30+
```bash
31+
git clone https://github.com/tuannvm/mcp-trino.git
32+
cd mcp-trino
33+
```
34+
35+
2. Build the server:
36+
37+
```bash
38+
./scripts/build.sh
39+
```
40+
41+
## Usage
42+
43+
### Standalone Usage
44+
45+
Run the server with STDIO transport (for direct LLM integration):
46+
47+
```bash
48+
./scripts/run.sh
49+
```
50+
51+
Or with HTTP transport:
52+
53+
```bash
54+
MCP_TRANSPORT=http MCP_PORT=9097 ./scripts/run.sh
55+
```
56+
57+
### Docker Usage
58+
59+
Start the server with Docker Compose:
60+
61+
```bash
62+
docker-compose up -d
63+
```
64+
65+
Verify the API is working:
66+
67+
```bash
68+
curl -X POST "http://localhost:9097/api/query" \
69+
-H "Content-Type: application/json" \
70+
-d '{"query": "SELECT 1 AS test"}'
71+
```
72+
73+
## MCP Tools
74+
75+
The server provides the following MCP tools:
76+
77+
1. `execute_query` - Execute a SQL query against Trino
78+
2. `list_catalogs` - List all catalogs available in the Trino server
79+
3. `list_schemas` - List all schemas in a catalog
80+
4. `list_tables` - List all tables in a schema
81+
5. `get_table_schema` - Get the schema of a table
82+
83+
## Configuration
84+
85+
The server can be configured using the following environment variables:
86+
87+
| Variable | Description | Default |
88+
| -------------- | ----------------------------- | --------- |
89+
| TRINO_HOST | Trino server hostname | localhost |
90+
| TRINO_PORT | Trino server port | 8080 |
91+
| TRINO_USER | Trino user | trino |
92+
| TRINO_PASSWORD | Trino password | (empty) |
93+
| TRINO_CATALOG | Default catalog | memory |
94+
| TRINO_SCHEMA | Default schema | default |
95+
| MCP_TRANSPORT | Transport method (stdio/http) | stdio |
96+
| MCP_PORT | HTTP port for http transport | 9097 |
97+
98+
## Development
99+
100+
1. Setup Go environment
101+
2. Install dependencies:
102+
103+
```bash
104+
go mod download
105+
```
106+
107+
3. Run tests:
108+
109+
```bash
110+
go test ./...
111+
```
112+
113+
## License
114+
115+
MIT

0 commit comments

Comments
 (0)