mcp-trino-python 0.4.0__tar.gz → 0.6.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.6.0}/PKG-INFO +11 -24
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/README.md +9 -23
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/pyproject.toml +2 -1
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/mcp_trino_python.egg-info/PKG-INFO +11 -24
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/mcp_trino_python.egg-info/requires.txt +1 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/server.py +209 -112
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/trino_client.py +79 -69
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/LICENSE +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/setup.cfg +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/__init__.py +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/config.py +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/mcp_trino_python.egg-info/SOURCES.txt +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/mcp_trino_python.egg-info/dependency_links.txt +0 -0
- {mcp_trino_python-0.4.0 → mcp_trino_python-0.6.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.6.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
|
|
@@ -13,6 +13,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
13
13
|
Requires-Python: >=3.12
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
|
+
Requires-Dist: fastapi>=0.115.12
|
|
16
17
|
Requires-Dist: loguru>=0.7.3
|
|
17
18
|
Requires-Dist: mcp[cli]>=1.6.0
|
|
18
19
|
Requires-Dist: python-dotenv>=1.1.0
|
|
@@ -21,6 +22,7 @@ Dynamic: license-file
|
|
|
21
22
|
|
|
22
23
|
# MCP Trino Server
|
|
23
24
|
|
|
25
|
+
[](https://smithery.ai/server/@alaturqua/mcp-trino-python)
|
|
24
26
|
[](https://www.python.org/downloads/)
|
|
25
27
|
[](https://code.visualstudio.com/)
|
|
26
28
|
[](https://github.com/alaturqua/mcp-trino-python/pkgs/container/mcp-trino-python)
|
|
@@ -45,6 +47,14 @@ data exploration, querying, and table maintenance capabilities through a standar
|
|
|
45
47
|
|
|
46
48
|
## Installation
|
|
47
49
|
|
|
50
|
+
### Installing via Smithery
|
|
51
|
+
|
|
52
|
+
To install MCP Trino Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@alaturqua/mcp-trino-python):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx -y @smithery/cli install @alaturqua/mcp-trino-python --client claude
|
|
56
|
+
```
|
|
57
|
+
|
|
48
58
|
### Running Trino Locally
|
|
49
59
|
|
|
50
60
|
The easiest way to get started is to use the included Docker Compose configuration to run Trino locally:
|
|
@@ -119,29 +129,6 @@ Add the following configuration to your Claude Desktop settings:
|
|
|
119
129
|
| TRINO_HTTP_SCHEME | HTTP scheme (http/https) | http |
|
|
120
130
|
| TRINO_PASSWORD | Trino password | None |
|
|
121
131
|
|
|
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
132
|
## Tools
|
|
146
133
|
|
|
147
134
|
### 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,12 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mcp-trino-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.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" }
|
|
7
7
|
requires-python = ">=3.12"
|
|
8
8
|
keywords = ["trino", "connector", "mcp"]
|
|
9
9
|
dependencies = [
|
|
10
|
+
"fastapi>=0.115.12",
|
|
10
11
|
"loguru>=0.7.3",
|
|
11
12
|
"mcp[cli]>=1.6.0",
|
|
12
13
|
"python-dotenv>=1.1.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-trino-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.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
|
|
@@ -13,6 +13,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
13
13
|
Requires-Python: >=3.12
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
|
+
Requires-Dist: fastapi>=0.115.12
|
|
16
17
|
Requires-Dist: loguru>=0.7.3
|
|
17
18
|
Requires-Dist: mcp[cli]>=1.6.0
|
|
18
19
|
Requires-Dist: python-dotenv>=1.1.0
|
|
@@ -21,6 +22,7 @@ Dynamic: license-file
|
|
|
21
22
|
|
|
22
23
|
# MCP Trino Server
|
|
23
24
|
|
|
25
|
+
[](https://smithery.ai/server/@alaturqua/mcp-trino-python)
|
|
24
26
|
[](https://www.python.org/downloads/)
|
|
25
27
|
[](https://code.visualstudio.com/)
|
|
26
28
|
[](https://github.com/alaturqua/mcp-trino-python/pkgs/container/mcp-trino-python)
|
|
@@ -45,6 +47,14 @@ data exploration, querying, and table maintenance capabilities through a standar
|
|
|
45
47
|
|
|
46
48
|
## Installation
|
|
47
49
|
|
|
50
|
+
### Installing via Smithery
|
|
51
|
+
|
|
52
|
+
To install MCP Trino Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@alaturqua/mcp-trino-python):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx -y @smithery/cli install @alaturqua/mcp-trino-python --client claude
|
|
56
|
+
```
|
|
57
|
+
|
|
48
58
|
### Running Trino Locally
|
|
49
59
|
|
|
50
60
|
The easiest way to get started is to use the included Docker Compose configuration to run Trino locally:
|
|
@@ -119,29 +129,6 @@ Add the following configuration to your Claude Desktop settings:
|
|
|
119
129
|
| TRINO_HTTP_SCHEME | HTTP scheme (http/https) | http |
|
|
120
130
|
| TRINO_PASSWORD | Trino password | None |
|
|
121
131
|
|
|
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
132
|
## Tools
|
|
146
133
|
|
|
147
134
|
### Query and Exploration Tools
|
|
@@ -4,8 +4,15 @@ This module provides a Model Context Protocol (MCP) server that exposes Trino
|
|
|
4
4
|
functionality through resources and tools, with special support for Iceberg tables.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
import uvicorn
|
|
8
|
+
from mcp.server import Server
|
|
7
9
|
from mcp.server.fastmcp import FastMCP
|
|
8
10
|
from mcp.server.fastmcp.prompts import base
|
|
11
|
+
from mcp.server.sse import SseServerTransport
|
|
12
|
+
from pydantic import Field
|
|
13
|
+
from starlette.applications import Starlette
|
|
14
|
+
from starlette.requests import Request
|
|
15
|
+
from starlette.routing import Mount, Route
|
|
9
16
|
|
|
10
17
|
from config import load_config
|
|
11
18
|
from trino_client import TrinoClient
|
|
@@ -13,38 +20,14 @@ from trino_client import TrinoClient
|
|
|
13
20
|
# Initialize the MCP server and Trino client
|
|
14
21
|
config = load_config()
|
|
15
22
|
client = TrinoClient(config)
|
|
16
|
-
mcp = FastMCP("Trino Explorer", dependencies=["trino", "python-dotenv", "loguru"])
|
|
17
23
|
|
|
18
24
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
# Initialize the MCP server with context
|
|
26
|
+
mcp = FastMCP(
|
|
27
|
+
name="Trino Explorer",
|
|
28
|
+
instructions="This Model Context Protocol (MCP) server provides access to Trino Query Engine.",
|
|
29
|
+
dependencies=["trino", "python-dotenv", "loguru"],
|
|
24
30
|
)
|
|
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
31
|
|
|
49
32
|
|
|
50
33
|
# Tools
|
|
@@ -55,7 +38,7 @@ def show_catalogs() -> str:
|
|
|
55
38
|
|
|
56
39
|
|
|
57
40
|
@mcp.tool(description="List all schemas in a catalog")
|
|
58
|
-
def show_schemas(catalog: str) -> str:
|
|
41
|
+
def show_schemas(catalog: str = Field(description="The name of the catalog")) -> str:
|
|
59
42
|
"""List all schemas in a catalog.
|
|
60
43
|
|
|
61
44
|
Args:
|
|
@@ -68,66 +51,81 @@ def show_schemas(catalog: str) -> str:
|
|
|
68
51
|
|
|
69
52
|
|
|
70
53
|
@mcp.tool(description="List all tables in a schema")
|
|
71
|
-
def show_tables(
|
|
54
|
+
def show_tables(
|
|
55
|
+
catalog: str = Field(description="The name of the catalog"),
|
|
56
|
+
schema_name: str = Field(description="The name of the schema"),
|
|
57
|
+
) -> str:
|
|
72
58
|
"""List all tables in a schema.
|
|
73
59
|
|
|
74
60
|
Args:
|
|
75
61
|
catalog: The name of the catalog
|
|
76
|
-
|
|
62
|
+
schema_name: The name of the schema
|
|
77
63
|
|
|
78
64
|
Returns:
|
|
79
65
|
str: List of tables in the specified schema
|
|
80
66
|
"""
|
|
81
|
-
return client.list_tables(catalog,
|
|
67
|
+
return client.list_tables(catalog, schema_name)
|
|
82
68
|
|
|
83
69
|
|
|
84
70
|
@mcp.tool(description="Describe a table")
|
|
85
|
-
def describe_table(
|
|
71
|
+
def describe_table(
|
|
72
|
+
catalog: str = Field(description="The catalog name"),
|
|
73
|
+
schema_name: str = Field(description="The schema name"),
|
|
74
|
+
table: str = Field(description="The name of the table"),
|
|
75
|
+
) -> str:
|
|
86
76
|
"""Describe a table.
|
|
87
77
|
|
|
88
78
|
Args:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
catalog (str): The catalog name
|
|
80
|
+
schema_name (str): The schema name
|
|
81
|
+
table (str): The name of the table
|
|
92
82
|
|
|
93
83
|
Returns:
|
|
94
84
|
str: Table description in JSON format
|
|
95
85
|
"""
|
|
96
|
-
return client.describe_table(
|
|
86
|
+
return client.describe_table(catalog, schema_name, table)
|
|
97
87
|
|
|
98
88
|
|
|
99
89
|
@mcp.tool(description="Show the CREATE TABLE statement for a specific table")
|
|
100
|
-
def show_create_table(
|
|
90
|
+
def show_create_table(
|
|
91
|
+
catalog: str = Field(description="catalog name "),
|
|
92
|
+
schema_name: str = Field(description="schema name "),
|
|
93
|
+
table: str = Field(description="The name of the table"),
|
|
94
|
+
) -> str:
|
|
101
95
|
"""Show the CREATE TABLE statement for a table.
|
|
102
96
|
|
|
103
97
|
Args:
|
|
98
|
+
catalog: catalog name
|
|
99
|
+
schema_name: schema name
|
|
104
100
|
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
101
|
|
|
108
102
|
Returns:
|
|
109
103
|
str: The CREATE TABLE statement
|
|
110
104
|
"""
|
|
111
|
-
return client.show_create_table(
|
|
105
|
+
return client.show_create_table(catalog, schema_name, table)
|
|
112
106
|
|
|
113
107
|
|
|
114
108
|
@mcp.tool(description="Show the CREATE VIEW statement for a specific view")
|
|
115
|
-
def show_create_view(
|
|
109
|
+
def show_create_view(
|
|
110
|
+
catalog: str = Field(description="catalog name "),
|
|
111
|
+
schema_name: str = Field(description="schema name "),
|
|
112
|
+
view: str = Field(description="The name of the view"),
|
|
113
|
+
) -> str:
|
|
116
114
|
"""Show the CREATE VIEW statement for a view.
|
|
117
115
|
|
|
118
116
|
Args:
|
|
117
|
+
catalog: catalog name
|
|
118
|
+
schema_name: schema name
|
|
119
119
|
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
120
|
|
|
123
121
|
Returns:
|
|
124
122
|
str: The CREATE VIEW statement
|
|
125
123
|
"""
|
|
126
|
-
return client.show_create_view(
|
|
124
|
+
return client.show_create_view(catalog, schema_name, view)
|
|
127
125
|
|
|
128
126
|
|
|
129
127
|
@mcp.tool(description="Execute a SQL query and return results in a readable format")
|
|
130
|
-
def execute_query(query: str) -> str:
|
|
128
|
+
def execute_query(query: str = Field(description="The SQL query to execute")) -> str:
|
|
131
129
|
"""Execute a SQL query and return formatted results.
|
|
132
130
|
|
|
133
131
|
Args:
|
|
@@ -140,77 +138,93 @@ def execute_query(query: str) -> str:
|
|
|
140
138
|
|
|
141
139
|
|
|
142
140
|
@mcp.tool(description="Optimize an Iceberg table's data files")
|
|
143
|
-
def optimize(
|
|
141
|
+
def optimize(
|
|
142
|
+
catalog: str = Field(description="catalog name "),
|
|
143
|
+
schema_name: str = Field(description="schema name "),
|
|
144
|
+
table: str = Field(description="The name of the table to optimize"),
|
|
145
|
+
) -> str:
|
|
144
146
|
"""Optimize an Iceberg table by compacting small files.
|
|
145
147
|
|
|
146
148
|
Args:
|
|
149
|
+
catalog: catalog name
|
|
150
|
+
schema_name: schema name
|
|
147
151
|
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
152
|
|
|
151
153
|
Returns:
|
|
152
154
|
str: Confirmation message
|
|
153
155
|
"""
|
|
154
|
-
return client.optimize(
|
|
156
|
+
return client.optimize(catalog, schema_name, table)
|
|
155
157
|
|
|
156
158
|
|
|
157
159
|
@mcp.tool(description="Optimize manifest files for an Iceberg table")
|
|
158
|
-
def optimize_manifests(
|
|
160
|
+
def optimize_manifests(
|
|
161
|
+
catalog: str = Field(description="catalog name "),
|
|
162
|
+
schema_name: str = Field(description="schema name "),
|
|
163
|
+
table: str = Field(description="The name of the table"),
|
|
164
|
+
) -> str:
|
|
159
165
|
"""Optimize manifest files for an Iceberg table.
|
|
160
166
|
|
|
161
167
|
Args:
|
|
168
|
+
catalog: catalog name
|
|
169
|
+
schema_name: schema name
|
|
162
170
|
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
171
|
|
|
166
172
|
Returns:
|
|
167
173
|
str: Confirmation message
|
|
168
174
|
"""
|
|
169
|
-
return client.optimize_manifests(
|
|
175
|
+
return client.optimize_manifests(catalog, schema_name, table)
|
|
170
176
|
|
|
171
177
|
|
|
172
178
|
@mcp.tool(description="Remove old snapshots from an Iceberg table")
|
|
173
179
|
def expire_snapshots(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
catalog: str = Field(description="catalog name "),
|
|
181
|
+
schema_name: str = Field(description="schema name "),
|
|
182
|
+
retention_threshold: str = Field(
|
|
183
|
+
description="Age threshold for snapshot removal (e.g., '7d', '30d')", default="7d"
|
|
184
|
+
),
|
|
185
|
+
table: str = Field(description="The name of the table"),
|
|
178
186
|
) -> str:
|
|
179
187
|
"""Remove old snapshots from an Iceberg table.
|
|
180
188
|
|
|
181
189
|
Args:
|
|
190
|
+
catalog: catalog name
|
|
191
|
+
schema_name: schema name
|
|
182
192
|
table: The name of the table
|
|
183
193
|
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
194
|
|
|
187
195
|
Returns:
|
|
188
196
|
str: Confirmation message
|
|
189
197
|
"""
|
|
190
|
-
return client.expire_snapshots(
|
|
198
|
+
return client.expire_snapshots(catalog, schema_name, table, retention_threshold)
|
|
191
199
|
|
|
192
200
|
|
|
193
201
|
@mcp.tool(description="Show statistics for a table")
|
|
194
|
-
def show_stats(
|
|
202
|
+
def show_stats(
|
|
203
|
+
catalog: str = Field(description="catalog name "),
|
|
204
|
+
schema_name: str = Field(description="schema name "),
|
|
205
|
+
table: str = Field(description="The name of the table"),
|
|
206
|
+
) -> str:
|
|
195
207
|
"""Show statistics for a table.
|
|
196
208
|
|
|
197
209
|
Args:
|
|
210
|
+
catalog: catalog name
|
|
211
|
+
schema_name: schema name
|
|
198
212
|
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
213
|
|
|
202
214
|
Returns:
|
|
203
215
|
str: Table statistics in JSON format
|
|
204
216
|
"""
|
|
205
|
-
return client.show_stats(
|
|
217
|
+
return client.show_stats(catalog, schema_name, table)
|
|
206
218
|
|
|
207
219
|
|
|
208
220
|
@mcp.tool(name="show_query_history", description="Get the history of executed queries")
|
|
209
|
-
def show_query_history(
|
|
221
|
+
def show_query_history(
|
|
222
|
+
limit: int = Field(description="maximum number of history entries to return", default=None),
|
|
223
|
+
) -> str:
|
|
210
224
|
"""Get the history of executed queries.
|
|
211
225
|
|
|
212
226
|
Args:
|
|
213
|
-
limit:
|
|
227
|
+
limit: maximum number of history entries to return.
|
|
214
228
|
If None, returns all entries.
|
|
215
229
|
|
|
216
230
|
Returns:
|
|
@@ -230,22 +244,30 @@ def show_catalog_tree() -> str:
|
|
|
230
244
|
|
|
231
245
|
|
|
232
246
|
@mcp.tool(description="Show Iceberg table properties")
|
|
233
|
-
def show_table_properties(
|
|
247
|
+
def show_table_properties(
|
|
248
|
+
catalog: str = Field(description="catalog name "),
|
|
249
|
+
schema_name: str = Field(description="schema name "),
|
|
250
|
+
table: str = Field(description="The name of the table"),
|
|
251
|
+
) -> str:
|
|
234
252
|
"""Show Iceberg table properties.
|
|
235
253
|
|
|
236
254
|
Args:
|
|
255
|
+
catalog: catalog name
|
|
256
|
+
schema_name: schema name
|
|
237
257
|
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
258
|
|
|
241
259
|
Returns:
|
|
242
260
|
str: JSON-formatted table properties
|
|
243
261
|
"""
|
|
244
|
-
return client.show_table_properties(
|
|
262
|
+
return client.show_table_properties(catalog, schema_name, table)
|
|
245
263
|
|
|
246
264
|
|
|
247
265
|
@mcp.tool(description="Show Iceberg table history/changelog")
|
|
248
|
-
def show_table_history(
|
|
266
|
+
def show_table_history(
|
|
267
|
+
catalog: str = Field(description="catalog name "),
|
|
268
|
+
schema_name: str = Field(description="schema name "),
|
|
269
|
+
table: str = Field(description="The name of the table"),
|
|
270
|
+
) -> str:
|
|
249
271
|
"""Show Iceberg table history/changelog.
|
|
250
272
|
|
|
251
273
|
The history contains:
|
|
@@ -255,18 +277,22 @@ def show_table_history(table: str, catalog: str | None = None, schema: str | Non
|
|
|
255
277
|
- is_current_ancestor: Whether snapshot is an ancestor of current
|
|
256
278
|
|
|
257
279
|
Args:
|
|
280
|
+
catalog: catalog name
|
|
281
|
+
schema_name: schema name
|
|
258
282
|
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
283
|
|
|
262
284
|
Returns:
|
|
263
285
|
str: JSON-formatted table history
|
|
264
286
|
"""
|
|
265
|
-
return client.show_table_history(
|
|
287
|
+
return client.show_table_history(catalog, schema_name, table)
|
|
266
288
|
|
|
267
289
|
|
|
268
|
-
@mcp.tool(description="Show
|
|
269
|
-
def show_metadata_log_entries(
|
|
290
|
+
@mcp.tool(description="Show metadata for the table")
|
|
291
|
+
def show_metadata_log_entries(
|
|
292
|
+
catalog: str = Field(description="catalog name "),
|
|
293
|
+
schema_name: str = Field(description="schema name "),
|
|
294
|
+
table: str = Field(description="The name of the table"),
|
|
295
|
+
) -> str:
|
|
270
296
|
"""Show Iceberg table metadata log entries.
|
|
271
297
|
|
|
272
298
|
The metadata log contains:
|
|
@@ -277,18 +303,22 @@ def show_metadata_log_entries(table: str, catalog: str | None = None, schema: st
|
|
|
277
303
|
- latest_sequence_number: Data sequence number of metadata file
|
|
278
304
|
|
|
279
305
|
Args:
|
|
306
|
+
catalog: catalog name
|
|
307
|
+
schema_name: schema name
|
|
280
308
|
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
309
|
|
|
284
310
|
Returns:
|
|
285
311
|
str: JSON-formatted metadata log entries
|
|
286
312
|
"""
|
|
287
|
-
return client.show_metadata_log_entries(
|
|
313
|
+
return client.show_metadata_log_entries(catalog, schema_name, table)
|
|
288
314
|
|
|
289
315
|
|
|
290
316
|
@mcp.tool(description="Show Iceberg table snapshots")
|
|
291
|
-
def show_snapshots(
|
|
317
|
+
def show_snapshots(
|
|
318
|
+
catalog: str = Field(description="catalog name "),
|
|
319
|
+
schema_name: str = Field(description="schema name "),
|
|
320
|
+
table: str = Field(description="The name of the table"),
|
|
321
|
+
) -> str:
|
|
292
322
|
"""Show Iceberg table snapshots.
|
|
293
323
|
|
|
294
324
|
The snapshots table contains:
|
|
@@ -300,19 +330,22 @@ def show_snapshots(table: str, catalog: str | None = None, schema: str | None =
|
|
|
300
330
|
- summary: Summary of changes from previous snapshot
|
|
301
331
|
|
|
302
332
|
Args:
|
|
333
|
+
catalog: catalog name
|
|
334
|
+
schema_name: schema name
|
|
303
335
|
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
336
|
|
|
307
337
|
Returns:
|
|
308
338
|
str: JSON-formatted table snapshots
|
|
309
339
|
"""
|
|
310
|
-
return client.show_snapshots(
|
|
340
|
+
return client.show_snapshots(catalog, schema_name, table)
|
|
311
341
|
|
|
312
342
|
|
|
313
343
|
@mcp.tool(description="Show Iceberg table manifests")
|
|
314
344
|
def show_manifests(
|
|
315
|
-
|
|
345
|
+
catalog: str = Field(description="catalog name"),
|
|
346
|
+
schema_name: str = Field(description="schema name"),
|
|
347
|
+
table: str = Field(description="The name of the table"),
|
|
348
|
+
all_snapshots: bool = False,
|
|
316
349
|
) -> str:
|
|
317
350
|
"""Show Iceberg table manifests for current or all snapshots.
|
|
318
351
|
|
|
@@ -330,19 +363,23 @@ def show_manifests(
|
|
|
330
363
|
- partition_summaries: Partition range metadata
|
|
331
364
|
|
|
332
365
|
Args:
|
|
366
|
+
catalog: catalog name
|
|
367
|
+
schema_name: schema name
|
|
333
368
|
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
369
|
all_snapshots: If True, show manifests from all snapshots
|
|
337
370
|
|
|
338
371
|
Returns:
|
|
339
372
|
str: JSON-formatted table manifests
|
|
340
373
|
"""
|
|
341
|
-
return client.show_manifests(
|
|
374
|
+
return client.show_manifests(catalog, schema_name, table, all_snapshots)
|
|
342
375
|
|
|
343
376
|
|
|
344
377
|
@mcp.tool(description="Show Iceberg table partitions")
|
|
345
|
-
def show_partitions(
|
|
378
|
+
def show_partitions(
|
|
379
|
+
catalog: str = Field(description="catalog name "),
|
|
380
|
+
schema_name: str = Field(description="schema name "),
|
|
381
|
+
table: str = Field(description="The name of the table"),
|
|
382
|
+
) -> str:
|
|
346
383
|
"""Show Iceberg table partitions.
|
|
347
384
|
|
|
348
385
|
The partitions table contains:
|
|
@@ -353,18 +390,22 @@ def show_partitions(table: str, catalog: str | None = None, schema: str | None =
|
|
|
353
390
|
- data: Partition range metadata with min/max values and null/nan counts
|
|
354
391
|
|
|
355
392
|
Args:
|
|
393
|
+
catalog: catalog name
|
|
394
|
+
schema_name: schema name
|
|
356
395
|
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
396
|
|
|
360
397
|
Returns:
|
|
361
398
|
str: JSON-formatted table partitions
|
|
362
399
|
"""
|
|
363
|
-
return client.show_partitions(
|
|
400
|
+
return client.show_partitions(catalog, schema_name, table)
|
|
364
401
|
|
|
365
402
|
|
|
366
403
|
@mcp.tool(description="Show Iceberg table data files")
|
|
367
|
-
def show_files(
|
|
404
|
+
def show_files(
|
|
405
|
+
catalog: str = Field(description="catalog name "),
|
|
406
|
+
schema_name: str = Field(description="schema name "),
|
|
407
|
+
table: str = Field(description="The name of the table"),
|
|
408
|
+
) -> str:
|
|
368
409
|
"""Show Iceberg table data files in current snapshot.
|
|
369
410
|
|
|
370
411
|
The files table contains:
|
|
@@ -384,18 +425,23 @@ def show_files(table: str, catalog: str | None = None, schema: str | None = None
|
|
|
384
425
|
- equality_ids: Field IDs for equality deletes
|
|
385
426
|
|
|
386
427
|
Args:
|
|
428
|
+
catalog: catalog name
|
|
429
|
+
schema_name: schema name
|
|
387
430
|
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
431
|
|
|
391
432
|
Returns:
|
|
392
433
|
str: JSON-formatted table files info
|
|
393
434
|
"""
|
|
394
|
-
return client.show_files(
|
|
435
|
+
return client.show_files(catalog, schema_name, table)
|
|
395
436
|
|
|
396
437
|
|
|
397
438
|
@mcp.tool(description="Show Iceberg table manifest entries")
|
|
398
|
-
def show_entries(
|
|
439
|
+
def show_entries(
|
|
440
|
+
catalog: str = Field(description="catalog name "),
|
|
441
|
+
schema_name: str = Field(description="schema name "),
|
|
442
|
+
table: str = Field(description="The name of the table"),
|
|
443
|
+
all_snapshots: bool = False,
|
|
444
|
+
) -> str:
|
|
399
445
|
"""Show Iceberg table manifest entries for current or all snapshots.
|
|
400
446
|
|
|
401
447
|
The entries table contains:
|
|
@@ -407,19 +453,23 @@ def show_entries(table: str, catalog: str | None = None, schema: str | None = No
|
|
|
407
453
|
- readable_metrics: Human-readable file metrics
|
|
408
454
|
|
|
409
455
|
Args:
|
|
456
|
+
catalog: catalog name
|
|
457
|
+
schema_name: schema name
|
|
410
458
|
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
459
|
all_snapshots: If True, show entries from all snapshots
|
|
414
460
|
|
|
415
461
|
Returns:
|
|
416
462
|
str: JSON-formatted manifest entries
|
|
417
463
|
"""
|
|
418
|
-
return client.show_entries(
|
|
464
|
+
return client.show_entries(catalog, schema_name, table, all_snapshots)
|
|
419
465
|
|
|
420
466
|
|
|
421
467
|
@mcp.tool(description="Show Iceberg table references (branches and tags)")
|
|
422
|
-
def show_refs(
|
|
468
|
+
def show_refs(
|
|
469
|
+
catalog: str = Field(description="catalog name "),
|
|
470
|
+
schema_name: str = Field(description="schema name "),
|
|
471
|
+
table: str = Field(description="The name of the table"),
|
|
472
|
+
) -> str:
|
|
423
473
|
"""Show Iceberg table references (branches and tags).
|
|
424
474
|
|
|
425
475
|
The refs table contains:
|
|
@@ -431,20 +481,28 @@ def show_refs(table: str, catalog: str | None = None, schema: str | None = None)
|
|
|
431
481
|
- max_snapshot_age_in_ms: Max snapshot age in branch
|
|
432
482
|
|
|
433
483
|
Args:
|
|
484
|
+
catalog: catalog name
|
|
485
|
+
schema_name: schema name
|
|
434
486
|
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
487
|
|
|
438
488
|
Returns:
|
|
439
489
|
str: JSON-formatted table references
|
|
440
490
|
"""
|
|
441
|
-
return client.show_refs(
|
|
491
|
+
return client.show_refs(catalog, schema_name, table)
|
|
442
492
|
|
|
443
493
|
|
|
444
494
|
# Prompts
|
|
445
495
|
@mcp.prompt()
|
|
446
|
-
def explore_data(catalog: str
|
|
447
|
-
"""Interactive prompt to explore Trino data.
|
|
496
|
+
def explore_data(catalog: str, schema_name: str) -> list[base.Message]:
|
|
497
|
+
"""Interactive prompt to explore Trino data.
|
|
498
|
+
|
|
499
|
+
Args:
|
|
500
|
+
catalog: The name of the catalog to explore
|
|
501
|
+
schema_name: The name of the schema to explore
|
|
502
|
+
|
|
503
|
+
Returns:
|
|
504
|
+
list[base.Message]: A list of system and user messages to guide the conversation
|
|
505
|
+
"""
|
|
448
506
|
messages = [
|
|
449
507
|
base.SystemMessage(
|
|
450
508
|
"I'll help you explore data in Trino. I can show you available catalogs, "
|
|
@@ -452,10 +510,10 @@ def explore_data(catalog: str | None = None, schema: str | None = None) -> list[
|
|
|
452
510
|
)
|
|
453
511
|
]
|
|
454
512
|
|
|
455
|
-
if catalog and
|
|
513
|
+
if catalog and schema_name:
|
|
456
514
|
messages.append(
|
|
457
515
|
base.UserMessage(
|
|
458
|
-
f"Show me what tables are available in the {catalog}.{
|
|
516
|
+
f"Show me what tables are available in the {catalog}.{schema_name} schema and help me query them."
|
|
459
517
|
)
|
|
460
518
|
)
|
|
461
519
|
elif catalog:
|
|
@@ -467,7 +525,7 @@ def explore_data(catalog: str | None = None, schema: str | None = None) -> list[
|
|
|
467
525
|
|
|
468
526
|
|
|
469
527
|
@mcp.prompt()
|
|
470
|
-
def maintain_iceberg(table: str, catalog: str
|
|
528
|
+
def maintain_iceberg(table: str, catalog: str, schema_name: str) -> list[base.Message]:
|
|
471
529
|
"""Interactive prompt for Iceberg table maintenance."""
|
|
472
530
|
return [
|
|
473
531
|
base.SystemMessage(
|
|
@@ -476,13 +534,52 @@ def maintain_iceberg(table: str, catalog: str | None = None, schema: str | None
|
|
|
476
534
|
),
|
|
477
535
|
base.UserMessage(
|
|
478
536
|
f"What maintenance operations should we perform on the Iceberg table "
|
|
479
|
-
f"{catalog + '.' if catalog else ''}{
|
|
537
|
+
f"{catalog + '.' if catalog else ''}{schema_name + '.' if schema_name else ''}{table}?"
|
|
480
538
|
),
|
|
481
539
|
]
|
|
482
540
|
|
|
483
541
|
|
|
542
|
+
def create_starlette_app(mcp_server: Server, *, debug: bool = False) -> Starlette:
|
|
543
|
+
"""Create a Starlette application that can server the provied mcp server with SSE."""
|
|
544
|
+
sse = SseServerTransport("/messages/")
|
|
545
|
+
|
|
546
|
+
async def handle_sse(request: Request) -> None:
|
|
547
|
+
async with sse.connect_sse(
|
|
548
|
+
request.scope,
|
|
549
|
+
request.receive,
|
|
550
|
+
request._send, # noqa: SLF001
|
|
551
|
+
) as (read_stream, write_stream):
|
|
552
|
+
await mcp_server.run(
|
|
553
|
+
read_stream,
|
|
554
|
+
write_stream,
|
|
555
|
+
mcp_server.create_initialization_options(),
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
return Starlette(
|
|
559
|
+
debug=debug,
|
|
560
|
+
routes=[
|
|
561
|
+
Route("/sse", endpoint=handle_sse),
|
|
562
|
+
Mount("/messages/", app=sse.handle_post_message),
|
|
563
|
+
],
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
|
|
484
567
|
if __name__ == "__main__":
|
|
568
|
+
import argparse
|
|
569
|
+
|
|
485
570
|
from loguru import logger
|
|
486
571
|
|
|
487
572
|
logger.info("Starting Trino MCP server...")
|
|
488
|
-
mcp.run()
|
|
573
|
+
# mcp.run()
|
|
574
|
+
mcp_server = mcp._mcp_server # noqa: SLF001
|
|
575
|
+
|
|
576
|
+
parser = argparse.ArgumentParser(description="Run MCP SSE-based server")
|
|
577
|
+
parser.add_argument("--host", default="0.0.0.0", help="Host to bind to")
|
|
578
|
+
parser.add_argument("--port", type=int, default=8000, help="Port to listen on")
|
|
579
|
+
args = parser.parse_args()
|
|
580
|
+
|
|
581
|
+
# Bind SSE request handling to MCP server
|
|
582
|
+
starlette_app = create_starlette_app(mcp_server, debug=True)
|
|
583
|
+
# Run the server with Uvicorn
|
|
584
|
+
uvicorn.run(starlette_app, host=args.host, port=args.port)
|
|
585
|
+
logger.info("Trino MCP server is running.")
|
|
@@ -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.6.0}/src/mcp_trino_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{mcp_trino_python-0.4.0 → mcp_trino_python-0.6.0}/src/mcp_trino_python.egg-info/top_level.txt
RENAMED
|
File without changes
|