getDatabase
Retrieve detailed database information, including schema and connection details, by providing the host, port, and schema name using the Alibaba Cloud DMS MCP Server tool.
Instructions
Obtain detailed information about a specific database in DMS when the host and port are provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | Hostname or IP of the database instance | |
| port | Yes | Connection port number | |
| schema_name | Yes | Name of the database schema | |
| sid | No | Required for Oracle like databases |
Implementation Reference
- The core handler function implementing the 'getDatabase' tool logic. It creates a DMS client, constructs a GetDatabaseRequest with host, port, schema_name (and optional sid), calls the API, parses the response into a DatabaseDetail model, and handles errors.async def get_database( host: str = Field(description="Hostname or IP of the database instance"), port: str = Field(description="Connection port number"), schema_name: str = Field(description="Name of the database schema"), sid: Optional[str] = Field(default=None, description="Required for Oracle like databases") ) -> DatabaseDetail: client = create_client() req = dms_enterprise_20181101_models.GetDatabaseRequest(host=host, port=port, schema_name=schema_name) if sid: req.sid = sid if mcp.state.real_login_uid: req.real_login_user_uid = mcp.state.real_login_uid try: resp = client.get_database(req) db_data = resp.body.to_map().get('Database', {}) if resp and resp.body else {} return DatabaseDetail(**db_data) except Exception as e: logger.error(f"Error in get_database: {e}") raise
- src/alibabacloud_dms_mcp_server/server.py:704-706 (registration)Registration of the 'getDatabase' tool in the ToolRegistry's _register_full_toolset method, associating the tool name with the get_database handler function, including description and read-only annotation.description="Obtain detailed information about a specific database in DMS when the host and port are provided.", annotations={"title": "获取DMS数据库详情", "readOnlyHint": True})(get_database) self.mcp.tool(name="listTables",
- Pydantic model used as the return type for the get_database handler, defining the structure and descriptions for the output schema including DatabaseId, SchemaName, DbType, InstanceAlias, InstanceId, and State.class DatabaseDetail(MyBaseModel): DatabaseId: Any = Field(description="Unique database identifier in DMS", default=None) SchemaName: Any = Field(description="Name of the database schema", default=None) DbType: Any = Field(description="Database Engine type", default=None) InstanceAlias: Any = Field(description="Instance alias in DMS", default=None) InstanceId: Any = Field(description="Instance identifier in DMS", default=None) State: Any = Field(description="Current operational status", default=None)