addInstance
Add an Aliyun database instance to Alibaba Cloud DMS by providing username, password, and either instance resource ID or host and port. Automatically retrieves existing instance information if already added.
Instructions
Add an instance to DMS. The username and password are required. Only Aliyun instances are supported. Either instance_resource_id or host and port must be provided. The region is optional, but it's recommended to include it.If the instance already exists, it will return the existing instance information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| db_password | Yes | The password used to connect to the database | |
| db_user | Yes | The username used to connect to the database | |
| host | No | The hostname of the database instance | |
| instance_resource_id | No | Aliyun instance resource ID | |
| port | No | The connection port number | |
| region | No | The region (e.g., 'cn-hangzhou') |
Implementation Reference
- The handler function that implements the core logic of the 'addInstance' tool. It validates inputs, creates a DMS client, builds the SimplyAddInstanceRequest, calls the Alibaba Cloud API, and returns an InstanceInfo object or raises an error.async def add_instance( db_user: str = Field(description="The username used to connect to the database"), db_password: str = Field(description="The password used to connect to the database"), instance_resource_id: Optional[str] = Field(default=None, description="Aliyun instance resource ID"), host: Optional[str] = Field(default=None, description="The hostname of the database instance"), port: Optional[str] = Field(default=None, description="The connection port number"), region: Optional[str] = Field(default=None, description="The region (e.g., 'cn-hangzhou')") ) -> InstanceInfo: if not db_user or not isinstance(db_user, str): raise ValueError("db_user must be a non-empty string") if not db_password or not isinstance(db_password, str): raise ValueError("db_password must be a non-empty string") client = create_client() req = dms_enterprise_20181101_models.SimplyAddInstanceRequest(database_user=db_user, database_password=db_password) if host: req.host = host if port: req.port = port if instance_resource_id: req.instance_id = instance_resource_id if region: req.region = region if mcp.state.real_login_uid: req.real_login_user_uid = mcp.state.real_login_uid try: resp = client.simply_add_instance(req) if resp and resp.body: body_dict = resp.body.to_map() return InstanceInfo(**(body_dict['Instance'] if 'Instance' in body_dict else body_dict)) else: return InstanceInfo() except Exception as e: logger.error(f"Error in add_instance: {e}") raise
- src/alibabacloud_dms_mcp_server/server.py:688-695 (registration)The registration of the 'addInstance' tool in the full toolset using FastMCP's tool decorator, binding it to the add_instance handler.self.mcp.tool(name="addInstance", description="Add an instance to DMS. The username and password are required. " "Only Aliyun instances are supported. " "Either instance_resource_id or host and port must be provided. " "The region is optional, but it's recommended to include it." "If the instance already exists, it will return the existing instance information.", annotations={"title": "添加或获取DMS实例", "readOnlyHint": False, "destructiveHint": False})( add_instance)
- Pydantic model defining the output schema for the 'addInstance' tool, used to structure the response from the DMS API.class InstanceInfo(MyBaseModel): InstanceId: Any = Field(description="Unique instance identifier in DMS", default=None) Host: Any = Field(description="The hostname of the database instance", default=None) Port: Any = Field(description="The connection port number", default=None)
- Input parameter definitions with Pydantic Field descriptions serving as the input schema for the 'addInstance' tool.db_user: str = Field(description="The username used to connect to the database"), db_password: str = Field(description="The password used to connect to the database"), instance_resource_id: Optional[str] = Field(default=None, description="Aliyun instance resource ID"), host: Optional[str] = Field(default=None, description="The hostname of the database instance"), port: Optional[str] = Field(default=None, description="The connection port number"), region: Optional[str] = Field(default=None, description="The region (e.g., 'cn-hangzhou')") ) -> InstanceInfo: