podbc_get_tables
Retrieve a list of tables and their details from a specified database schema using SQLAlchemy connectivity. Automatically defaults to the connection schema if none is provided.
Instructions
Retrieve and return a list containing information about tables in specified schema, if empty uses connection default
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Schema | No | ||
| url | No |
Implementation Reference
- mcp_sqlalchemy_server/server.py:81-84 (registration)Registers the 'podbc_get_tables' tool using the @mcp.tool decorator with name and description.@mcp.tool( name="podbc_get_tables", description="Retrieve and return a list containing information about tables in specified schema, if empty uses connection default" )
- mcp_sqlalchemy_server/server.py:85-114 (handler)The handler function that connects to the ODBC database, executes cursor.tables() to fetch tables in the specified catalog/schema, collects TABLE_CAT, TABLE_SCHEM, TABLE_NAME into a list of dicts, and returns formatted JSON.def podbc_get_tables(Schema: Optional[str] = None, user:Optional[str]=None, password:Optional[str]=None, dsn:Optional[str]=None) -> str: """ Retrieve and return a list containing information about tables. If `schema` is None, returns tables for all schemas. If `schema` is not None, returns tables for the specified schema. Args: schema (Optional[str]): The name of the schema to retrieve tables for. If None, retrieves tables for all schemas. user (Optional[str]=None): Optional username. password (Optional[str]=None): Optional password. dsn (Optional[str]=None): Optional dsn name. Returns: str: A list containing information about tables. """ cat = "%" if Schema is None else Schema try: with get_connection(True, user, password, dsn) as conn: cursor = conn.cursor() rs = cursor.tables(table=None, catalog=cat, schema="%", tableType="TABLE"); results = [] for row in rs: results.append({"TABLE_CAT":row[0], "TABLE_SCHEM":row[1], "TABLE_NAME":row[2]}) return json.dumps(results, indent=2) except pyodbc.Error as e: logging.error(f"Error retrieving tables: {e}") raise