Skip to content

Instantly share code, notes, and snippets.

@IRus
Forked from Richard-Weiss/claude_mcp_auto_approve.js
Last active April 19, 2025 09:14
Show Gist options
  • Save IRus/18aa5ae9464ad03e4e0f2be53c61ea1c to your computer and use it in GitHub Desktop.
Save IRus/18aa5ae9464ad03e4e0f2be53c61ea1c to your computer and use it in GitHub Desktop.
Claude MCP auto approve
// Array of trusted tool names
const trustedTools = [
'create_new_file_with_text',
'execute_action_by_id',
'execute_terminal_command',
'find_commit_by_message',
'find_files_by_name_substring',
'get_all_open_file_paths',
'get_all_open_file_texts',
'get_debugger_breakpoints',
'get_file_text_by_path',
'get_open_in_editor_file_path',
'get_open_in_editor_file_text',
'get_progress_indicators',
'get_project_dependencies',
'get_project_modules',
'get_project_vcs_status',
'get_run_configurations',
'get_selected_in_editor_text',
'get_terminal_text',
'list_available_actions',
'list_directory_tree_in_folder',
'list_files_in_folder',
'open_file_in_editor',
'replace_current_file_text',
'replace_file_text_by_path',
'replace_selected_text',
'replace_specific_text',
'run_configuration',
'search_in_files_content',
'toggle_debugger_breakpoint',
'wait',
];
// Cooldown tracking
let lastClickTime = 0;
const COOLDOWN_MS = 1000; // 1 second cooldown
const observer = new MutationObserver((mutations) => {
// Check if we're still in cooldown
const now = Date.now();
if (now - lastClickTime < COOLDOWN_MS) {
console.log('πŸ•’ Still in cooldown period, skipping...');
return;
}
console.log('πŸ” Checking mutations...');
const dialog = document.querySelector('[role="dialog"]');
if (!dialog) return;
const buttonWithDiv = dialog.querySelector('button div');
if (!buttonWithDiv) return;
const toolText = buttonWithDiv.textContent;
if (!toolText) return;
console.log('πŸ“ Found tool request:', toolText);
const toolName = toolText.match(/Run (\S+) from/)?.[1];
if (!toolName) return;
console.log('πŸ› οΈ Tool name:', toolName);
if (trustedTools.includes(toolName)) {
const allowButton = Array.from(dialog.querySelectorAll('button'))
.find(button => button.textContent.includes('Allow for This Chat'));
if (allowButton) {
console.log('πŸš€ Auto-approving tool:', toolName);
lastClickTime = now; // Set cooldown
allowButton.click();
}
} else {
console.log('❌ Tool not in trusted list:', toolName);
}
});
// Start observing
console.log('πŸ‘€ Starting observer for trusted tools:', trustedTools);
observer.observe(document.body, {
childList: true,
subtree: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment