addInstance
Add Alibaba Cloud database instances to DMS for cross-engine data querying using credentials and connection details.
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_user | Yes | The username used to connect to the database | |
| db_password | Yes | The password used to connect to the database | |
| instance_resource_id | No | Aliyun instance resource ID | |
| host | No | The hostname of the database instance | |
| port | No | The connection port number | |
| region | No | The region (e.g., 'cn-hangzhou') |
Implementation Reference
- The main handler function for the 'addInstance' tool. It validates inputs, creates a DMS client, constructs a SimplyAddInstanceRequest, calls the Alibaba Cloud API, parses the response into an InstanceInfo model, and handles errors.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 FastMCP server within the _register_full_toolset method, specifying name, description, annotations, and linking to the add_instance handler function.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 containing key instance details like ID, host, and port.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)