google_ads_assign_shared_budget
Replace a campaign's individual budget with a shared budget, enabling centralized budget management across campaigns.
Instructions
Assign a shared budget to a campaign.
Args: customer_id: Customer ID (without hyphens) campaign_id: Campaign ID to update budget_resource_name: Resource name of the shared budget (from google_ads_create_shared_budget)
Returns: Success message
Note: The campaign will switch from its individual budget to the shared budget.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customer_id | Yes | ||
| campaign_id | Yes | ||
| budget_resource_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The MCP tool handler function for 'google_ads_assign_shared_budget'. It is decorated with @mcp.tool() and receives customer_id, campaign_id, and budget_resource_name. It calls CampaignManager.assign_shared_budget() and formats the success/error response.
def google_ads_assign_shared_budget( customer_id: str, campaign_id: str, budget_resource_name: str ) -> str: """ Assign a shared budget to a campaign. Args: customer_id: Customer ID (without hyphens) campaign_id: Campaign ID to update budget_resource_name: Resource name of the shared budget (from google_ads_create_shared_budget) Returns: Success message Note: The campaign will switch from its individual budget to the shared budget. """ with performance_logger.track_operation('assign_shared_budget', customer_id=customer_id): try: client = get_auth_manager().get_client() campaign_manager = CampaignManager(client) result = campaign_manager.assign_shared_budget( customer_id, campaign_id, budget_resource_name ) # Audit log audit_logger.log_api_call( customer_id=customer_id, operation="assign_shared_budget", resource_type="campaign", resource_id=campaign_id, action="update", result="success", details={'budget_resource_name': budget_resource_name} ) # Invalidate cache get_cache_manager().invalidate(customer_id, ResourceType.CAMPAIGN) output = f"✅ Shared budget assigned to campaign {campaign_id}\n\n" output += f"**Budget Resource**: {budget_resource_name}\n\n" output += f"{result['message']}\n\n" output += "The campaign now shares its budget with other campaigns using the same budget." return output except Exception as e: error_msg = ErrorHandler.handle_error(e, context="assign_shared_budget") return f"❌ Failed to assign shared budget: {error_msg}" - managers/campaign_manager.py:916-958 (helper)The CampaignManager.assign_shared_budget() method that contains the core logic. It creates a CampaignOperation, sets the campaign_budget field to the shared budget resource name, applies a field mask, and calls the Google Ads CampaignService.mutate_campaigns() API.
def assign_shared_budget( self, customer_id: str, campaign_id: str, budget_resource_name: str ) -> Dict[str, Any]: """ Assign a shared budget to a campaign. Args: customer_id: Customer ID campaign_id: Campaign ID budget_resource_name: Resource name of the shared budget Returns: Operation result """ campaign_service = self.client.get_service("CampaignService") campaign_operation = self.client.get_type("CampaignOperation") campaign = campaign_operation.update campaign.resource_name = campaign_service.campaign_path(customer_id, campaign_id) campaign.campaign_budget = budget_resource_name # Set field mask self.client.copy_from( campaign_operation.update_mask, field_mask_pb2.FieldMask(paths=["campaign_budget"]) ) # Update campaign response = campaign_service.mutate_campaigns( customer_id=customer_id, operations=[campaign_operation] ) logger.info(f"Assigned shared budget to campaign {campaign_id}") return { "campaign_id": campaign_id, "budget_resource_name": budget_resource_name } - tools/campaigns/mcp_tools_campaigns.py:25-26 (registration)The 'register_campaign_tools' function registers all campaign tools (including this one) with the MCP server via @mcp.tool() decorator inside the function body.
def register_campaign_tools(mcp: FastMCP): """Register campaign management tools with MCP server."""