Skip to content

Commit dca53a9

Browse files
committed
standardizing on db_name #106
1 parent 9bf1c39 commit dca53a9

File tree

5 files changed

+58
-140
lines changed

5 files changed

+58
-140
lines changed

src/teradata_mcp_server/tools/base/base_tools.py

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import re
22
import logging
3-
from typing import Optional, Any, Dict, List
3+
from typing import Optional
44
from teradatasql import TeradataConnection
5-
import json
6-
from datetime import date, datetime
7-
from decimal import Decimal
85
from sqlalchemy import text
9-
from sqlalchemy.engine import Engine, Connection
6+
from sqlalchemy.engine import Connection
107
from sqlalchemy.engine import default
118
from teradata_mcp_server.tools.utils import serialize_teradata_types, rows_to_json, create_response
129

1310
logger = logging.getLogger("teradata_mcp_server")
1411

1512
#------------------ Tool ------------------#
13+
# Read query tool
1614
def handle_base_readQuery(
1715
conn: Connection,
1816
sql: str = None,
@@ -71,12 +69,11 @@ def handle_base_readQuery(
7169

7270
return create_response(data, metadata)
7371

74-
#------------------ Tool ------------------#
75-
# Write SQL execution tool
76-
from teradata_mcp_server.tools.utils import serialize_teradata_types, rows_to_json, create_response
77-
# table_name (str) - name of the table to get the definition for
78-
# Returns: ResponseType - formatted response with ddl results or error message
7972

73+
74+
75+
#------------------ Tool ------------------#
76+
# get DDL tool
8077
def handle_base_tableDDL(conn: TeradataConnection, db_name: str, table_name: str, *args, **kwargs):
8178
"""
8279
Displays the DDL definition of a table via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
@@ -112,11 +109,6 @@ def handle_base_tableDDL(conn: TeradataConnection, db_name: str, table_name: str
112109

113110
#------------------ Tool ------------------#
114111
# Read column description tool
115-
# Arguments:
116-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
117-
# db_name (str) - name of the database to list objects from
118-
# obj_name (str) - name of the object to list columns from
119-
# Returns: formatted response with list of columns and data types or error message
120112
def handle_base_columnDescription(conn: TeradataConnection, db_name: str, obj_name: str, *args, **kwargs):
121113
"""
122114
Shows detailed column information about a database table via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
@@ -197,11 +189,6 @@ def handle_base_columnDescription(conn: TeradataConnection, db_name: str, obj_na
197189

198190
#------------------ Tool ------------------#
199191
# Read table preview tool
200-
# Arguments:
201-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
202-
# db_name (str) - name of the database to list objects from
203-
# table_name (str) - name of the table to list columns from
204-
# Returns: formatted response string or error message
205192
def handle_base_tablePreview(conn: TeradataConnection, table_name: str, db_name: Optional[str] = None, *args, **kwargs):
206193
"""
207194
This function returns data sample and inferred structure from a database table or view via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
@@ -240,11 +227,6 @@ def handle_base_tablePreview(conn: TeradataConnection, table_name: str, db_name:
240227

241228
#------------------ Tool ------------------#
242229
# Read table affinity tool
243-
# Arguments:
244-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
245-
# db_name (str) - name of the database to list objects from
246-
# obj_name (str) - name of the object to list columns from
247-
# Returns: formatted response with list of tables and their usage or error message
248230
def handle_base_tableAffinity(conn: TeradataConnection, db_name: str, obj_name: str, *args, **kwargs):
249231
"""
250232
Get tables commonly used together by database users, this is helpful to infer relationships between tables via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
@@ -321,10 +303,6 @@ def handle_base_tableAffinity(conn: TeradataConnection, db_name: str, obj_name:
321303

322304
#------------------ Tool ------------------#
323305
# Read table usage tool
324-
# Arguments:
325-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
326-
# db_name (str) - name of the database to list objects from
327-
# Returns: formatted response with list of tables and their usage or error message
328306
def handle_base_tableUsage(conn: TeradataConnection, db_name: Optional[str] = None, *args, **kwargs):
329307
"""
330308
Measure the usage of a table and views by users in a given schema, this is helpful to infer what database objects are most actively used or drive most value via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
@@ -405,13 +383,6 @@ def handle_base_tableUsage(conn: TeradataConnection, db_name: Optional[str] = No
405383

406384
#------------------ Tool ------------------#
407385
# Dynamic SQL execution tool
408-
# This tool is used to execute dynamic SQL queries that are generated at runtime by a generator function.
409-
# This is not intended to be directly exposed as a tool, but used to build other tools.
410-
# Arguments:
411-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
412-
# sql_generator (callable) - a generator function that returns a SQL query string
413-
# *args - additional positional arguments to pass to the generator function
414-
# Returns: ResponseType - formatted response with query results or error message
415386
def util_base_dynamicQuery(conn: TeradataConnection, sql_generator: callable, *args, **kwargs):
416387
"""
417388
This tool is used to execute dynamic SQL queries that are generated at runtime by a generator function.

src/teradata_mcp_server/tools/dba/dba_tools.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import logging
22
from teradatasql import TeradataConnection
3-
from typing import Optional, Any, Dict, List
4-
import json
5-
from datetime import date, datetime
6-
from decimal import Decimal
3+
from typing import Optional, List
74

85
from teradata_mcp_server.tools.utils import serialize_teradata_types, rows_to_json, create_response
96

107
logger = logging.getLogger("teradata_mcp_server")
118

129
#------------------ Tool ------------------#
1310
# Get table SQL tool
14-
# Arguments:
15-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
16-
# user_name (str) - name of the user
17-
# Returns: formatted response with list of QueryText and UserIDs or error message
1811
def handle_dba_tableSqlList(conn: TeradataConnection, table_name: str, no_days: Optional[int], *args, **kwargs):
1912
"""
2013
Get a list of SQL run against a table in the last number of days.
@@ -51,11 +44,7 @@ def handle_dba_tableSqlList(conn: TeradataConnection, table_name: str, no_days:
5144
return create_response(data, metadata)
5245

5346
#------------------ Tool ------------------#
54-
# Get user SQL tool
55-
# Arguments:
56-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
57-
# user_name (str) - name of the user
58-
# Returns: formatted response with list of QueryText and UserIDs or error message
47+
# Get user SQL tool
5948
def handle_dba_userSqlList(conn: TeradataConnection, user_name: Optional[str] | None, no_days: Optional[int], *args, **kwargs):
6049
"""
6150
Get a list of SQL run by a user in the last number of days if a user name is provided, otherwise get list of all SQL in the last number of days.
@@ -98,12 +87,7 @@ def handle_dba_userSqlList(conn: TeradataConnection, user_name: Optional[str] |
9887

9988

10089
#------------------ Tool ------------------#
101-
# Get table space tool
102-
# Arguments:
103-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
104-
# table_name (str) - name of the table
105-
# db_name (str) - name of the database
106-
# Returns: formatted response with list of tables and space information or database and space used or error message
90+
# Get table space tool
10791
def handle_dba_tableSpace(conn: TeradataConnection, db_name: Optional[str] | None , table_name: Optional[str] | None, *args, **kwargs):
10892
"""
10993
Get table space used for a table if table name is provided or get table space for all tables in a database if a database name is provided."
@@ -161,11 +145,7 @@ def handle_dba_tableSpace(conn: TeradataConnection, db_name: Optional[str] | Non
161145

162146

163147
#------------------ Tool ------------------#
164-
# Get database space tool
165-
# Arguments:
166-
# conn (TeradataConnection) - Teradata connection object for executing SQL queries
167-
# db_name (str) - name of the database
168-
# Returns: formatted response with list of databases and space information or error message
148+
# Get database space tool
169149
def handle_dba_databaseSpace(conn: TeradataConnection, db_name: Optional[str] | None, *args, **kwargs):
170150
"""
171151
Get database space if database name is provided, otherwise get all databases space allocations.
@@ -218,8 +198,6 @@ def handle_dba_databaseSpace(conn: TeradataConnection, db_name: Optional[str] |
218198

219199
#------------------ Tool ------------------#
220200
# Resource usage summary tool
221-
# Arguments:
222-
# dimensions (List[str]) - list of dimensions to aggregate the resource usage summary. All dimensions are: ["LogDate", "hourOfDay", "dayOfWeek", "workloadType", "workloadComplexity", "UserName", "AppId", "StatementType"]
223201
def handle_dba_resusageSummary(conn: TeradataConnection,
224202
dimensions: Optional[List[str]] = None,
225203
user_name: Optional[str] = None,
@@ -348,9 +326,6 @@ def handle_dba_resusageSummary(conn: TeradataConnection,
348326

349327
#------------------ Tool ------------------#
350328
# Get table usage impact tool
351-
# Arguments:
352-
# db_name (str) - name of the database
353-
# user_name (str) - name of the user
354329
def handle_dba_tableUsageImpact(conn: TeradataConnection, db_name: Optional[str] = None, user_name: Optional[str] = None, *args, **kwargs):
355330
"""
356331
Measure the usage of a table and views by users, this is helpful to understand what user and tables are driving most resource usage at any point in time.

0 commit comments

Comments
 (0)