@@ -453,6 +453,12 @@ function MainView:setup_active_mode()
453
453
end ,
454
454
desc = " Toggle" ,
455
455
},
456
+ [" a" ] = {
457
+ action = function ()
458
+ self :handle_auto_approve_toggle ()
459
+ end ,
460
+ desc = " Auto-approve" ,
461
+ },
456
462
[" h" ] = {
457
463
action = function ()
458
464
self :handle_collapse ()
@@ -483,6 +489,137 @@ function MainView:setup_active_mode()
483
489
self :apply_keymaps ()
484
490
end
485
491
492
+ -- Helper function to get all tool names for a server
493
+ local function get_server_tool_names (server_name )
494
+ local tools = {}
495
+
496
+ -- Check if it's a native server
497
+ local is_native = native .is_native_server (server_name )
498
+ if is_native then
499
+ local native_server = is_native
500
+ for _ , tool in ipairs (native_server .capabilities .tools or {}) do
501
+ table.insert (tools , tool .name )
502
+ end
503
+ else
504
+ -- Regular MCP server
505
+ for _ , server in ipairs (State .server_state .servers ) do
506
+ if server .name == server_name and server .capabilities then
507
+ for _ , tool in ipairs (server .capabilities .tools or {}) do
508
+ table.insert (tools , tool .name )
509
+ end
510
+ break
511
+ end
512
+ end
513
+ end
514
+
515
+ return tools
516
+ end
517
+
518
+ -- Helper function to determine actual auto-approval status
519
+ local function get_auto_approval_status (server_config , all_tools )
520
+ local auto_approve = server_config .autoApprove
521
+
522
+ if auto_approve == true then
523
+ return " all" , # all_tools -- All tools auto-approved
524
+ elseif type (auto_approve ) == " table" and vim .islist (auto_approve ) then
525
+ if # auto_approve == 0 then
526
+ return " none" , 0
527
+ elseif # auto_approve == # all_tools then
528
+ return " all" , # all_tools -- All tools are in the list
529
+ else
530
+ return " partial" , # auto_approve -- Some tools auto-approved
531
+ end
532
+ else
533
+ return " none" , 0 -- No auto-approval
534
+ end
535
+ end
536
+
537
+ function MainView :handle_auto_approve_toggle ()
538
+ -- Get current line
539
+ local cursor = vim .api .nvim_win_get_cursor (0 )
540
+ local line = cursor [1 ]
541
+
542
+ -- Get line info
543
+ local type , context = self :get_line_info (line )
544
+ if not type or not context or not State .hub_instance then
545
+ return
546
+ end
547
+
548
+ if type == " server" then
549
+ -- Check if server is enabled
550
+ if context .status == " disabled" or context .status == " disconnected" then
551
+ return
552
+ end
553
+
554
+ -- Toggle auto-approval for entire server
555
+ local server_name = context .name
556
+ local is_native = native .is_native_server (server_name )
557
+ local server_config = (
558
+ is_native and State .native_servers_config [server_name ] or State .servers_config [server_name ]
559
+ ) or {}
560
+
561
+ local all_tools = get_server_tool_names (server_name )
562
+ local status , _ = get_auto_approval_status (server_config , all_tools )
563
+ local new_auto_approve
564
+
565
+ if status == " all" then
566
+ -- Currently auto-approving all tools, turn off
567
+ new_auto_approve = {}
568
+ else
569
+ -- Currently partial or no auto-approval, enable for all
570
+ new_auto_approve = vim .deepcopy (all_tools )
571
+ end
572
+
573
+ State .hub_instance :update_server_config (server_name , {
574
+ autoApprove = new_auto_approve ,
575
+ })
576
+ elseif type == " tool" and context then
577
+ -- Check if tool is enabled
578
+ if context .disabled then
579
+ return
580
+ end
581
+
582
+ -- Toggle auto-approval for specific tool
583
+ local server_name = context .server_name
584
+ local tool_name = context .def .name
585
+ local is_native = native .is_native_server (server_name )
586
+ local server_config = (
587
+ is_native and State .native_servers_config [server_name ] or State .servers_config [server_name ]
588
+ ) or {}
589
+
590
+ local current_auto_approve = server_config .autoApprove or {}
591
+ local new_auto_approve
592
+
593
+ -- Handle boolean case (convert to array first)
594
+ if current_auto_approve == true then
595
+ local all_tools = get_server_tool_names (server_name )
596
+ current_auto_approve = vim .deepcopy (all_tools )
597
+ end
598
+
599
+ -- Ensure it's an array
600
+ if not vim .islist (current_auto_approve ) then
601
+ current_auto_approve = {}
602
+ end
603
+
604
+ -- Toggle the tool in the list using filter instead of table.remove
605
+ local tool_approved = vim .tbl_contains (current_auto_approve , tool_name )
606
+
607
+ if tool_approved then
608
+ -- Remove tool from auto-approve list
609
+ new_auto_approve = vim .tbl_filter (function (tool )
610
+ return tool ~= tool_name
611
+ end , current_auto_approve )
612
+ else
613
+ -- Add tool to auto-approve list
614
+ new_auto_approve = vim .deepcopy (current_auto_approve )
615
+ table.insert (new_auto_approve , tool_name )
616
+ end
617
+
618
+ State .hub_instance :update_server_config (server_name , {
619
+ autoApprove = new_auto_approve ,
620
+ })
621
+ end
622
+ end
486
623
function MainView :handle_server_toggle ()
487
624
-- Get current line
488
625
local cursor = vim .api .nvim_win_get_cursor (0 )
0 commit comments