Skip to content

Commit 599e4a5

Browse files
authored
Merge pull request #3 from alaturqua/add_tools
refactor: rename show_* functions to list_* and add describe_table fu…
2 parents c6df8f0 + 33659ea commit 599e4a5

File tree

4 files changed

+111
-16
lines changed

4 files changed

+111
-16
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@ The server provides the following MCP resources:
104104

105105
### Catalog and Schema Navigation
106106

107-
- **catalog://main** (`show_catalogs`)
107+
- **catalog://main** (`list_catalogs`)
108108

109109
- Lists all available Trino catalogs
110110
- No parameters required
111111

112-
- **schema://{catalog}** (`show_schemas`)
112+
- **schema://{catalog}** (`list_schemas`)
113113

114114
- Lists all schemas in the specified catalog
115115
- Parameters:
116116
- `catalog`: Catalog name (string, required)
117117

118-
- **table://{catalog}/{schema}** (`show_tables`)
118+
- **table://{catalog}/{schema}** (`list_tables`)
119119
- Lists all tables in the specified schema
120120
- Parameters:
121121
- `catalog`: Catalog name (string, required)
@@ -125,6 +125,32 @@ The server provides the following MCP resources:
125125

126126
### Query and Exploration Tools
127127

128+
- **show_catalogs**
129+
130+
- List all available catalogs
131+
- No parameters required
132+
133+
- **show_schemas**
134+
135+
- List all schemas in a catalog
136+
- Parameters:
137+
- `catalog`: Catalog name (string, required)
138+
139+
- **show_tables**
140+
141+
- List all tables in a schema
142+
- Parameters:
143+
- `catalog`: Catalog name (string, required)
144+
- `schema`: Schema name (string, required)
145+
146+
- **describe_table**
147+
148+
- Show detailed table structure and column information
149+
- Parameters:
150+
- `table`: Table name (string, required)
151+
- `catalog`: Catalog name (string, optional)
152+
- `schema`: Schema name (string, optional)
153+
128154
- **execute_query**
129155

130156
- Execute a SQL query and return formatted results

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-trino-python"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
description = "A Model Context Protocol (MCP) connector for Trino, enabling seamless integration between MCP-compliant services and Trino query engine"
55
readme = "README.md"
66
license = { text = "Apache-2.0" }

src/server.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,83 @@
1919
# Resources
2020
@mcp.resource(
2121
"catalog://main",
22-
name="show_catalogs",
22+
name="list_catalogs",
2323
description="List all available Trino catalogs",
2424
)
25-
def show_catalogs() -> str:
25+
def list_catalogs() -> str:
2626
"""List all available Trino catalogs."""
27-
return client.show_catalogs()
27+
return client.list_catalogs()
2828

2929

3030
@mcp.resource(
3131
"schema://{catalog}",
32-
name="show_schemas",
32+
name="list_schemas",
3333
description="List all schemas in the specified catalog",
3434
)
35-
def show_schemas(catalog: str) -> str:
35+
def list_schemas(catalog: str) -> str:
3636
"""List all schemas in a catalog."""
37-
return client.show_schemas(catalog)
37+
return client.list_schemas(catalog)
3838

3939

4040
@mcp.resource(
4141
"table://{catalog}/{schema}",
42-
name="show_tables",
42+
name="list_tables",
4343
description="List all tables in the specified schema",
4444
)
45-
def show_tables(catalog: str, schema: str) -> str:
45+
def list_tables(catalog: str, schema: str) -> str:
4646
"""List all tables in a schema."""
47-
return client.show_tables(catalog, schema)
47+
return client.list_tables(catalog, schema)
4848

4949

5050
# Tools
51+
@mcp.tool(description="List all available catalogs")
52+
def show_catalogs() -> str:
53+
"""List all available catalogs."""
54+
return client.list_catalogs()
55+
56+
57+
@mcp.tool(description="List all schemas in a catalog")
58+
def show_schemas(catalog: str) -> str:
59+
"""List all schemas in a catalog.
60+
61+
Args:
62+
catalog: The name of the catalog
63+
64+
Returns:
65+
str: List of schemas in the specified catalog
66+
"""
67+
return client.list_schemas(catalog)
68+
69+
70+
@mcp.tool(description="List all tables in a schema")
71+
def show_tables(catalog: str, schema: str) -> str:
72+
"""List all tables in a schema.
73+
74+
Args:
75+
catalog: The name of the catalog
76+
schema: The name of the schema
77+
78+
Returns:
79+
str: List of tables in the specified schema
80+
"""
81+
return client.list_tables(catalog, schema)
82+
83+
84+
@mcp.tool(description="Describe a table")
85+
def describe_table(table: str, catalog: str | None = None, schema: str | None = None) -> str:
86+
"""Describe a table.
87+
88+
Args:
89+
table: The name of the table
90+
catalog: Optional catalog name (defaults to configured catalog)
91+
schema: Optional schema name (defaults to configured schema)
92+
93+
Returns:
94+
str: Table description in JSON format
95+
"""
96+
return client.describe_table(table, catalog, schema)
97+
98+
5199
@mcp.tool(description="Show the CREATE TABLE statement for a specific table")
52100
def show_create_table(table: str, catalog: str | None = None, schema: str | None = None) -> str:
53101
"""Show the CREATE TABLE statement for a table.

src/trino_client.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get_query_history(self, limit: int | None = None) -> str:
9696
query += f" LIMIT {limit}"
9797
return self.execute_query(query)
9898

99-
def show_catalogs(self) -> str:
99+
def list_catalogs(self) -> str:
100100
"""List all available catalogs.
101101
102102
Returns:
@@ -105,7 +105,7 @@ def show_catalogs(self) -> str:
105105
catalogs = [row["Catalog"] for row in json.loads(self.execute_query("SHOW CATALOGS"))]
106106
return "\n".join(catalogs)
107107

108-
def show_schemas(self, catalog: str | None = None) -> str:
108+
def list_schemas(self, catalog: str | None = None) -> str:
109109
"""List all schemas in a catalog.
110110
111111
Args:
@@ -125,7 +125,7 @@ def show_schemas(self, catalog: str | None = None) -> str:
125125
schemas = [row["Schema"] for row in json.loads(self.execute_query(query))]
126126
return "\n".join(schemas)
127127

128-
def show_tables(self, catalog: str | None = None, schema: str | None = None) -> str:
128+
def list_tables(self, catalog: str | None = None, schema: str | None = None) -> str:
129129
"""List all tables in a schema.
130130
131131
Args:
@@ -147,6 +147,27 @@ def show_tables(self, catalog: str | None = None, schema: str | None = None) ->
147147
tables = [row["Table"] for row in json.loads(self.execute_query(query))]
148148
return "\n".join(tables)
149149

150+
def describe_table(self, table: str, catalog: str | None = None, schema: str | None = None) -> str:
151+
"""Describe the structure of a table.
152+
153+
Args:
154+
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+
Returns:
159+
str: JSON-formatted string containing table description.
160+
161+
Raises:
162+
CatalogSchemaError: If either catalog or schema is not specified and not configured.
163+
"""
164+
catalog = catalog or self.config.catalog
165+
schema = schema or self.config.schema
166+
if not catalog or not schema:
167+
raise CatalogSchemaError()
168+
query = f"DESCRIBE {catalog}.{schema}.{table}"
169+
return self.execute_query(query)
170+
150171
def show_create_table(self, table: str, catalog: str | None = None, schema: str | None = None) -> str:
151172
"""Show the CREATE TABLE statement for a table.
152173

0 commit comments

Comments
 (0)