|
14 | 14 | from alibabacloud_dms_enterprise20181101.client import Client as dms_enterprise20181101Client |
15 | 15 | from alibabacloud_tea_openapi import models as open_api_models |
16 | 16 | from alibabacloud_dms_enterprise20181101 import models as dms_enterprise_20181101_models |
17 | | -from alibabacloud_dts20200101 import models as dts_20200101_models |
18 | | -from alibabacloud_dts20200101.client import Client as DtsClient |
19 | 17 | from alibabacloud_tea_openapi.models import Config |
20 | 18 | from alibabacloud_tea_util import models as util_models |
21 | 19 |
|
@@ -158,21 +156,6 @@ def create_client() -> dms_enterprise20181101Client: |
158 | 156 | config.user_agent = "dms-mcp" |
159 | 157 | return dms_enterprise20181101Client(config) |
160 | 158 |
|
161 | | - |
162 | | -def get_dts_client(region_id: str): |
163 | | - config = Config( |
164 | | - access_key_id=os.getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), |
165 | | - access_key_secret=os.getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'), |
166 | | - security_token=os.getenv('ALIBABA_CLOUD_SECURITY_TOKEN'), |
167 | | - region_id=region_id, |
168 | | - protocol="https", |
169 | | - connect_timeout=10 * 1000, |
170 | | - read_timeout=300 * 1000 |
171 | | - ) |
172 | | - client = DtsClient(config) |
173 | | - return client |
174 | | - |
175 | | - |
176 | 159 | async def add_instance( |
177 | 160 | db_user: str = Field(description="The username used to connect to the database"), |
178 | 161 | db_password: str = Field(description="The password used to connect to the database"), |
@@ -416,137 +399,6 @@ async def nl2sql( |
416 | 399 | logger.error(f"Error in nl2sql_explicit_db: {e}") |
417 | 400 | raise |
418 | 401 |
|
419 | | - |
420 | | -async def configureDtsJob( |
421 | | - region_id: str = Field(description="The region id of the dts job (e.g., 'cn-hangzhou')"), |
422 | | - job_type: str = Field( |
423 | | - description="The type of job (synchronization job: SYNC, migration job: MIGRATION, data check job: CHECK)"), |
424 | | - source_endpoint_region: str = Field(description="The source endpoint region ID"), |
425 | | - source_endpoint_instance_type: str = Field( |
426 | | - description="The source endpoint instance type (RDS, ECS, EXPRESS, CEN, DG)"), |
427 | | - source_endpoint_engine_name: str = Field( |
428 | | - description="The source endpoint engine name (MySQL, PostgreSQL, SQLServer)"), |
429 | | - source_endpoint_instance_id: str = Field(description="The source endpoint instance ID (e.g., 'rm-xxx')"), |
430 | | - source_endpoint_user_name: str = Field(description="The source endpoint user name"), |
431 | | - source_endpoint_password: str = Field(description="The source endpoint password"), |
432 | | - destination_endpoint_region: str = Field(description="The destination endpoint region ID"), |
433 | | - destination_endpoint_instance_type: str = Field( |
434 | | - description="The destination endpoint instance type (RDS, ECS, EXPRESS, CEN, DG)"), |
435 | | - destination_endpoint_engine_name: str = Field( |
436 | | - description="The destination endpoint engine name (MySQL, PostgreSQL, SQLServer)"), |
437 | | - destination_endpoint_instance_id: str = Field( |
438 | | - description="The destination endpoint instance ID (e.g., 'rm-xxx')"), |
439 | | - destination_endpoint_user_name: str = Field(description="The destination endpoint user name"), |
440 | | - destination_endpoint_password: str = Field(description="The destination endpoint password"), |
441 | | - db_list: Dict[str, Any] = Field( |
442 | | - description='The database objects in JSON format, example 1: migration dtstest database, db_list should like {"dtstest":{"name":"dtstest","all":true}}; example 2: migration one table task01 in dtstest database, db_list should like {"dtstest":{"name":"dtstest","all":false,"Table":{"task01":{"name":"task01","all":true}}}}; example 3: migration two tables task01 and task02 in dtstest database, db_list should like {"dtstest":{"name":"dtstest","all":false,"Table":{"task01":{"name":"task01","all":true},"task02":{"name":"task02","all":true}}}}') |
443 | | -) -> Dict[str, Any]: |
444 | | - try: |
445 | | - db_list_str = json.dumps(db_list, separators=(',', ':')) |
446 | | - logger.info(f"Configure dts job with db_list: {db_list_str}") |
447 | | - |
448 | | - # init dts client |
449 | | - client = get_dts_client(region_id) |
450 | | - runtime = util_models.RuntimeOptions() |
451 | | - |
452 | | - # create dts instance |
453 | | - create_dts_instance_request = dts_20200101_models.CreateDtsInstanceRequest( |
454 | | - region_id=region_id, |
455 | | - type=job_type, |
456 | | - source_region=source_endpoint_region, |
457 | | - destination_region=destination_endpoint_region, |
458 | | - source_endpoint_engine_name=source_endpoint_engine_name, |
459 | | - destination_endpoint_engine_name=destination_endpoint_engine_name, |
460 | | - pay_type='PostPaid', |
461 | | - quantity=1, |
462 | | - min_du=1, |
463 | | - max_du=4, |
464 | | - instance_class='micro' |
465 | | - ) |
466 | | - |
467 | | - create_dts_instance_response = client.create_dts_instance_with_options(create_dts_instance_request, runtime) |
468 | | - logger.info(f"Create dts instance response: {create_dts_instance_response.body.to_map()}") |
469 | | - dts_job_id = create_dts_instance_response.body.to_map()['JobId'] |
470 | | - |
471 | | - # configure dts job |
472 | | - ran_job_name = 'dtsmcp-' + ''.join(random.sample(string.ascii_letters + string.digits, 6)) |
473 | | - custom_reserved = json.loads(g_reserved) |
474 | | - dts_mcp_channel = os.getenv('DTS_MCP_CHANNEL') |
475 | | - if dts_mcp_channel and len(dts_mcp_channel) > 0: |
476 | | - logger.info(f"Configure dts job with custom dts mcp channel: {dts_mcp_channel}") |
477 | | - custom_reserved['channelInfo'] = dts_mcp_channel |
478 | | - custom_reserved_str = json.dumps(custom_reserved, separators=(',', ':')) |
479 | | - logger.info(f"Configure dts job with reserved: {custom_reserved_str}") |
480 | | - configure_dts_job_request = dts_20200101_models.ConfigureDtsJobRequest( |
481 | | - region_id=region_id, |
482 | | - dts_job_name=ran_job_name, |
483 | | - source_endpoint_instance_type=source_endpoint_instance_type, |
484 | | - source_endpoint_engine_name=source_endpoint_engine_name, |
485 | | - source_endpoint_instance_id=source_endpoint_instance_id, |
486 | | - source_endpoint_region=source_endpoint_region, |
487 | | - source_endpoint_user_name=source_endpoint_user_name, |
488 | | - source_endpoint_password=source_endpoint_password, |
489 | | - destination_endpoint_instance_type=destination_endpoint_instance_type, |
490 | | - destination_endpoint_instance_id=destination_endpoint_instance_id, |
491 | | - destination_endpoint_engine_name=destination_endpoint_engine_name, |
492 | | - destination_endpoint_region=destination_endpoint_region, |
493 | | - destination_endpoint_user_name=destination_endpoint_user_name, |
494 | | - destination_endpoint_password=destination_endpoint_password, |
495 | | - structure_initialization=True, |
496 | | - data_initialization=True, |
497 | | - data_synchronization=False, |
498 | | - job_type=job_type, |
499 | | - db_list=db_list_str, |
500 | | - reserve=custom_reserved_str |
501 | | - ) |
502 | | - |
503 | | - if dts_job_id and len(dts_job_id) > 0: |
504 | | - configure_dts_job_request.dts_job_id = dts_job_id |
505 | | - |
506 | | - configure_dts_job_response = client.configure_dts_job_with_options(configure_dts_job_request, runtime) |
507 | | - logger.info(f"Configure dts job response: {configure_dts_job_response.body.to_map()}") |
508 | | - return configure_dts_job_response.body.to_map() |
509 | | - except Exception as e: |
510 | | - logger.error(f"Error occurred while configure dts job: {str(e)}") |
511 | | - raise e |
512 | | - |
513 | | - |
514 | | -async def startDtsJob( |
515 | | - region_id: str = Field(description="The region id of the dts job (e.g., 'cn-hangzhou')"), |
516 | | - dts_job_id: str = Field(description="The job id of the dts job") |
517 | | -) -> Dict[str, Any]: |
518 | | - try: |
519 | | - client = get_dts_client(region_id) |
520 | | - request = dts_20200101_models.StartDtsJobRequest( |
521 | | - region_id=region_id, |
522 | | - dts_job_id=dts_job_id |
523 | | - ) |
524 | | - runtime = util_models.RuntimeOptions() |
525 | | - response = client.start_dts_job_with_options(request, runtime) |
526 | | - return response.body.to_map() |
527 | | - except Exception as e: |
528 | | - logger.error(f"Error occurred while start dts job: {str(e)}") |
529 | | - raise e |
530 | | - |
531 | | - |
532 | | -async def getDtsJob( |
533 | | - region_id: str = Field(description="The region id of the dts job (e.g., 'cn-hangzhou')"), |
534 | | - dts_job_id: str = Field(description="The job id of the dts job") |
535 | | -) -> Dict[str, Any]: |
536 | | - try: |
537 | | - client = get_dts_client(region_id) |
538 | | - request = dts_20200101_models.DescribeDtsJobDetailRequest( |
539 | | - region_id=region_id, |
540 | | - dts_job_id=dts_job_id |
541 | | - ) |
542 | | - runtime = util_models.RuntimeOptions() |
543 | | - response = client.describe_dts_job_detail_with_options(request, runtime) |
544 | | - return response.body.to_map() |
545 | | - except Exception as e: |
546 | | - logger.error(f"Error occurred while describe dts job detail: {str(e)}") |
547 | | - raise e |
548 | | - |
549 | | - |
550 | 402 | # --- ToolRegistry Class --- |
551 | 403 | class ToolRegistry: |
552 | 404 | def __init__(self, mcp: FastMCP): |
@@ -621,14 +473,6 @@ async def ask_database_configured( |
621 | 473 | return AskDatabaseResult(executed_sql=generated_sql, |
622 | 474 | execution_result=f"Error: An issue occurred while executing the query: {str(e)}") |
623 | 475 |
|
624 | | - self.mcp.tool(name="configureDtsJob", description="Configure a dts job.", |
625 | | - annotations={"title": "配置DTS任务", "readOnlyHint": False, "destructiveHint": True})( |
626 | | - configureDtsJob) |
627 | | - self.mcp.tool(name="startDtsJob", description="Start a dts job.", |
628 | | - annotations={"title": "启动DTS任务", "readOnlyHint": False, "destructiveHint": True})(startDtsJob) |
629 | | - self.mcp.tool(name="getDtsJob", description="Get a dts job detail information.", |
630 | | - annotations={"title": "查询DTS任务详细信息", "readOnlyHint": True})(getDtsJob) |
631 | | - |
632 | 476 | def _register_full_toolset(self): |
633 | 477 | self.mcp.tool(name="addInstance", |
634 | 478 | description="Add an instance to DMS. The username and password are required. " |
@@ -680,14 +524,6 @@ async def execute_script_full_wrapper( |
680 | 524 | self.mcp.tool(name="generateSql", description="Generate SELECT-type SQL queries from natural language input.", |
681 | 525 | annotations={"title": "自然语言转SQL (DMS)", "readOnlyHint": True})(nl2sql) |
682 | 526 |
|
683 | | - self.mcp.tool(name="configureDtsJob", description="Configure a dts job.", |
684 | | - annotations={"title": "配置DTS任务", "readOnlyHint": False, "destructiveHint": True})( |
685 | | - configureDtsJob) |
686 | | - self.mcp.tool(name="startDtsJob", description="Start a dts job.", |
687 | | - annotations={"title": "启动DTS任务", "readOnlyHint": False, "destructiveHint": True})(startDtsJob) |
688 | | - self.mcp.tool(name="getDtsJob", description="Get a dts job detail information.", |
689 | | - annotations={"title": "查询DTS任务详细信息", "readOnlyHint": True})(getDtsJob) |
690 | | - |
691 | 527 |
|
692 | 528 | # --- Lifespan Function --- |
693 | 529 | @asynccontextmanager |
|
0 commit comments