mcp-trino-python 0.4.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/PKG-INFO +10 -24
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/README.md +9 -23
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/pyproject.toml +1 -1
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/PKG-INFO +10 -24
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/server.py +164 -112
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/trino_client.py +79 -69
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/LICENSE +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/setup.cfg +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/__init__.py +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/config.py +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/SOURCES.txt +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/dependency_links.txt +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/requires.txt +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-trino-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A Model Context Protocol (MCP) connector for Trino, enabling seamless integration between MCP-compliant services and Trino query engine
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Keywords: trino,connector,mcp
|
|
@@ -21,6 +21,7 @@ Dynamic: license-file
|
|
|
21
21
|
|
|
22
22
|
# MCP Trino Server
|
|
23
23
|
|
|
24
|
+
[](https://smithery.ai/server/@alaturqua/mcp-trino-python)
|
|
24
25
|
[](https://www.python.org/downloads/)
|
|
25
26
|
[](https://code.visualstudio.com/)
|
|
26
27
|
[](https://github.com/alaturqua/mcp-trino-python/pkgs/container/mcp-trino-python)
|
|
@@ -45,6 +46,14 @@ data exploration, querying, and table maintenance capabilities through a standar
|
|
|
45
46
|
|
|
46
47
|
## Installation
|
|
47
48
|
|
|
49
|
+
### Installing via Smithery
|
|
50
|
+
|
|
51
|
+
To install MCP Trino Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@alaturqua/mcp-trino-python):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx -y @smithery/cli install @alaturqua/mcp-trino-python --client claude
|
|
55
|
+
```
|
|
56
|
+
|
|
48
57
|
### Running Trino Locally
|
|
49
58
|
|
|
50
59
|
The easiest way to get started is to use the included Docker Compose configuration to run Trino locally:
|
|
@@ -119,29 +128,6 @@ Add the following configuration to your Claude Desktop settings:
|
|
|
119
128
|
| TRINO_HTTP_SCHEME | HTTP scheme (http/https) | http |
|
|
120
129
|
| TRINO_PASSWORD | Trino password | None |
|
|
121
130
|
|
|
122
|
-
## Resources
|
|
123
|
-
|
|
124
|
-
The server provides the following MCP resources:
|
|
125
|
-
|
|
126
|
-
### Catalog and Schema Navigation
|
|
127
|
-
|
|
128
|
-
- **catalog://main** (`list_catalogs`)
|
|
129
|
-
|
|
130
|
-
- Lists all available Trino catalogs
|
|
131
|
-
- No parameters required
|
|
132
|
-
|
|
133
|
-
- **schema://{catalog}** (`list_schemas`)
|
|
134
|
-
|
|
135
|
-
- Lists all schemas in the specified catalog
|
|
136
|
-
- Parameters:
|
|
137
|
-
- `catalog`: Catalog name (string, required)
|
|
138
|
-
|
|
139
|
-
- **table://{catalog}/{schema}** (`list_tables`)
|
|
140
|
-
- Lists all tables in the specified schema
|
|
141
|
-
- Parameters:
|
|
142
|
-
- `catalog`: Catalog name (string, required)
|
|
143
|
-
- `schema`: Schema name (string, required)
|
|
144
|
-
|
|
145
131
|
## Tools
|
|
146
132
|
|
|
147
133
|
### Query and Exploration Tools
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# MCP Trino Server
|
|
2
2
|
|
|
3
|
+
[](https://smithery.ai/server/@alaturqua/mcp-trino-python)
|
|
3
4
|
[](https://www.python.org/downloads/)
|
|
4
5
|
[](https://code.visualstudio.com/)
|
|
5
6
|
[](https://github.com/alaturqua/mcp-trino-python/pkgs/container/mcp-trino-python)
|
|
@@ -24,6 +25,14 @@ data exploration, querying, and table maintenance capabilities through a standar
|
|
|
24
25
|
|
|
25
26
|
## Installation
|
|
26
27
|
|
|
28
|
+
### Installing via Smithery
|
|
29
|
+
|
|
30
|
+
To install MCP Trino Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@alaturqua/mcp-trino-python):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx -y @smithery/cli install @alaturqua/mcp-trino-python --client claude
|
|
34
|
+
```
|
|
35
|
+
|
|
27
36
|
### Running Trino Locally
|
|
28
37
|
|
|
29
38
|
The easiest way to get started is to use the included Docker Compose configuration to run Trino locally:
|
|
@@ -98,29 +107,6 @@ Add the following configuration to your Claude Desktop settings:
|
|
|
98
107
|
| TRINO_HTTP_SCHEME | HTTP scheme (http/https) | http |
|
|
99
108
|
| TRINO_PASSWORD | Trino password | None |
|
|
100
109
|
|
|
101
|
-
## Resources
|
|
102
|
-
|
|
103
|
-
The server provides the following MCP resources:
|
|
104
|
-
|
|
105
|
-
### Catalog and Schema Navigation
|
|
106
|
-
|
|
107
|
-
- **catalog://main** (`list_catalogs`)
|
|
108
|
-
|
|
109
|
-
- Lists all available Trino catalogs
|
|
110
|
-
- No parameters required
|
|
111
|
-
|
|
112
|
-
- **schema://{catalog}** (`list_schemas`)
|
|
113
|
-
|
|
114
|
-
- Lists all schemas in the specified catalog
|
|
115
|
-
- Parameters:
|
|
116
|
-
- `catalog`: Catalog name (string, required)
|
|
117
|
-
|
|
118
|
-
- **table://{catalog}/{schema}** (`list_tables`)
|
|
119
|
-
- Lists all tables in the specified schema
|
|
120
|
-
- Parameters:
|
|
121
|
-
- `catalog`: Catalog name (string, required)
|
|
122
|
-
- `schema`: Schema name (string, required)
|
|
123
|
-
|
|
124
110
|
## Tools
|
|
125
111
|
|
|
126
112
|
### Query and Exploration Tools
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mcp-trino-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "A Model Context Protocol (MCP) connector for Trino, enabling seamless integration between MCP-compliant services and Trino query engine"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = { text = "Apache-2.0" }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-trino-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A Model Context Protocol (MCP) connector for Trino, enabling seamless integration between MCP-compliant services and Trino query engine
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Keywords: trino,connector,mcp
|
|
@@ -21,6 +21,7 @@ Dynamic: license-file
|
|
|
21
21
|
|
|
22
22
|
# MCP Trino Server
|
|
23
23
|
|
|
24
|
+
[](https://smithery.ai/server/@alaturqua/mcp-trino-python)
|
|
24
25
|
[](https://www.python.org/downloads/)
|
|
25
26
|
[](https://code.visualstudio.com/)
|
|
26
27
|
[](https://github.com/alaturqua/mcp-trino-python/pkgs/container/mcp-trino-python)
|
|
@@ -45,6 +46,14 @@ data exploration, querying, and table maintenance capabilities through a standar
|
|
|
45
46
|
|
|
46
47
|
## Installation
|
|
47
48
|
|
|
49
|
+
### Installing via Smithery
|
|
50
|
+
|
|
51
|
+
To install MCP Trino Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@alaturqua/mcp-trino-python):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx -y @smithery/cli install @alaturqua/mcp-trino-python --client claude
|
|
55
|
+
```
|
|
56
|
+
|
|
48
57
|
### Running Trino Locally
|
|
49
58
|
|
|
50
59
|
The easiest way to get started is to use the included Docker Compose configuration to run Trino locally:
|
|
@@ -119,29 +128,6 @@ Add the following configuration to your Claude Desktop settings:
|
|
|
119
128
|
| TRINO_HTTP_SCHEME | HTTP scheme (http/https) | http |
|
|
120
129
|
| TRINO_PASSWORD | Trino password | None |
|
|
121
130
|
|
|
122
|
-
## Resources
|
|
123
|
-
|
|
124
|
-
The server provides the following MCP resources:
|
|
125
|
-
|
|
126
|
-
### Catalog and Schema Navigation
|
|
127
|
-
|
|
128
|
-
- **catalog://main** (`list_catalogs`)
|
|
129
|
-
|
|
130
|
-
- Lists all available Trino catalogs
|
|
131
|
-
- No parameters required
|
|
132
|
-
|
|
133
|
-
- **schema://{catalog}** (`list_schemas`)
|
|
134
|
-
|
|
135
|
-
- Lists all schemas in the specified catalog
|
|
136
|
-
- Parameters:
|
|
137
|
-
- `catalog`: Catalog name (string, required)
|
|
138
|
-
|
|
139
|
-
- **table://{catalog}/{schema}** (`list_tables`)
|
|
140
|
-
- Lists all tables in the specified schema
|
|
141
|
-
- Parameters:
|
|
142
|
-
- `catalog`: Catalog name (string, required)
|
|
143
|
-
- `schema`: Schema name (string, required)
|
|
144
|
-
|
|
145
131
|
## Tools
|
|
146
132
|
|
|
147
133
|
### Query and Exploration Tools
|
|
@@ -6,6 +6,7 @@ functionality through resources and tools, with special support for Iceberg tabl
|
|
|
6
6
|
|
|
7
7
|
from mcp.server.fastmcp import FastMCP
|
|
8
8
|
from mcp.server.fastmcp.prompts import base
|
|
9
|
+
from pydantic import Field
|
|
9
10
|
|
|
10
11
|
from config import load_config
|
|
11
12
|
from trino_client import TrinoClient
|
|
@@ -13,38 +14,14 @@ from trino_client import TrinoClient
|
|
|
13
14
|
# Initialize the MCP server and Trino client
|
|
14
15
|
config = load_config()
|
|
15
16
|
client = TrinoClient(config)
|
|
16
|
-
mcp = FastMCP("Trino Explorer", dependencies=["trino", "python-dotenv", "loguru"])
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
# Initialize the MCP server with context
|
|
20
|
+
mcp = FastMCP(
|
|
21
|
+
name="Trino Explorer",
|
|
22
|
+
instructions="This Model Context Protocol (MCP) server provides access to Trino Query Engine.",
|
|
23
|
+
dependencies=["trino", "python-dotenv", "loguru"],
|
|
24
24
|
)
|
|
25
|
-
def list_catalogs() -> str:
|
|
26
|
-
"""List all available Trino catalogs."""
|
|
27
|
-
return client.list_catalogs()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@mcp.resource(
|
|
31
|
-
"schema://{catalog}",
|
|
32
|
-
name="list_schemas",
|
|
33
|
-
description="List all schemas in the specified catalog",
|
|
34
|
-
)
|
|
35
|
-
def list_schemas(catalog: str) -> str:
|
|
36
|
-
"""List all schemas in a catalog."""
|
|
37
|
-
return client.list_schemas(catalog)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@mcp.resource(
|
|
41
|
-
"table://{catalog}/{schema}",
|
|
42
|
-
name="list_tables",
|
|
43
|
-
description="List all tables in the specified schema",
|
|
44
|
-
)
|
|
45
|
-
def list_tables(catalog: str, schema: str) -> str:
|
|
46
|
-
"""List all tables in a schema."""
|
|
47
|
-
return client.list_tables(catalog, schema)
|
|
48
25
|
|
|
49
26
|
|
|
50
27
|
# Tools
|
|
@@ -55,7 +32,7 @@ def show_catalogs() -> str:
|
|
|
55
32
|
|
|
56
33
|
|
|
57
34
|
@mcp.tool(description="List all schemas in a catalog")
|
|
58
|
-
def show_schemas(catalog: str) -> str:
|
|
35
|
+
def show_schemas(catalog: str = Field(description="The name of the catalog")) -> str:
|
|
59
36
|
"""List all schemas in a catalog.
|
|
60
37
|
|
|
61
38
|
Args:
|
|
@@ -68,66 +45,81 @@ def show_schemas(catalog: str) -> str:
|
|
|
68
45
|
|
|
69
46
|
|
|
70
47
|
@mcp.tool(description="List all tables in a schema")
|
|
71
|
-
def show_tables(
|
|
48
|
+
def show_tables(
|
|
49
|
+
catalog: str = Field(description="The name of the catalog"),
|
|
50
|
+
schema_name: str = Field(description="The name of the schema"),
|
|
51
|
+
) -> str:
|
|
72
52
|
"""List all tables in a schema.
|
|
73
53
|
|
|
74
54
|
Args:
|
|
75
55
|
catalog: The name of the catalog
|
|
76
|
-
|
|
56
|
+
schema_name: The name of the schema
|
|
77
57
|
|
|
78
58
|
Returns:
|
|
79
59
|
str: List of tables in the specified schema
|
|
80
60
|
"""
|
|
81
|
-
return client.list_tables(catalog,
|
|
61
|
+
return client.list_tables(catalog, schema_name)
|
|
82
62
|
|
|
83
63
|
|
|
84
64
|
@mcp.tool(description="Describe a table")
|
|
85
|
-
def describe_table(
|
|
65
|
+
def describe_table(
|
|
66
|
+
catalog: str = Field(description="The catalog name"),
|
|
67
|
+
schema_name: str = Field(description="The schema name"),
|
|
68
|
+
table: str = Field(description="The name of the table"),
|
|
69
|
+
) -> str:
|
|
86
70
|
"""Describe a table.
|
|
87
71
|
|
|
88
72
|
Args:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
73
|
+
catalog (str): The catalog name
|
|
74
|
+
schema_name (str): The schema name
|
|
75
|
+
table (str): The name of the table
|
|
92
76
|
|
|
93
77
|
Returns:
|
|
94
78
|
str: Table description in JSON format
|
|
95
79
|
"""
|
|
96
|
-
return client.describe_table(
|
|
80
|
+
return client.describe_table(catalog, schema_name, table)
|
|
97
81
|
|
|
98
82
|
|
|
99
83
|
@mcp.tool(description="Show the CREATE TABLE statement for a specific table")
|
|
100
|
-
def show_create_table(
|
|
84
|
+
def show_create_table(
|
|
85
|
+
catalog: str = Field(description="catalog name "),
|
|
86
|
+
schema_name: str = Field(description="schema name "),
|
|
87
|
+
table: str = Field(description="The name of the table"),
|
|
88
|
+
) -> str:
|
|
101
89
|
"""Show the CREATE TABLE statement for a table.
|
|
102
90
|
|
|
103
91
|
Args:
|
|
92
|
+
catalog: catalog name
|
|
93
|
+
schema_name: schema name
|
|
104
94
|
table: The name of the table
|
|
105
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
106
|
-
schema: Optional schema name (defaults to configured schema)
|
|
107
95
|
|
|
108
96
|
Returns:
|
|
109
97
|
str: The CREATE TABLE statement
|
|
110
98
|
"""
|
|
111
|
-
return client.show_create_table(
|
|
99
|
+
return client.show_create_table(catalog, schema_name, table)
|
|
112
100
|
|
|
113
101
|
|
|
114
102
|
@mcp.tool(description="Show the CREATE VIEW statement for a specific view")
|
|
115
|
-
def show_create_view(
|
|
103
|
+
def show_create_view(
|
|
104
|
+
catalog: str = Field(description="catalog name "),
|
|
105
|
+
schema_name: str = Field(description="schema name "),
|
|
106
|
+
view: str = Field(description="The name of the view"),
|
|
107
|
+
) -> str:
|
|
116
108
|
"""Show the CREATE VIEW statement for a view.
|
|
117
109
|
|
|
118
110
|
Args:
|
|
111
|
+
catalog: catalog name
|
|
112
|
+
schema_name: schema name
|
|
119
113
|
view: The name of the view
|
|
120
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
121
|
-
schema: Optional schema name (defaults to configured schema)
|
|
122
114
|
|
|
123
115
|
Returns:
|
|
124
116
|
str: The CREATE VIEW statement
|
|
125
117
|
"""
|
|
126
|
-
return client.show_create_view(
|
|
118
|
+
return client.show_create_view(catalog, schema_name, view)
|
|
127
119
|
|
|
128
120
|
|
|
129
121
|
@mcp.tool(description="Execute a SQL query and return results in a readable format")
|
|
130
|
-
def execute_query(query: str) -> str:
|
|
122
|
+
def execute_query(query: str = Field(description="The SQL query to execute")) -> str:
|
|
131
123
|
"""Execute a SQL query and return formatted results.
|
|
132
124
|
|
|
133
125
|
Args:
|
|
@@ -140,77 +132,93 @@ def execute_query(query: str) -> str:
|
|
|
140
132
|
|
|
141
133
|
|
|
142
134
|
@mcp.tool(description="Optimize an Iceberg table's data files")
|
|
143
|
-
def optimize(
|
|
135
|
+
def optimize(
|
|
136
|
+
catalog: str = Field(description="catalog name "),
|
|
137
|
+
schema_name: str = Field(description="schema name "),
|
|
138
|
+
table: str = Field(description="The name of the table to optimize"),
|
|
139
|
+
) -> str:
|
|
144
140
|
"""Optimize an Iceberg table by compacting small files.
|
|
145
141
|
|
|
146
142
|
Args:
|
|
143
|
+
catalog: catalog name
|
|
144
|
+
schema_name: schema name
|
|
147
145
|
table: The name of the table to optimize
|
|
148
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
149
|
-
schema: Optional schema name (defaults to configured schema)
|
|
150
146
|
|
|
151
147
|
Returns:
|
|
152
148
|
str: Confirmation message
|
|
153
149
|
"""
|
|
154
|
-
return client.optimize(
|
|
150
|
+
return client.optimize(catalog, schema_name, table)
|
|
155
151
|
|
|
156
152
|
|
|
157
153
|
@mcp.tool(description="Optimize manifest files for an Iceberg table")
|
|
158
|
-
def optimize_manifests(
|
|
154
|
+
def optimize_manifests(
|
|
155
|
+
catalog: str = Field(description="catalog name "),
|
|
156
|
+
schema_name: str = Field(description="schema name "),
|
|
157
|
+
table: str = Field(description="The name of the table"),
|
|
158
|
+
) -> str:
|
|
159
159
|
"""Optimize manifest files for an Iceberg table.
|
|
160
160
|
|
|
161
161
|
Args:
|
|
162
|
+
catalog: catalog name
|
|
163
|
+
schema_name: schema name
|
|
162
164
|
table: The name of the table
|
|
163
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
164
|
-
schema: Optional schema name (defaults to configured schema)
|
|
165
165
|
|
|
166
166
|
Returns:
|
|
167
167
|
str: Confirmation message
|
|
168
168
|
"""
|
|
169
|
-
return client.optimize_manifests(
|
|
169
|
+
return client.optimize_manifests(catalog, schema_name, table)
|
|
170
170
|
|
|
171
171
|
|
|
172
172
|
@mcp.tool(description="Remove old snapshots from an Iceberg table")
|
|
173
173
|
def expire_snapshots(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
catalog: str = Field(description="catalog name "),
|
|
175
|
+
schema_name: str = Field(description="schema name "),
|
|
176
|
+
retention_threshold: str = Field(
|
|
177
|
+
description="Age threshold for snapshot removal (e.g., '7d', '30d')", default="7d"
|
|
178
|
+
),
|
|
179
|
+
table: str = Field(description="The name of the table"),
|
|
178
180
|
) -> str:
|
|
179
181
|
"""Remove old snapshots from an Iceberg table.
|
|
180
182
|
|
|
181
183
|
Args:
|
|
184
|
+
catalog: catalog name
|
|
185
|
+
schema_name: schema name
|
|
182
186
|
table: The name of the table
|
|
183
187
|
retention_threshold: Age threshold for snapshot removal (e.g., "7d", "30d")
|
|
184
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
185
|
-
schema: Optional schema name (defaults to configured schema)
|
|
186
188
|
|
|
187
189
|
Returns:
|
|
188
190
|
str: Confirmation message
|
|
189
191
|
"""
|
|
190
|
-
return client.expire_snapshots(
|
|
192
|
+
return client.expire_snapshots(catalog, schema_name, table, retention_threshold)
|
|
191
193
|
|
|
192
194
|
|
|
193
195
|
@mcp.tool(description="Show statistics for a table")
|
|
194
|
-
def show_stats(
|
|
196
|
+
def show_stats(
|
|
197
|
+
catalog: str = Field(description="catalog name "),
|
|
198
|
+
schema_name: str = Field(description="schema name "),
|
|
199
|
+
table: str = Field(description="The name of the table"),
|
|
200
|
+
) -> str:
|
|
195
201
|
"""Show statistics for a table.
|
|
196
202
|
|
|
197
203
|
Args:
|
|
204
|
+
catalog: catalog name
|
|
205
|
+
schema_name: schema name
|
|
198
206
|
table: The name of the table
|
|
199
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
200
|
-
schema: Optional schema name (defaults to configured schema)
|
|
201
207
|
|
|
202
208
|
Returns:
|
|
203
209
|
str: Table statistics in JSON format
|
|
204
210
|
"""
|
|
205
|
-
return client.show_stats(
|
|
211
|
+
return client.show_stats(catalog, schema_name, table)
|
|
206
212
|
|
|
207
213
|
|
|
208
214
|
@mcp.tool(name="show_query_history", description="Get the history of executed queries")
|
|
209
|
-
def show_query_history(
|
|
215
|
+
def show_query_history(
|
|
216
|
+
limit: int = Field(description="maximum number of history entries to return", default=None),
|
|
217
|
+
) -> str:
|
|
210
218
|
"""Get the history of executed queries.
|
|
211
219
|
|
|
212
220
|
Args:
|
|
213
|
-
limit:
|
|
221
|
+
limit: maximum number of history entries to return.
|
|
214
222
|
If None, returns all entries.
|
|
215
223
|
|
|
216
224
|
Returns:
|
|
@@ -230,22 +238,30 @@ def show_catalog_tree() -> str:
|
|
|
230
238
|
|
|
231
239
|
|
|
232
240
|
@mcp.tool(description="Show Iceberg table properties")
|
|
233
|
-
def show_table_properties(
|
|
241
|
+
def show_table_properties(
|
|
242
|
+
catalog: str = Field(description="catalog name "),
|
|
243
|
+
schema_name: str = Field(description="schema name "),
|
|
244
|
+
table: str = Field(description="The name of the table"),
|
|
245
|
+
) -> str:
|
|
234
246
|
"""Show Iceberg table properties.
|
|
235
247
|
|
|
236
248
|
Args:
|
|
249
|
+
catalog: catalog name
|
|
250
|
+
schema_name: schema name
|
|
237
251
|
table: The name of the table
|
|
238
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
239
|
-
schema: Optional schema name (defaults to configured schema)
|
|
240
252
|
|
|
241
253
|
Returns:
|
|
242
254
|
str: JSON-formatted table properties
|
|
243
255
|
"""
|
|
244
|
-
return client.show_table_properties(
|
|
256
|
+
return client.show_table_properties(catalog, schema_name, table)
|
|
245
257
|
|
|
246
258
|
|
|
247
259
|
@mcp.tool(description="Show Iceberg table history/changelog")
|
|
248
|
-
def show_table_history(
|
|
260
|
+
def show_table_history(
|
|
261
|
+
catalog: str = Field(description="catalog name "),
|
|
262
|
+
schema_name: str = Field(description="schema name "),
|
|
263
|
+
table: str = Field(description="The name of the table"),
|
|
264
|
+
) -> str:
|
|
249
265
|
"""Show Iceberg table history/changelog.
|
|
250
266
|
|
|
251
267
|
The history contains:
|
|
@@ -255,18 +271,22 @@ def show_table_history(table: str, catalog: str | None = None, schema: str | Non
|
|
|
255
271
|
- is_current_ancestor: Whether snapshot is an ancestor of current
|
|
256
272
|
|
|
257
273
|
Args:
|
|
274
|
+
catalog: catalog name
|
|
275
|
+
schema_name: schema name
|
|
258
276
|
table: The name of the table
|
|
259
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
260
|
-
schema: Optional schema name (defaults to configured schema)
|
|
261
277
|
|
|
262
278
|
Returns:
|
|
263
279
|
str: JSON-formatted table history
|
|
264
280
|
"""
|
|
265
|
-
return client.show_table_history(
|
|
281
|
+
return client.show_table_history(catalog, schema_name, table)
|
|
266
282
|
|
|
267
283
|
|
|
268
|
-
@mcp.tool(description="Show
|
|
269
|
-
def show_metadata_log_entries(
|
|
284
|
+
@mcp.tool(description="Show metadata for the table")
|
|
285
|
+
def show_metadata_log_entries(
|
|
286
|
+
catalog: str = Field(description="catalog name "),
|
|
287
|
+
schema_name: str = Field(description="schema name "),
|
|
288
|
+
table: str = Field(description="The name of the table"),
|
|
289
|
+
) -> str:
|
|
270
290
|
"""Show Iceberg table metadata log entries.
|
|
271
291
|
|
|
272
292
|
The metadata log contains:
|
|
@@ -277,18 +297,22 @@ def show_metadata_log_entries(table: str, catalog: str | None = None, schema: st
|
|
|
277
297
|
- latest_sequence_number: Data sequence number of metadata file
|
|
278
298
|
|
|
279
299
|
Args:
|
|
300
|
+
catalog: catalog name
|
|
301
|
+
schema_name: schema name
|
|
280
302
|
table: The name of the table
|
|
281
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
282
|
-
schema: Optional schema name (defaults to configured schema)
|
|
283
303
|
|
|
284
304
|
Returns:
|
|
285
305
|
str: JSON-formatted metadata log entries
|
|
286
306
|
"""
|
|
287
|
-
return client.show_metadata_log_entries(
|
|
307
|
+
return client.show_metadata_log_entries(catalog, schema_name, table)
|
|
288
308
|
|
|
289
309
|
|
|
290
310
|
@mcp.tool(description="Show Iceberg table snapshots")
|
|
291
|
-
def show_snapshots(
|
|
311
|
+
def show_snapshots(
|
|
312
|
+
catalog: str = Field(description="catalog name "),
|
|
313
|
+
schema_name: str = Field(description="schema name "),
|
|
314
|
+
table: str = Field(description="The name of the table"),
|
|
315
|
+
) -> str:
|
|
292
316
|
"""Show Iceberg table snapshots.
|
|
293
317
|
|
|
294
318
|
The snapshots table contains:
|
|
@@ -300,19 +324,22 @@ def show_snapshots(table: str, catalog: str | None = None, schema: str | None =
|
|
|
300
324
|
- summary: Summary of changes from previous snapshot
|
|
301
325
|
|
|
302
326
|
Args:
|
|
327
|
+
catalog: catalog name
|
|
328
|
+
schema_name: schema name
|
|
303
329
|
table: The name of the table
|
|
304
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
305
|
-
schema: Optional schema name (defaults to configured schema)
|
|
306
330
|
|
|
307
331
|
Returns:
|
|
308
332
|
str: JSON-formatted table snapshots
|
|
309
333
|
"""
|
|
310
|
-
return client.show_snapshots(
|
|
334
|
+
return client.show_snapshots(catalog, schema_name, table)
|
|
311
335
|
|
|
312
336
|
|
|
313
337
|
@mcp.tool(description="Show Iceberg table manifests")
|
|
314
338
|
def show_manifests(
|
|
315
|
-
|
|
339
|
+
catalog: str = Field(description="catalog name"),
|
|
340
|
+
schema_name: str = Field(description="schema name"),
|
|
341
|
+
table: str = Field(description="The name of the table"),
|
|
342
|
+
all_snapshots: bool = False,
|
|
316
343
|
) -> str:
|
|
317
344
|
"""Show Iceberg table manifests for current or all snapshots.
|
|
318
345
|
|
|
@@ -330,19 +357,23 @@ def show_manifests(
|
|
|
330
357
|
- partition_summaries: Partition range metadata
|
|
331
358
|
|
|
332
359
|
Args:
|
|
360
|
+
catalog: catalog name
|
|
361
|
+
schema_name: schema name
|
|
333
362
|
table: The name of the table
|
|
334
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
335
|
-
schema: Optional schema name (defaults to configured schema)
|
|
336
363
|
all_snapshots: If True, show manifests from all snapshots
|
|
337
364
|
|
|
338
365
|
Returns:
|
|
339
366
|
str: JSON-formatted table manifests
|
|
340
367
|
"""
|
|
341
|
-
return client.show_manifests(
|
|
368
|
+
return client.show_manifests(catalog, schema_name, table, all_snapshots)
|
|
342
369
|
|
|
343
370
|
|
|
344
371
|
@mcp.tool(description="Show Iceberg table partitions")
|
|
345
|
-
def show_partitions(
|
|
372
|
+
def show_partitions(
|
|
373
|
+
catalog: str = Field(description="catalog name "),
|
|
374
|
+
schema_name: str = Field(description="schema name "),
|
|
375
|
+
table: str = Field(description="The name of the table"),
|
|
376
|
+
) -> str:
|
|
346
377
|
"""Show Iceberg table partitions.
|
|
347
378
|
|
|
348
379
|
The partitions table contains:
|
|
@@ -353,18 +384,22 @@ def show_partitions(table: str, catalog: str | None = None, schema: str | None =
|
|
|
353
384
|
- data: Partition range metadata with min/max values and null/nan counts
|
|
354
385
|
|
|
355
386
|
Args:
|
|
387
|
+
catalog: catalog name
|
|
388
|
+
schema_name: schema name
|
|
356
389
|
table: The name of the table
|
|
357
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
358
|
-
schema: Optional schema name (defaults to configured schema)
|
|
359
390
|
|
|
360
391
|
Returns:
|
|
361
392
|
str: JSON-formatted table partitions
|
|
362
393
|
"""
|
|
363
|
-
return client.show_partitions(
|
|
394
|
+
return client.show_partitions(catalog, schema_name, table)
|
|
364
395
|
|
|
365
396
|
|
|
366
397
|
@mcp.tool(description="Show Iceberg table data files")
|
|
367
|
-
def show_files(
|
|
398
|
+
def show_files(
|
|
399
|
+
catalog: str = Field(description="catalog name "),
|
|
400
|
+
schema_name: str = Field(description="schema name "),
|
|
401
|
+
table: str = Field(description="The name of the table"),
|
|
402
|
+
) -> str:
|
|
368
403
|
"""Show Iceberg table data files in current snapshot.
|
|
369
404
|
|
|
370
405
|
The files table contains:
|
|
@@ -384,18 +419,23 @@ def show_files(table: str, catalog: str | None = None, schema: str | None = None
|
|
|
384
419
|
- equality_ids: Field IDs for equality deletes
|
|
385
420
|
|
|
386
421
|
Args:
|
|
422
|
+
catalog: catalog name
|
|
423
|
+
schema_name: schema name
|
|
387
424
|
table: The name of the table
|
|
388
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
389
|
-
schema: Optional schema name (defaults to configured schema)
|
|
390
425
|
|
|
391
426
|
Returns:
|
|
392
427
|
str: JSON-formatted table files info
|
|
393
428
|
"""
|
|
394
|
-
return client.show_files(
|
|
429
|
+
return client.show_files(catalog, schema_name, table)
|
|
395
430
|
|
|
396
431
|
|
|
397
432
|
@mcp.tool(description="Show Iceberg table manifest entries")
|
|
398
|
-
def show_entries(
|
|
433
|
+
def show_entries(
|
|
434
|
+
catalog: str = Field(description="catalog name "),
|
|
435
|
+
schema_name: str = Field(description="schema name "),
|
|
436
|
+
table: str = Field(description="The name of the table"),
|
|
437
|
+
all_snapshots: bool = False,
|
|
438
|
+
) -> str:
|
|
399
439
|
"""Show Iceberg table manifest entries for current or all snapshots.
|
|
400
440
|
|
|
401
441
|
The entries table contains:
|
|
@@ -407,19 +447,23 @@ def show_entries(table: str, catalog: str | None = None, schema: str | None = No
|
|
|
407
447
|
- readable_metrics: Human-readable file metrics
|
|
408
448
|
|
|
409
449
|
Args:
|
|
450
|
+
catalog: catalog name
|
|
451
|
+
schema_name: schema name
|
|
410
452
|
table: The name of the table
|
|
411
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
412
|
-
schema: Optional schema name (defaults to configured schema)
|
|
413
453
|
all_snapshots: If True, show entries from all snapshots
|
|
414
454
|
|
|
415
455
|
Returns:
|
|
416
456
|
str: JSON-formatted manifest entries
|
|
417
457
|
"""
|
|
418
|
-
return client.show_entries(
|
|
458
|
+
return client.show_entries(catalog, schema_name, table, all_snapshots)
|
|
419
459
|
|
|
420
460
|
|
|
421
461
|
@mcp.tool(description="Show Iceberg table references (branches and tags)")
|
|
422
|
-
def show_refs(
|
|
462
|
+
def show_refs(
|
|
463
|
+
catalog: str = Field(description="catalog name "),
|
|
464
|
+
schema_name: str = Field(description="schema name "),
|
|
465
|
+
table: str = Field(description="The name of the table"),
|
|
466
|
+
) -> str:
|
|
423
467
|
"""Show Iceberg table references (branches and tags).
|
|
424
468
|
|
|
425
469
|
The refs table contains:
|
|
@@ -431,20 +475,28 @@ def show_refs(table: str, catalog: str | None = None, schema: str | None = None)
|
|
|
431
475
|
- max_snapshot_age_in_ms: Max snapshot age in branch
|
|
432
476
|
|
|
433
477
|
Args:
|
|
478
|
+
catalog: catalog name
|
|
479
|
+
schema_name: schema name
|
|
434
480
|
table: The name of the table
|
|
435
|
-
catalog: Optional catalog name (defaults to configured catalog)
|
|
436
|
-
schema: Optional schema name (defaults to configured schema)
|
|
437
481
|
|
|
438
482
|
Returns:
|
|
439
483
|
str: JSON-formatted table references
|
|
440
484
|
"""
|
|
441
|
-
return client.show_refs(
|
|
485
|
+
return client.show_refs(catalog, schema_name, table)
|
|
442
486
|
|
|
443
487
|
|
|
444
488
|
# Prompts
|
|
445
489
|
@mcp.prompt()
|
|
446
|
-
def explore_data(catalog: str
|
|
447
|
-
"""Interactive prompt to explore Trino data.
|
|
490
|
+
def explore_data(catalog: str, schema_name: str) -> list[base.Message]:
|
|
491
|
+
"""Interactive prompt to explore Trino data.
|
|
492
|
+
|
|
493
|
+
Args:
|
|
494
|
+
catalog: The name of the catalog to explore
|
|
495
|
+
schema_name: The name of the schema to explore
|
|
496
|
+
|
|
497
|
+
Returns:
|
|
498
|
+
list[base.Message]: A list of system and user messages to guide the conversation
|
|
499
|
+
"""
|
|
448
500
|
messages = [
|
|
449
501
|
base.SystemMessage(
|
|
450
502
|
"I'll help you explore data in Trino. I can show you available catalogs, "
|
|
@@ -452,10 +504,10 @@ def explore_data(catalog: str | None = None, schema: str | None = None) -> list[
|
|
|
452
504
|
)
|
|
453
505
|
]
|
|
454
506
|
|
|
455
|
-
if catalog and
|
|
507
|
+
if catalog and schema_name:
|
|
456
508
|
messages.append(
|
|
457
509
|
base.UserMessage(
|
|
458
|
-
f"Show me what tables are available in the {catalog}.{
|
|
510
|
+
f"Show me what tables are available in the {catalog}.{schema_name} schema and help me query them."
|
|
459
511
|
)
|
|
460
512
|
)
|
|
461
513
|
elif catalog:
|
|
@@ -467,7 +519,7 @@ def explore_data(catalog: str | None = None, schema: str | None = None) -> list[
|
|
|
467
519
|
|
|
468
520
|
|
|
469
521
|
@mcp.prompt()
|
|
470
|
-
def maintain_iceberg(table: str, catalog: str
|
|
522
|
+
def maintain_iceberg(table: str, catalog: str, schema_name: str) -> list[base.Message]:
|
|
471
523
|
"""Interactive prompt for Iceberg table maintenance."""
|
|
472
524
|
return [
|
|
473
525
|
base.SystemMessage(
|
|
@@ -476,7 +528,7 @@ def maintain_iceberg(table: str, catalog: str | None = None, schema: str | None
|
|
|
476
528
|
),
|
|
477
529
|
base.UserMessage(
|
|
478
530
|
f"What maintenance operations should we perform on the Iceberg table "
|
|
479
|
-
f"{catalog + '.' if catalog else ''}{
|
|
531
|
+
f"{catalog + '.' if catalog else ''}{schema_name + '.' if schema_name else ''}{table}?"
|
|
480
532
|
),
|
|
481
533
|
]
|
|
482
534
|
|
|
@@ -485,4 +537,4 @@ if __name__ == "__main__":
|
|
|
485
537
|
from loguru import logger
|
|
486
538
|
|
|
487
539
|
logger.info("Starting Trino MCP server...")
|
|
488
|
-
mcp.run()
|
|
540
|
+
mcp.run(transport="stdio")
|
|
@@ -69,11 +69,12 @@ class TrinoClient:
|
|
|
69
69
|
|
|
70
70
|
Args:
|
|
71
71
|
query (str): The SQL query to execute.
|
|
72
|
+
params (Optional[dict]): Dictionary of query parameters with primitive types.
|
|
72
73
|
|
|
73
74
|
Returns:
|
|
74
75
|
str: JSON-formatted string containing query results or success message.
|
|
75
76
|
"""
|
|
76
|
-
cur = self.client.cursor()
|
|
77
|
+
cur: trino.dbapi.Cursor = self.client.cursor()
|
|
77
78
|
cur.execute(query)
|
|
78
79
|
if cur.description:
|
|
79
80
|
return json.dumps(
|
|
@@ -82,7 +83,7 @@ class TrinoClient:
|
|
|
82
83
|
)
|
|
83
84
|
return "Query executed successfully (no results to display)"
|
|
84
85
|
|
|
85
|
-
def get_query_history(self, limit: int
|
|
86
|
+
def get_query_history(self, limit: int) -> str:
|
|
86
87
|
"""Retrieve the history of executed queries.
|
|
87
88
|
|
|
88
89
|
Args:
|
|
@@ -105,7 +106,7 @@ class TrinoClient:
|
|
|
105
106
|
catalogs = [row["Catalog"] for row in json.loads(self.execute_query("SHOW CATALOGS"))]
|
|
106
107
|
return "\n".join(catalogs)
|
|
107
108
|
|
|
108
|
-
def list_schemas(self, catalog: str
|
|
109
|
+
def list_schemas(self, catalog: str) -> str:
|
|
109
110
|
"""List all schemas in a catalog.
|
|
110
111
|
|
|
111
112
|
Args:
|
|
@@ -125,7 +126,7 @@ class TrinoClient:
|
|
|
125
126
|
schemas = [row["Schema"] for row in json.loads(self.execute_query(query))]
|
|
126
127
|
return "\n".join(schemas)
|
|
127
128
|
|
|
128
|
-
def list_tables(self, catalog: str
|
|
129
|
+
def list_tables(self, catalog: str, schema: str) -> str:
|
|
129
130
|
"""List all tables in a schema.
|
|
130
131
|
|
|
131
132
|
Args:
|
|
@@ -147,13 +148,13 @@ class TrinoClient:
|
|
|
147
148
|
tables = [row["Table"] for row in json.loads(self.execute_query(query))]
|
|
148
149
|
return "\n".join(tables)
|
|
149
150
|
|
|
150
|
-
def describe_table(self,
|
|
151
|
+
def describe_table(self, catalog: str, schema: str, table: str) -> str:
|
|
151
152
|
"""Describe the structure of a table.
|
|
152
153
|
|
|
153
154
|
Args:
|
|
155
|
+
catalog (str): The catalog name. If None, uses configured default.
|
|
156
|
+
schema (str): The schema name. If None, uses configured default.
|
|
154
157
|
table (str): The name of the table.
|
|
155
|
-
catalog (Optional[str]): The catalog name. If None, uses configured default.
|
|
156
|
-
schema (Optional[str]): The schema name. If None, uses configured default.
|
|
157
158
|
|
|
158
159
|
Returns:
|
|
159
160
|
str: JSON-formatted string containing table description.
|
|
@@ -164,17 +165,17 @@ class TrinoClient:
|
|
|
164
165
|
catalog = catalog or self.config.catalog
|
|
165
166
|
schema = schema or self.config.schema
|
|
166
167
|
if not catalog or not schema:
|
|
167
|
-
raise CatalogSchemaError
|
|
168
|
+
raise CatalogSchemaError
|
|
168
169
|
query = f"DESCRIBE {catalog}.{schema}.{table}"
|
|
169
170
|
return self.execute_query(query)
|
|
170
171
|
|
|
171
|
-
def show_create_table(self,
|
|
172
|
+
def show_create_table(self, catalog: str, schema: str, table: str) -> str:
|
|
172
173
|
"""Show the CREATE TABLE statement for a table.
|
|
173
174
|
|
|
174
175
|
Args:
|
|
176
|
+
schema (str): The schema name. If None, uses configured default.
|
|
177
|
+
catalog (str): The catalog name. If None, uses configured default.
|
|
175
178
|
table (str): The name of the table.
|
|
176
|
-
catalog (Optional[str]): The catalog name. If None, uses configured default.
|
|
177
|
-
schema (Optional[str]): The schema name. If None, uses configured default.
|
|
178
179
|
|
|
179
180
|
Returns:
|
|
180
181
|
str: The CREATE TABLE statement for the specified table.
|
|
@@ -185,18 +186,23 @@ class TrinoClient:
|
|
|
185
186
|
catalog = catalog or self.config.catalog
|
|
186
187
|
schema = schema or self.config.schema
|
|
187
188
|
if not catalog or not schema:
|
|
188
|
-
raise CatalogSchemaError
|
|
189
|
+
raise CatalogSchemaError
|
|
189
190
|
query = f"SHOW CREATE TABLE {catalog}.{schema}.{table}"
|
|
190
191
|
result = json.loads(self.execute_query(query))
|
|
191
192
|
return result[0]["Create Table"] if result else ""
|
|
192
193
|
|
|
193
|
-
def show_create_view(
|
|
194
|
+
def show_create_view(
|
|
195
|
+
self,
|
|
196
|
+
catalog: str,
|
|
197
|
+
schema: str,
|
|
198
|
+
view: str,
|
|
199
|
+
) -> str:
|
|
194
200
|
"""Show the CREATE VIEW statement for a view.
|
|
195
201
|
|
|
196
202
|
Args:
|
|
203
|
+
catalog (str): The catalog name. If None, uses configured default.
|
|
204
|
+
schema (str): The schema name. If None, uses configured default.
|
|
197
205
|
view (str): The name of the view.
|
|
198
|
-
catalog (Optional[str]): The catalog name. If None, uses configured default.
|
|
199
|
-
schema (Optional[str]): The schema name. If None, uses configured default.
|
|
200
206
|
|
|
201
207
|
Returns:
|
|
202
208
|
str: The CREATE VIEW statement for the specified view.
|
|
@@ -207,18 +213,18 @@ class TrinoClient:
|
|
|
207
213
|
catalog = catalog or self.config.catalog
|
|
208
214
|
schema = schema or self.config.schema
|
|
209
215
|
if not catalog or not schema:
|
|
210
|
-
raise CatalogSchemaError
|
|
216
|
+
raise CatalogSchemaError
|
|
211
217
|
query = f"SHOW CREATE VIEW {catalog}.{schema}.{view}"
|
|
212
218
|
result = json.loads(self.execute_query(query))
|
|
213
219
|
return result[0]["Create View"] if result else ""
|
|
214
220
|
|
|
215
|
-
def show_stats(self,
|
|
221
|
+
def show_stats(self, catalog: str, schema: str, table: str) -> str:
|
|
216
222
|
"""Show statistics for a table.
|
|
217
223
|
|
|
218
224
|
Args:
|
|
225
|
+
catalog (str): The catalog name. If None, uses configured default.
|
|
226
|
+
schema (str): The schema name. If None, uses configured default.
|
|
219
227
|
table (str): The name of the table.
|
|
220
|
-
catalog (Optional[str]): The catalog name. If None, uses configured default.
|
|
221
|
-
schema (Optional[str]): The schema name. If None, uses configured default.
|
|
222
228
|
|
|
223
229
|
Returns:
|
|
224
230
|
str: JSON-formatted string containing table statistics.
|
|
@@ -229,17 +235,17 @@ class TrinoClient:
|
|
|
229
235
|
catalog = catalog or self.config.catalog
|
|
230
236
|
schema = schema or self.config.schema
|
|
231
237
|
if not catalog or not schema:
|
|
232
|
-
raise CatalogSchemaError
|
|
238
|
+
raise CatalogSchemaError
|
|
233
239
|
query = f"SHOW STATS FOR {catalog}.{schema}.{table}"
|
|
234
240
|
return self.execute_query(query)
|
|
235
241
|
|
|
236
|
-
def optimize(self,
|
|
242
|
+
def optimize(self, catalog: str, schema: str, table: str) -> str:
|
|
237
243
|
"""Optimize an Iceberg table by compacting small files.
|
|
238
244
|
|
|
239
245
|
Args:
|
|
246
|
+
catalog (str): The catalog name. If None, uses configured default.
|
|
247
|
+
schema (str): The schema name. If None, uses configured default.
|
|
240
248
|
table (str): The name of the table to optimize.
|
|
241
|
-
catalog (Optional[str]): The catalog name. If None, uses configured default.
|
|
242
|
-
schema (Optional[str]): The schema name. If None, uses configured default.
|
|
243
249
|
|
|
244
250
|
Returns:
|
|
245
251
|
str: Success message indicating the table was optimized.
|
|
@@ -250,12 +256,12 @@ class TrinoClient:
|
|
|
250
256
|
catalog = catalog or self.config.catalog
|
|
251
257
|
schema = schema or self.config.schema
|
|
252
258
|
if not catalog or not schema:
|
|
253
|
-
raise CatalogSchemaError
|
|
259
|
+
raise CatalogSchemaError
|
|
254
260
|
query = f"ALTER TABLE {catalog}.{schema}.{table} EXECUTE optimize"
|
|
255
261
|
self.execute_query(query)
|
|
256
262
|
return f"Table {catalog}.{schema}.{table} optimized successfully"
|
|
257
263
|
|
|
258
|
-
def optimize_manifests(self, table: str, catalog: str
|
|
264
|
+
def optimize_manifests(self, table: str, catalog: str, schema: str) -> str:
|
|
259
265
|
"""Optimize manifest files for an Iceberg table.
|
|
260
266
|
|
|
261
267
|
This operation reorganizes and compacts the table's manifest files for improved
|
|
@@ -275,17 +281,17 @@ class TrinoClient:
|
|
|
275
281
|
catalog = catalog or self.config.catalog
|
|
276
282
|
schema = schema or self.config.schema
|
|
277
283
|
if not catalog or not schema:
|
|
278
|
-
raise CatalogSchemaError
|
|
284
|
+
raise CatalogSchemaError
|
|
279
285
|
query = f"ALTER TABLE {catalog}.{schema}.{table} EXECUTE optimize_manifests"
|
|
280
286
|
self.execute_query(query)
|
|
281
287
|
return f"Manifests for table {catalog}.{schema}.{table} optimized successfully"
|
|
282
288
|
|
|
283
289
|
def expire_snapshots(
|
|
284
290
|
self,
|
|
291
|
+
catalog: str,
|
|
285
292
|
table: str,
|
|
293
|
+
schema: str,
|
|
286
294
|
retention_threshold: str = "7d",
|
|
287
|
-
catalog: str | None = None,
|
|
288
|
-
schema: str | None = None,
|
|
289
295
|
) -> str:
|
|
290
296
|
"""Remove old snapshots from an Iceberg table.
|
|
291
297
|
|
|
@@ -342,7 +348,7 @@ class TrinoClient:
|
|
|
342
348
|
tree.append("Unable to list schemas")
|
|
343
349
|
return "\n".join(tree) if tree else "No catalogs found"
|
|
344
350
|
|
|
345
|
-
def show_table_properties(self, table: str, catalog: str
|
|
351
|
+
def show_table_properties(self, table: str, catalog: str, schema: str) -> str:
|
|
346
352
|
"""Show Iceberg table properties.
|
|
347
353
|
|
|
348
354
|
Args:
|
|
@@ -356,11 +362,12 @@ class TrinoClient:
|
|
|
356
362
|
catalog = catalog or self.config.catalog
|
|
357
363
|
schema = schema or self.config.schema
|
|
358
364
|
if not catalog or not schema:
|
|
359
|
-
raise CatalogSchemaError
|
|
360
|
-
query =
|
|
361
|
-
|
|
365
|
+
raise CatalogSchemaError
|
|
366
|
+
query = 'SELECT * FROM "{}$properties"'
|
|
367
|
+
table_identifier = f"{catalog}.{schema}.{table}"
|
|
368
|
+
return self.execute_query(query.format(table_identifier))
|
|
362
369
|
|
|
363
|
-
def show_table_history(self, table: str, catalog: str
|
|
370
|
+
def show_table_history(self, table: str, catalog: str, schema: str) -> str:
|
|
364
371
|
"""Show Iceberg table history/changelog.
|
|
365
372
|
|
|
366
373
|
The history contains:
|
|
@@ -380,11 +387,12 @@ class TrinoClient:
|
|
|
380
387
|
catalog = catalog or self.config.catalog
|
|
381
388
|
schema = schema or self.config.schema
|
|
382
389
|
if not catalog or not schema:
|
|
383
|
-
raise CatalogSchemaError
|
|
384
|
-
|
|
385
|
-
|
|
390
|
+
raise CatalogSchemaError
|
|
391
|
+
table_identifier = f"{catalog}.{schema}.{table}"
|
|
392
|
+
query = 'SELECT * FROM "{}$history"'
|
|
393
|
+
return self.execute_query(query.format(table_identifier))
|
|
386
394
|
|
|
387
|
-
def show_metadata_log_entries(self, table: str, catalog: str
|
|
395
|
+
def show_metadata_log_entries(self, table: str, catalog: str, schema: str) -> str:
|
|
388
396
|
"""Show Iceberg table metadata log entries.
|
|
389
397
|
|
|
390
398
|
The metadata log contains:
|
|
@@ -405,11 +413,12 @@ class TrinoClient:
|
|
|
405
413
|
catalog = catalog or self.config.catalog
|
|
406
414
|
schema = schema or self.config.schema
|
|
407
415
|
if not catalog or not schema:
|
|
408
|
-
raise CatalogSchemaError
|
|
409
|
-
query =
|
|
410
|
-
|
|
416
|
+
raise CatalogSchemaError
|
|
417
|
+
query = 'SELECT * FROM "{}$metadata_log_entries"'
|
|
418
|
+
table_identifier = f"{catalog}.{schema}.{table}"
|
|
419
|
+
return self.execute_query(query.format(table_identifier))
|
|
411
420
|
|
|
412
|
-
def show_snapshots(self, table: str, catalog: str
|
|
421
|
+
def show_snapshots(self, table: str, catalog: str, schema: str) -> str:
|
|
413
422
|
"""Show Iceberg table snapshots.
|
|
414
423
|
|
|
415
424
|
The snapshots table contains:
|
|
@@ -431,13 +440,12 @@ class TrinoClient:
|
|
|
431
440
|
catalog = catalog or self.config.catalog
|
|
432
441
|
schema = schema or self.config.schema
|
|
433
442
|
if not catalog or not schema:
|
|
434
|
-
raise CatalogSchemaError
|
|
435
|
-
|
|
436
|
-
|
|
443
|
+
raise CatalogSchemaError
|
|
444
|
+
table_identifier = f"{catalog}.{schema}.{table}$snapshots"
|
|
445
|
+
query = 'SELECT * FROM "{}"'
|
|
446
|
+
return self.execute_query(query.format(table_identifier))
|
|
437
447
|
|
|
438
|
-
def show_manifests(
|
|
439
|
-
self, table: str, catalog: str | None = None, schema: str | None = None, all_snapshots: bool = False
|
|
440
|
-
) -> str:
|
|
448
|
+
def show_manifests(self, table: str, catalog: str, schema: str, all_snapshots: bool = False) -> str:
|
|
441
449
|
"""Show Iceberg table manifests for current or all snapshots.
|
|
442
450
|
|
|
443
451
|
The manifests table contains:
|
|
@@ -465,12 +473,13 @@ class TrinoClient:
|
|
|
465
473
|
catalog = catalog or self.config.catalog
|
|
466
474
|
schema = schema or self.config.schema
|
|
467
475
|
if not catalog or not schema:
|
|
468
|
-
raise CatalogSchemaError
|
|
469
|
-
|
|
470
|
-
query =
|
|
471
|
-
|
|
476
|
+
raise CatalogSchemaError
|
|
477
|
+
table_type = "all_manifests" if all_snapshots else "manifests"
|
|
478
|
+
query = 'SELECT * FROM "{}${}"'
|
|
479
|
+
table_identifier = f"{catalog}.{schema}.{table}"
|
|
480
|
+
return self.execute_query(query.format(table_identifier, table_type))
|
|
472
481
|
|
|
473
|
-
def show_partitions(self, table: str, catalog: str
|
|
482
|
+
def show_partitions(self, table: str, catalog: str, schema: str) -> str:
|
|
474
483
|
"""Show Iceberg table partitions.
|
|
475
484
|
|
|
476
485
|
The partitions table contains:
|
|
@@ -491,11 +500,12 @@ class TrinoClient:
|
|
|
491
500
|
catalog = catalog or self.config.catalog
|
|
492
501
|
schema = schema or self.config.schema
|
|
493
502
|
if not catalog or not schema:
|
|
494
|
-
raise CatalogSchemaError
|
|
495
|
-
|
|
496
|
-
|
|
503
|
+
raise CatalogSchemaError
|
|
504
|
+
table_identifier = f"{catalog}.{schema}.{table}$partitions"
|
|
505
|
+
query = 'SELECT * FROM "{}"'
|
|
506
|
+
return self.execute_query(query.format(table_identifier))
|
|
497
507
|
|
|
498
|
-
def show_files(self, table: str, catalog: str
|
|
508
|
+
def show_files(self, table: str, catalog: str, schema: str) -> str:
|
|
499
509
|
"""Show Iceberg table data files in current snapshot.
|
|
500
510
|
|
|
501
511
|
The files table contains:
|
|
@@ -525,13 +535,12 @@ class TrinoClient:
|
|
|
525
535
|
catalog = catalog or self.config.catalog
|
|
526
536
|
schema = schema or self.config.schema
|
|
527
537
|
if not catalog or not schema:
|
|
528
|
-
raise CatalogSchemaError
|
|
529
|
-
|
|
530
|
-
|
|
538
|
+
raise CatalogSchemaError
|
|
539
|
+
table_identifier = f"{catalog}.{schema}.{table}$files"
|
|
540
|
+
query = 'SELECT * FROM "{}"'
|
|
541
|
+
return self.execute_query(query.format(table_identifier))
|
|
531
542
|
|
|
532
|
-
def show_entries(
|
|
533
|
-
self, table: str, catalog: str | None = None, schema: str | None = None, all_snapshots: bool = False
|
|
534
|
-
) -> str:
|
|
543
|
+
def show_entries(self, table: str, catalog: str, schema: str, all_snapshots: bool = False) -> str:
|
|
535
544
|
"""Show Iceberg table manifest entries for current or all snapshots.
|
|
536
545
|
|
|
537
546
|
The entries table contains:
|
|
@@ -554,12 +563,12 @@ class TrinoClient:
|
|
|
554
563
|
catalog = catalog or self.config.catalog
|
|
555
564
|
schema = schema or self.config.schema
|
|
556
565
|
if not catalog or not schema:
|
|
557
|
-
raise CatalogSchemaError
|
|
566
|
+
raise CatalogSchemaError
|
|
558
567
|
table_name = f"{catalog}.{schema}.{table}${'all_' if all_snapshots else ''}entries"
|
|
559
|
-
query =
|
|
560
|
-
return self.execute_query(query)
|
|
568
|
+
query = 'SELECT * FROM "{}"'
|
|
569
|
+
return self.execute_query(query.format(table_name))
|
|
561
570
|
|
|
562
|
-
def show_refs(self, table: str, catalog: str
|
|
571
|
+
def show_refs(self, table: str, catalog: str, schema: str) -> str:
|
|
563
572
|
"""Show Iceberg table references (branches and tags).
|
|
564
573
|
|
|
565
574
|
The refs table contains:
|
|
@@ -581,6 +590,7 @@ class TrinoClient:
|
|
|
581
590
|
catalog = catalog or self.config.catalog
|
|
582
591
|
schema = schema or self.config.schema
|
|
583
592
|
if not catalog or not schema:
|
|
584
|
-
raise CatalogSchemaError
|
|
585
|
-
|
|
586
|
-
|
|
593
|
+
raise CatalogSchemaError
|
|
594
|
+
table_identifier = f"{catalog}.{schema}.{table}$refs"
|
|
595
|
+
query = 'SELECT * FROM "{}"'
|
|
596
|
+
return self.execute_query(query.format(table_identifier))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{mcp_trino_python-0.4.0 → mcp_trino_python-0.5.0}/src/mcp_trino_python.egg-info/top_level.txt
RENAMED
|
File without changes
|