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.

Enhance get_campaigns function to support pagination

Yves Junqueira94dcfc558466
diff --git a/meta_ads_mcp/api.py b/meta_ads_mcp/api.py
index b43c0de..d91ac46 100644
--- a/meta_ads_mcp/api.py
+++ b/meta_ads_mcp/api.py
@@ -767,7 +767,7 @@ async def get_account_info(access_token: str = None, account_id: str = None) ->
@mcp_server.tool()
@meta_api_tool
-async def get_campaigns(access_token: str = None, account_id: str = None, limit: int = 10, status_filter: str = "") -> str:
+async def get_campaigns(access_token: str = None, account_id: str = None, limit: int = 10, status_filter: str = "", after: str = "") -> str:
"""
Get campaigns for a Meta Ads account with optional filtering.
@@ -776,6 +776,7 @@ async def get_campaigns(access_token: str = None, account_id: str = None, limit:
account_id: Meta Ads account ID (format: act_XXXXXXXXX)
limit: Maximum number of campaigns to return (default: 10)
status_filter: Filter by status (empty for all, or 'ACTIVE', 'PAUSED', etc.)
+ after: Pagination cursor to get the next set of results
"""
# If no account ID is specified, try to get the first one for the user
if not account_id:
@@ -796,6 +797,9 @@ async def get_campaigns(access_token: str = None, account_id: str = None, limit:
if status_filter:
params["effective_status"] = [status_filter]
+ if after:
+ params["after"] = after
+
data = await make_api_request(endpoint, access_token, params)
return json.dumps(data, indent=2)
diff --git a/meta_ads_mcp/core/campaigns.py b/meta_ads_mcp/core/campaigns.py
index f54d06c..496e1a9 100644
--- a/meta_ads_mcp/core/campaigns.py
+++ b/meta_ads_mcp/core/campaigns.py
@@ -9,7 +9,7 @@ from .server import mcp_server
@mcp_server.tool()
@meta_api_tool
-async def get_campaigns(access_token: str = None, account_id: str = None, limit: int = 10, status_filter: str = "") -> str:
+async def get_campaigns(access_token: str = None, account_id: str = None, limit: int = 10, status_filter: str = "", after: str = "") -> str:
"""
Get campaigns for a Meta Ads account with optional filtering.
@@ -26,6 +26,7 @@ async def get_campaigns(access_token: str = None, account_id: str = None, limit:
status_filter: Filter by effective status (e.g., 'ACTIVE', 'PAUSED', 'ARCHIVED').
Maps to the 'effective_status' API parameter, which expects an array
(this function handles the required JSON formatting). Leave empty for all statuses.
+ after: Pagination cursor to get the next set of results
"""
# If no account ID is specified, try to get the first one for the user
if not account_id:
@@ -47,6 +48,9 @@ async def get_campaigns(access_token: str = None, account_id: str = None, limit:
# API expects an array, encode it as a JSON string
params["effective_status"] = json.dumps([status_filter])
+ if after:
+ params["after"] = after
+
data = await make_api_request(endpoint, access_token, params)
return json.dumps(data, indent=2)