searchDatabase
Query and locate databases by name within Alibaba Cloud DMS MCP Server, enabling efficient search across diverse database ecosystems with customizable pagination.
Instructions
Search databases in DMS by name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_number | No | Page number (starting from 1) | |
| page_size | No | Results per page (max 1000) | |
| search_key | Yes | database name to search for |
Implementation Reference
- The core handler function that implements the searchDatabase tool. It creates a DMS client, sends a SearchDatabaseRequest with the provided search_key and pagination parameters, processes the response into DatabaseInfo objects, handling schema name formatting, and returns the list of matching databases.async def search_database( search_key: str = Field(description="database name to search for"), page_number: int = Field(default=1, description="Page number (starting from 1)"), page_size: int = Field(default=200, description="Results per page (max 1000)") ) -> List[DatabaseInfo]: client = create_client() req = dms_enterprise_20181101_models.SearchDatabaseRequest(search_key=search_key, page_number=page_number, page_size=page_size) if mcp.state.real_login_uid: req.real_login_user_uid = mcp.state.real_login_uid try: resp = client.search_database(req) if not resp or not resp.body: return [] db_list_data = resp.body.to_map().get('SearchDatabaseList', {}).get('SearchDatabase', []) result = [] for db in db_list_data: db_info_map = {"DatabaseId": db.get("DatabaseId"), "Host": db.get("Host"), "Port": db.get("Port"), "DbType": db.get("DbType")} db_info_map["SchemaName"] = f'{db.get("CatalogName", "")}.{db.get("SchemaName", "")}' if db.get( "CatalogName") != 'def' else db.get("SchemaName", "") result.append(DatabaseInfo(**db_info_map)) return result except Exception as e: logger.error(f"Error in search_database: {e}") raise
- src/alibabacloud_dms_mcp_server/server.py:701-702 (registration)Registers the search_database function as the MCP tool named 'searchDatabase' with description and annotations.self.mcp.tool(name="searchDatabase", description="Search databases in DMS by name.", annotations={"title": "搜索DMS数据库", "readOnlyHint": True})(search_database)
- Pydantic model defining the output schema for database search results, used by the handler to structure returned data.class DatabaseInfo(MyBaseModel): DatabaseId: Any = Field(description="Unique database identifier in DMS") Host: Any = Field(description="Hostname or IP address of the database instance") Port: Any = Field(description="Connection port number") DbType: Any = Field(description="Database Engine type") SchemaName: Any = Field(description="Name of the database schema")