google_ads_apply_recommendation
Automatically implement a single Google Ads optimization recommendation, including keyword additions, budget adjustments, or bidding strategy changes.
Instructions
Apply a single optimization recommendation.
This will automatically implement the suggested optimization. For example:
KEYWORD recommendations will add the keyword to your account
CAMPAIGN_BUDGET recommendations will increase the budget
Bidding strategy recommendations will change the bidding strategy
Args: customer_id: Customer ID (without hyphens) recommendation_resource_name: Resource name of the recommendation to apply (obtained from google_ads_get_recommendations)
Returns: Success message confirming application
Example: google_ads_apply_recommendation( customer_id="1234567890", recommendation_resource_name="customers/1234567890/recommendations/12345" )
Warning: This will make changes to your account. Review the recommendation details carefully before applying.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customer_id | Yes | ||
| recommendation_resource_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The MCP tool handler function for google_ads_apply_recommendation. It receives customer_id and recommendation_resource_name, calls AutomationManager.apply_recommendation(), logs the operation, invalidates caches, and returns a success/failure message.
def google_ads_apply_recommendation( customer_id: str, recommendation_resource_name: str ) -> str: """ Apply a single optimization recommendation. This will automatically implement the suggested optimization. For example: - KEYWORD recommendations will add the keyword to your account - CAMPAIGN_BUDGET recommendations will increase the budget - Bidding strategy recommendations will change the bidding strategy Args: customer_id: Customer ID (without hyphens) recommendation_resource_name: Resource name of the recommendation to apply (obtained from google_ads_get_recommendations) Returns: Success message confirming application Example: google_ads_apply_recommendation( customer_id="1234567890", recommendation_resource_name="customers/1234567890/recommendations/12345" ) Warning: This will make changes to your account. Review the recommendation details carefully before applying. """ with performance_logger.track_operation('apply_recommendation', customer_id=customer_id): try: client = get_auth_manager().get_client() automation_manager = AutomationManager(client) result = automation_manager.apply_recommendation( customer_id, recommendation_resource_name ) # Audit log audit_logger.log_api_call( customer_id=customer_id, operation="apply_recommendation", resource_type="recommendation", action="update", result="success", details={'resource_name': recommendation_resource_name} ) # Invalidate all caches (recommendation could affect any resource) get_cache_manager().invalidate(customer_id, ResourceType.CAMPAIGN) get_cache_manager().invalidate(customer_id, ResourceType.AD_GROUP) get_cache_manager().invalidate(customer_id, ResourceType.KEYWORD) output = f"✅ Recommendation applied successfully!\n\n" output += f"**Resource Name**: {result['resource_name']}\n" output += f"**Status**: {result['status']}\n\n" output += f"The optimization has been implemented in your account.\n" output += f"Monitor performance over the next few days to see the impact.\n" return output except Exception as e: error_msg = ErrorHandler.handle_error(e, context="apply_recommendation") return f"❌ Failed to apply recommendation: {error_msg}" - The AutomationManager.apply_recommendation() method that actually calls the Google Ads API RecommendationService.apply_recommendation() with the recommendation resource name and returns the result.
def apply_recommendation( self, customer_id: str, recommendation_resource_name: str ) -> Dict[str, Any]: """Apply a single optimization recommendation. Args: customer_id: Customer ID (without hyphens) recommendation_resource_name: Resource name of the recommendation Returns: Dictionary with application result """ recommendation_service = self.client.get_service("RecommendationService") apply_operation = self.client.get_type("ApplyRecommendationOperation") apply_operation.resource_name = recommendation_resource_name response = recommendation_service.apply_recommendation( customer_id=customer_id, operations=[apply_operation] ) result = response.results[0] return { 'resource_name': result.resource_name, 'status': 'applied' } - managers/automation_manager.py:25-26 (schema)The RecommendationType enum used to define valid recommendation types. Though not directly used in the apply function, it's part of the recommendation schema used across the automation module.
class RecommendationType(str, Enum): """Google Ads recommendation types.""" - tools/automation/mcp_tools_automation.py:37-43 (registration)The register_automation_tools() function that registers all automation tools with the MCP server via @mcp.tool() decorators.
def register_automation_tools(mcp): """Register all automation and optimization tools with the MCP server. Args: mcp: FastMCP server instance """ - google_ads_mcp.py:498-513 (registration)The _register_all_modular_tools() function that imports and calls register_automation_tools (among others) to register the tool on the MCP server.
def _register_all_modular_tools(): """Import and register every modular tool module.""" import importlib registered = 0 for label, module_path, func_name in _TOOL_MODULES: try: mod = importlib.import_module(module_path) register_fn = getattr(mod, func_name) register_fn(mcp) logger.info(f" ✓ {label}") registered += 1 except Exception as exc: logger.error(f" ✗ {label}: {exc}") logger.info(f"Registered {registered}/{len(_TOOL_MODULES)} modular tool modules")