@@ -486,17 +486,15 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
486486 enabled bool
487487 ddl bool
488488 insert bool
489- toolName string // Added for MCP routing
490489 api string
491490 requestHeader map [string ]string
492- requestBody string // Changed to string to support dual-routing
491+ requestBody string // Changed to string to easily route to MCP or API
493492 want string
494493 isErr bool
495494 }{
496495 {
497496 name : "invoke create-table-templateParams-tool" ,
498497 ddl : true ,
499- toolName : "create-table-templateParams-tool" ,
500498 api : "http://127.0.0.1:5000/api/tool/create-table-templateParams-tool/invoke" ,
501499 requestHeader : map [string ]string {},
502500 requestBody : fmt .Sprintf (`{"tableName": "%s", "columns":%s}` , tableName , configs .createColArray ),
@@ -506,7 +504,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
506504 {
507505 name : "invoke insert-table-templateParams-tool" ,
508506 insert : true ,
509- toolName : "insert-table-templateParams-tool" ,
510507 api : "http://127.0.0.1:5000/api/tool/insert-table-templateParams-tool/invoke" ,
511508 requestHeader : map [string ]string {},
512509 requestBody : fmt .Sprintf (`{"tableName": "%s", "columns":["id","name","age"], "values":"1, 'Alex', 21"}` , tableName ),
@@ -516,7 +513,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
516513 {
517514 name : "invoke insert-table-templateParams-tool" ,
518515 insert : true ,
519- toolName : "insert-table-templateParams-tool" ,
520516 api : "http://127.0.0.1:5000/api/tool/insert-table-templateParams-tool/invoke" ,
521517 requestHeader : map [string ]string {},
522518 requestBody : fmt .Sprintf (`{"tableName": "%s", "columns":["id","name","age"], "values":"2, 'Alice', 100"}` , tableName ),
@@ -525,7 +521,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
525521 },
526522 {
527523 name : "invoke select-templateParams-tool" ,
528- toolName : "select-templateParams-tool" ,
529524 api : "http://127.0.0.1:5000/api/tool/select-templateParams-tool/invoke" ,
530525 requestHeader : map [string ]string {},
531526 requestBody : fmt .Sprintf (`{"tableName": "%s"}` , tableName ),
@@ -534,7 +529,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
534529 },
535530 {
536531 name : "invoke select-templateParams-combined-tool" ,
537- toolName : "select-templateParams-combined-tool" ,
538532 api : "http://127.0.0.1:5000/api/tool/select-templateParams-combined-tool/invoke" ,
539533 requestHeader : map [string ]string {},
540534 requestBody : fmt .Sprintf (`{"id": 1, "tableName": "%s"}` , tableName ),
@@ -543,7 +537,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
543537 },
544538 {
545539 name : "invoke select-templateParams-combined-tool with no results" ,
546- toolName : "select-templateParams-combined-tool" ,
547540 api : "http://127.0.0.1:5000/api/tool/select-templateParams-combined-tool/invoke" ,
548541 requestHeader : map [string ]string {},
549542 requestBody : fmt .Sprintf (`{"id": 999, "tableName": "%s"}` , tableName ),
@@ -553,7 +546,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
553546 {
554547 name : "invoke select-fields-templateParams-tool" ,
555548 enabled : configs .supportSelectFields ,
556- toolName : "select-fields-templateParams-tool" ,
557549 api : "http://127.0.0.1:5000/api/tool/select-fields-templateParams-tool/invoke" ,
558550 requestHeader : map [string ]string {},
559551 requestBody : fmt .Sprintf (`{"tableName": "%s", "fields":%s}` , tableName , configs .nameFieldArray ),
@@ -562,7 +554,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
562554 },
563555 {
564556 name : "invoke select-filter-templateParams-combined-tool" ,
565- toolName : "select-filter-templateParams-combined-tool" ,
566557 api : "http://127.0.0.1:5000/api/tool/select-filter-templateParams-combined-tool/invoke" ,
567558 requestHeader : map [string ]string {},
568559 requestBody : fmt .Sprintf (`{"name": "Alex", "tableName": "%s", "columnFilter": "%s"}` , tableName , configs .nameColFilter ),
@@ -572,7 +563,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
572563 {
573564 name : "invoke drop-table-templateParams-tool" ,
574565 ddl : true ,
575- toolName : "drop-table-templateParams-tool" ,
576566 api : "http://127.0.0.1:5000/api/tool/drop-table-templateParams-tool/invoke" ,
577567 requestHeader : map [string ]string {},
578568 requestBody : fmt .Sprintf (`{"tableName": "%s"}` , tableName ),
@@ -597,14 +587,18 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
597587 var got string
598588
599589 if configs .IsMCP {
590+ // Extract toolName from API path
591+ parts := strings .Split (tc .api , "/" )
592+ toolName := parts [len (parts )- 2 ]
593+
600594 var args map [string ]any
601595 if tc .requestBody != "" {
602596 if err := json .Unmarshal ([]byte (tc .requestBody ), & args ); err != nil {
603597 t .Fatalf ("failed to unmarshal request body for MCP args: %v" , err )
604598 }
605599 }
606600
607- statusCode , mcpResp , err := InvokeMCPTool (t , tc . toolName , args , nil )
601+ statusCode , mcpResp , err := InvokeMCPTool (t , toolName , args , nil )
608602 if statusCode != http .StatusOK {
609603 if tc .isErr {
610604 return
@@ -618,8 +612,6 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
618612 blocks = append (blocks , strings .TrimSpace (content .Text ))
619613 }
620614 }
621-
622- // Safely map MCP empty responses back to legacy API's "null"
623615 if len (blocks ) == 0 {
624616 got = "null"
625617 } else {
@@ -650,8 +642,8 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
650642 }
651643 }
652644
645+ // JSON-Aware Comparison
653646 if got != tc .want {
654- // JSON Aware comparision
655647 var gotJSON , wantJSON any
656648 errGot := json .Unmarshal ([]byte (got ), & gotJSON )
657649 errWant := json .Unmarshal ([]byte (tc .want ), & wantJSON )
@@ -661,8 +653,7 @@ func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options
661653 t .Fatalf ("unexpected JSON value mismatch (-want +got):\n %s\n Raw got: %s\n Raw want: %s" , diff , got , tc .want )
662654 }
663655 } else {
664- // Fallback to strict string error if they weren't valid JSON arrays/objects
665- t .Fatalf ("unexpected string value: got %q, want %q" , got , tc .want )
656+ t .Fatalf ("unexpected value: got %q, want %q" , got , tc .want )
666657 }
667658 }
668659 }
0 commit comments