listTables
Search and retrieve table information from Alibaba Cloud DMS databases using database IDs and optional table name filters to manage database metadata.
Instructions
Search for tables by databaseId and (optional) table name. If you don't know the databaseId, first use getDatabase or searchDatabase to retrieve it. (1) If you have the exact host, port, and database name, use getDatabase. (2) If you only know the database name, use searchDatabase. (3) If you don't know any information, ask the user to provide the necessary details. Note: searchDatabase may return multiple databases. In this case, let the user choose which one to use.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database_id | Yes | DMS databaseId | |
| search_name | No | Optional: Search keyword for table names | |
| page_number | No | Pagination page number | |
| page_size | No | Results per page (max 200) |
Implementation Reference
- The core handler function that lists tables by calling the Alibaba Cloud DMS Enterprise API's list_tables method. This is the primary logic for the tool.async def list_tables( # Renamed from listTable to follow convention database_id: str = Field(description="DMS databaseId"), search_name: Optional[str] = Field(default=None, description="Optional: Search keyword for table names"), page_number: int = Field(default=1, description="Pagination page number"), page_size: int = Field(default=200, description="Results per page (max 200)") ) -> Dict[str, Any]: if not search_name: search_name = "%" client = create_client() req = dms_enterprise_20181101_models.ListTablesRequest(database_id=database_id, search_name=search_name, page_number=page_number, page_size=page_size, return_guid=True) if mcp.state.real_login_uid: req.real_login_user_uid = mcp.state.real_login_uid try: resp = client.list_tables(req) return resp.body.to_map() if resp and resp.body else {} except Exception as e: logger.error(f"Error in list_tables: {e}") raise
- src/alibabacloud_dms_mcp_server/server.py:570-583 (registration)Registration of the listTables tool in the configured database mode. This wrapper function automatically uses the pre-configured default_database_id.@self.mcp.tool(name="listTables", description="Lists tables in the database. Search by name is supported.", annotations={"title": "List Tables (Pre-configured DB)", "readOnlyHint": True}) async def list_tables_configured( search_name: Optional[str] = Field(default=None, description="Optional: A string used as the search keyword to match table names."), page_number: int = Field(description="Pagination page number", default=1), page_size: int = Field(description="Number of results per page", default=200) ) -> Dict[str, Any]: if not search_name: search_name = "%" return await list_tables(database_id=self.default_database_id, search_name=search_name, page_number=page_number, page_size=page_size)
- src/alibabacloud_dms_mcp_server/server.py:706-709 (registration)Direct registration of the core list_tables handler as the listTables tool in the full toolset mode (when no default database is configured).self.mcp.tool(name="listTables", description=f"Search for tables by databaseId and (optional) table name. " f"{DATABASE_ID_DESCRIPTION}", annotations={"title": "列出DMS表", "readOnlyHint": True})(list_tables)