@@ -287,7 +287,8 @@ async def get_database(
287
287
) -> DatabaseDetail :
288
288
client = create_client ()
289
289
req = dms_enterprise_20181101_models .GetDatabaseRequest (host = host , port = port , schema_name = schema_name )
290
- if sid : req .sid = sid
290
+ if sid :
291
+ req .sid = sid
291
292
try :
292
293
resp = client .get_database (req )
293
294
db_data = resp .body .to_map ().get ('Database' , {}) if resp and resp .body else {}
@@ -377,6 +378,67 @@ async def execute_script(
377
378
return "当前实例尚未开启安全托管功能。您可以通过DMS控制台免费开启「安全托管模式」。请注意,该操作需要管理员或DBA身份权限。"
378
379
379
380
381
+ async def create_data_change_order (
382
+ database_id : str = Field (description = "DMS databaseId" ),
383
+ script : str = Field (description = "SQL script to execute" ),
384
+ logic : bool = Field (default = False , description = "Whether to use logical execution mode" )
385
+ ) -> Dict [str , Any ]:
386
+
387
+ client = create_client ()
388
+ req = dms_enterprise_20181101_models .CreateDataCorrectOrderRequest ()
389
+ req .comment = "Data correct order submitted by MCP"
390
+
391
+ param = dms_enterprise_20181101_models .CreateDataCorrectOrderRequestParam ()
392
+ param .estimate_affect_rows = 1
393
+ param .sql_type = "TEXT"
394
+ param .exec_sql = script
395
+ param .classify = "MCP"
396
+
397
+ db_list = dms_enterprise_20181101_models .CreateDataCorrectOrderRequestParamDbItemList ()
398
+ db_list .db_id = database_id
399
+ db_list .logic = logic
400
+
401
+ db_items = [db_list ]
402
+ param .db_item_list = db_items
403
+
404
+ req .param = param
405
+ try :
406
+ resp = client .create_data_correct_order (req )
407
+ return resp .body
408
+ except Exception as e :
409
+ logger .error (f"Error in create_data_change_order: { e } " )
410
+ raise
411
+
412
+
413
+ async def get_order_base_info (
414
+ order_id : str = Field (description = "DMS order ID" )
415
+ ) -> Dict [str , Any ]:
416
+
417
+ client = create_client ()
418
+ req = dms_enterprise_20181101_models .GetOrderBaseInfoRequest ()
419
+ req .order_id = order_id
420
+ try :
421
+ resp = client .get_order_base_info (req )
422
+ return resp .body
423
+ except Exception as e :
424
+ logger .error (f"Error in get_order_base_info: { e } " )
425
+ raise
426
+
427
+
428
+ async def submit_order_approval (
429
+ order_id : str = Field (description = "DMS order ID" )
430
+ ) -> Dict [str , Any ]:
431
+
432
+ client = create_client ()
433
+ req = dms_enterprise_20181101_models .SubmitOrderApprovalRequest ()
434
+ req .order_id = order_id
435
+ try :
436
+ resp = client .submit_order_approval (req )
437
+ return resp .body
438
+ except Exception as e :
439
+ logger .error (f"Error in submit_order_approval: { e } " )
440
+ raise
441
+
380
442
async def nl2sql (
381
443
database_id : str = Field (description = "DMS databaseId" ),
382
444
question : str = Field (description = "Natural language question" ),
@@ -566,12 +628,28 @@ async def list_tables_configured(
566
628
annotations = {"title" : "Execute SQL (Pre-configured DB)" , "readOnlyHint" : False ,
567
629
"destructiveHint" : True })
568
630
async def execute_script_configured (
569
- script : str = Field (description = "SQL script to execute" ),
570
- logic : bool = Field (description = "Whether to use logical execution mode" , default = False )
631
+ script : str = Field (description = "SQL script to execute" )
571
632
) -> str :
572
- result_obj = await execute_script (database_id = self .default_database_id , script = script , logic = logic )
633
+ result_obj = await execute_script (database_id = self .default_database_id , script = script , logic = False )
573
634
return str (result_obj )
574
635
636
+ @self .mcp .tool (name = "createDataChangeOrder" ,
637
+ description = "Execute SQL changes through a data change order, and a corresponding order ID will be returned. "
638
+ "Prefer using the executeScript tool for SQL execution; "
639
+ "only use this tool when explicitly instructed to perform the operation via a order." ,
640
+ annotations = {"title" : "在DMS中创建数据变更工单" , "readOnlyHint" : False , "destructiveHint" : True })
641
+ async def create_data_change_order_configured (
642
+ script : str = Field (description = "SQL script to execute" )
643
+ ) -> str :
644
+ result_obj = await create_data_change_order (database_id = self .default_database_id , script = script , logic = False )
645
+ return str (result_obj )
646
+
647
+ self .mcp .tool (name = "getOrderInfo" , description = "Retrieve order information from DMS using the order ID." ,
648
+ annotations = {"title" : "获取DMS工单详情" , "readOnlyHint" : True })(get_order_base_info )
649
+
650
+ self .mcp .tool (name = "submitOrderApproval" , description = "Submit the order for approval in DMS using the order ID." ,
651
+ annotations = {"title" : "提交工单审批" , "readOnlyHint" : False })(submit_order_approval )
652
+
575
653
@self .mcp .tool (name = "askDatabase" ,
576
654
description = "Ask a question in natural language to the pre-configured database and get results directly." ,
577
655
annotations = {"title" : "Ask Pre-configured Database" , "readOnlyHint" : True })
@@ -655,6 +733,29 @@ async def execute_script_full_wrapper(
655
733
result_obj = await execute_script (database_id = database_id , script = script , logic = logic )
656
734
return str (result_obj )
657
735
736
+ @self .mcp .tool (name = "createDataChangeOrder" ,
737
+ description = "Execute SQL changes through a data change order, and a corresponding order ID will be returned. "
738
+ "Prefer using the executeScript tool for SQL execution; only use this tool when explicitly instructed to perform the operation via a order."
739
+ "If you don't know the databaseId, first use getDatabase or searchDatabase to retrieve it."
740
+ "(1)If you have the exact host, port, and database name, use getDatabase."
741
+ "(2)If you only know the database name, use searchDatabase."
742
+ "(3)If you don't know any information, ask the user to provide the necessary details."
743
+ "Note: searchDatabase may return multiple databases. In this case, let the user choose which one to use." ,
744
+ annotations = {"title" : "在DMS中创建数据变更工单" , "readOnlyHint" : False , "destructiveHint" : True })
745
+ async def create_data_change_order_wrapper (
746
+ database_id : str = Field (description = "Required DMS databaseId. Obtained via getDatabase tool" ),
747
+ script : str = Field (description = "SQL script to execute" ),
748
+ logic : bool = Field (description = "Whether to use logical execution mode" , default = False )
749
+ ) -> str : # Return string representation
750
+ result_obj = await create_data_change_order (database_id = database_id , script = script , logic = logic )
751
+ return str (result_obj )
752
+
753
+ self .mcp .tool (name = "getOrderInfo" , description = "Retrieve order information from DMS using the order ID." ,
754
+ annotations = {"title" : "获取DMS工单详情" , "readOnlyHint" : True })(get_order_base_info )
755
+
756
+ self .mcp .tool (name = "submitOrderApproval" , description = "Submit the order for approval in DMS using the order ID." ,
757
+ annotations = {"title" : "提交工单审批" , "readOnlyHint" : False })(submit_order_approval )
758
+
658
759
self .mcp .tool (name = "generateSql" , description = "Generate SELECT-type SQL queries from natural language input." ,
659
760
annotations = {"title" : "自然语言转SQL (DMS)" , "readOnlyHint" : True })(nl2sql )
660
761
0 commit comments