Skip to content

Meta Ads (Facebook/Instagram) MCP server for Claude, ChatGPT, Perplexity & Cursor — the Meta node of Pipeboard’s 5-platform family (+ Google, TikTok, Snap, Reddit). Hosted remote MCP, badged Meta Business Partner, free plan — no self-hosting required.

fix: accept integer IDs in tool parameters to prevent pydantic validation errors

Yves Junqueira7f2b18f9445a
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index 986dc0f..7224a0f 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -2,7 +2,7 @@
import json
import logging
-from typing import Optional, Dict, Any, List
+from typing import Optional, Dict, Any, List, Union
import io
from PIL import Image as PILImage
from mcp.server.fastmcp import Image
@@ -837,12 +837,12 @@ async def update_ad(
status: Optional[str] = None,
bid_amount: Optional[int] = None,
tracking_specs: Optional[List[Dict[str, Any]]] = None,
- creative_id: Optional[str] = None,
+ creative_id: Optional[Union[str, int]] = None,
access_token: Optional[str] = None
) -> str:
"""
Update an ad with new settings.
-
+
Args:
ad_id: Meta Ads ad ID
status: Update ad status (ACTIVE, PAUSED, etc.)
@@ -854,6 +854,10 @@ async def update_ad(
if not ad_id:
return json.dumps({"error": "Ad ID is required"}, indent=2)
+ # Coerce numeric IDs to strings (LLM clients may send integers for numeric-only IDs)
+ if creative_id is not None:
+ creative_id = str(creative_id)
+
params = {}
if status:
params["status"] = status
@@ -1101,7 +1105,7 @@ async def create_ad_creative(
image_hash: Optional[str] = None,
access_token: Optional[str] = None,
name: Optional[str] = None,
- page_id: Optional[str] = None,
+ page_id: Optional[Union[str, int]] = None,
link_url: Optional[str] = None,
message: Optional[str] = None,
messages: Optional[List[str]] = None,
@@ -1110,13 +1114,13 @@ async def create_ad_creative(
description: Optional[str] = None,
descriptions: Optional[List[str]] = None,
image_hashes: Optional[List[str]] = None,
- video_id: Optional[str] = None,
+ video_id: Optional[Union[str, int]] = None,
thumbnail_url: Optional[str] = None,
optimization_type: Optional[str] = None,
dynamic_creative_spec: Optional[Dict[str, Any]] = None,
call_to_action_type: Optional[str] = None,
- lead_gen_form_id: Optional[str] = None,
- instagram_actor_id: Optional[str] = None,
+ lead_gen_form_id: Optional[Union[str, int]] = None,
+ instagram_actor_id: Optional[Union[str, int]] = None,
ad_formats: Optional[List[str]] = None,
asset_customization_rules: Optional[List[Dict[str, Any]]] = None,
creative_features_spec: Optional[Dict[str, Any]] = None,
@@ -1205,6 +1209,14 @@ async def create_ad_creative(
if not account_id:
return json.dumps({"error": "No account ID provided"}, indent=2)
+ # Coerce numeric IDs to strings (LLM clients may send integers for numeric-only IDs)
+ if video_id is not None:
+ video_id = str(video_id)
+ if instagram_actor_id is not None:
+ instagram_actor_id = str(instagram_actor_id)
+ if lead_gen_form_id is not None:
+ lead_gen_form_id = str(lead_gen_form_id)
+
# Defensive coercion: some MCP transports deliver array/dict params as JSON strings
if isinstance(asset_customization_rules, str):
try:
@@ -1678,7 +1690,7 @@ async def update_ad_creative(
optimization_type: Optional[str] = None,
dynamic_creative_spec: Optional[Dict[str, Any]] = None,
call_to_action_type: Optional[str] = None,
- lead_gen_form_id: Optional[str] = None,
+ lead_gen_form_id: Optional[Union[str, int]] = None,
ad_formats: Optional[List[str]] = None
) -> str:
"""
@@ -1710,6 +1722,9 @@ async def update_ad_creative(
Returns:
JSON response with updated creative details
"""
+ # Coerce numeric IDs to strings (LLM clients may send integers for numeric-only IDs)
+ if lead_gen_form_id is not None:
+ lead_gen_form_id = str(lead_gen_form_id)
# Check required parameters
if not creative_id:
return json.dumps({"error": "No creative ID provided"}, indent=2)
diff --git a/meta_ads_mcp/core/duplication.py b/meta_ads_mcp/core/duplication.py
index a690bf8..b1ecd09 100644
--- a/meta_ads_mcp/core/duplication.py
+++ b/meta_ads_mcp/core/duplication.py
@@ -83,7 +83,7 @@ if ENABLE_DUPLICATION:
async def duplicate_adset(
adset_id: str,
access_token: Optional[str] = None,
- target_campaign_id: Optional[str] = None,
+ target_campaign_id: Optional[Union[str, int]] = None,
name_suffix: Optional[str] = " - Copy",
include_ads: bool = True,
include_creatives: bool = True,
@@ -111,6 +111,9 @@ if ENABLE_DUPLICATION:
new_end_time: Override end time for the duplicated ad set (ISO 8601, e.g. 2026-03-20T23:59:59-0500)
new_status: Status for the new ad set (ACTIVE or PAUSED)
"""
+ # Coerce numeric IDs to strings
+ if target_campaign_id is not None:
+ target_campaign_id = str(target_campaign_id)
return await _forward_duplication_request(
"adset",
adset_id,
@@ -134,7 +137,7 @@ if ENABLE_DUPLICATION:
async def duplicate_ad(
ad_id: str,
access_token: Optional[str] = None,
- target_adset_id: Optional[str] = None,
+ target_adset_id: Optional[Union[str, int]] = None,
name_suffix: Optional[str] = " - Copy",
duplicate_creative: bool = True,
new_creative_name: Optional[str] = None,
@@ -154,6 +157,9 @@ if ENABLE_DUPLICATION:
new_creative_name: Override name for the duplicated creative
new_status: Status for the new ad (ACTIVE or PAUSED)
"""
+ # Coerce numeric IDs to strings
+ if target_adset_id is not None:
+ target_adset_id = str(target_adset_id)
return await _forward_duplication_request(
"ad",
ad_id,
diff --git a/meta_ads_mcp/core/targeting.py b/meta_ads_mcp/core/targeting.py
index 9fd21a9..af6ad4a 100644
--- a/meta_ads_mcp/core/targeting.py
+++ b/meta_ads_mcp/core/targeting.py
@@ -1,7 +1,7 @@
"""Targeting search functionality for Meta Ads API."""
import json
-from typing import Optional, List, Dict, Any
+from typing import Optional, List, Dict, Any, Union
import os
from .api import meta_api_tool, make_api_request
from .server import mcp_server
@@ -69,7 +69,7 @@ async def get_interest_suggestions(interest_list: List[str], access_token: Optio
@meta_api_tool
async def estimate_audience_size(
access_token: Optional[str] = None,
- account_id: Optional[str] = None,
+ account_id: Optional[Union[str, int]] = None,
targeting: Optional[Dict[str, Any]] = None,
optimization_goal: str = "REACH",
# Backwards compatibility for simple interest validation
@@ -105,6 +105,10 @@ async def estimate_audience_size(
JSON string with audience estimation results including estimated_audience_size,
reach_estimate, and targeting validation
"""
+ # Coerce numeric IDs to strings
+ if account_id is not None:
+ account_id = str(account_id)
+
# Handle backwards compatibility - simple interest validation
# Check if we're in backwards compatibility mode (interest params provided OR no comprehensive params)
is_backwards_compatible_call = (interest_list or interest_fbid_list) or (not account_id and not targeting)