Last updated: 16 November 2026. Meta, Anthropic and OpenAI documentation checked that day.
Letting an AI agent touch a live ad account is a budget decision, not just a technical one. This guide is about the guardrails: how to build a Claude agent that can draft Facebook campaigns through Meta’s ads MCP server, while a human stays in charge of anything that spends money. If you are just connecting Claude for the first time, start with how to connect Claude to Facebook Ads.
Six layers of guardrails
| Layer | Mechanism | What it stops |
|---|---|---|
| Meta token | Employee-role system user, minimum permissions | Access beyond assigned ad accounts |
| Meta server | Write tools create PAUSED; activation asks first | Ads going live by accident |
| Tool list | allowed / denied MCP tools | Agent calling tools it never needs |
| Approval | can_use_tool callback or ask rules | Unreviewed writes |
| Hook | PreToolUse budget check | Budgets above your ceiling |
| Audit | Activity logs + your own log | Changes nobody can explain |

Layer 1–2: what Meta already enforces
Meta’s ads MCP server only works with Employee-role system user tokens; Admin-role system user tokens are not supported. The minimum permissions are ads_mcp_management plus ads_read or ads_management (ads MCP get started). Write tools create campaigns, ad sets and ads as PAUSED, and activation is a separate tool that asks the user to confirm (available tools). Design your agent so it never needs to call that tool.
Layer 3–4: approvals in the Claude Agent SDK
The Claude Agent SDK gives you the same agent loop as Claude Code in Python or TypeScript (Agent SDK overview). Its can_use_tool callback runs before each tool call that isn’t already allowed, so you can auto-approve reads, deny activation and ask a human for everything else (Python reference):
# agent.py - Claude Agent SDK (pip install claude-agent-sdk), API-key auth
import asyncio, os
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
from claude_agent_sdk.types import PermissionResultAllow, PermissionResultDeny
READ_ONLY = {"mcp__meta-ads__ads_get_ad_accounts", "mcp__meta-ads__ads_get_ad_entities",
"mcp__meta-ads__ads_get_ad_preview", "mcp__meta-ads__ads_get_creatives"}
async def gate(tool_name, tool_input, context):
if tool_name in READ_ONLY:
return PermissionResultAllow(updated_input=tool_input)
if tool_name == "mcp__meta-ads__ads_activate_entity":
return PermissionResultDeny(message="Activation is done by a human in Ads Manager", interrupt=True)
if tool_name.startswith("mcp__meta-ads__"):
print("\nAgent wants:", tool_name, tool_input)
if input("Approve? [y/N] ").strip().lower() == "y":
return PermissionResultAllow(updated_input=tool_input)
return PermissionResultDeny(message="Not approved")
options = ClaudeAgentOptions(
mcp_servers={"meta-ads": {"type": "http", "url": "https://mcp.facebook.com/ads",
"headers": {"Authorization": "Bearer " + os.environ["META_ADS_MCP_TOKEN"]}}},
can_use_tool=gate, # do not also list gated tools in allowed_tools
strict_mcp_config=True,
)
async def main():
async with ClaudeSDKClient(options=options) as client:
await client.query("Draft (paused) a traffic campaign for act_<AD_ACCOUNT_ID> "
"from brief.md, then list what you created.")
async for msg in client.receive_response():
print(msg)
asyncio.run(main())- Don’t put gated tools in
allowed_tools; pre-approved tools skip the callback. strict_mcp_config=Trueignores any other MCP config on the machine.- Authenticate with an API key. Anthropic doesn’t allow third-party products to use claude.ai login for the Agent SDK.
- Keep the Meta token in a custom environment variable such as
META_ADS_MCP_TOKEN.
The same rules in Claude Code
For a buyer working interactively, Claude Code’s permission rules use mcp__server__tool names in allow, ask and deny lists (permissions):
// .claude/settings.json - read freely, ask before writes, never activate
{
"permissions": {
"allow": [
"mcp__meta-ads__ads_get_ad_accounts",
"mcp__meta-ads__ads_get_ad_entities",
"mcp__meta-ads__ads_get_ad_preview"
],
"ask": [
"mcp__meta-ads__ads_create_campaign",
"mcp__meta-ads__ads_create_ad_set",
"mcp__meta-ads__ads_create_ad",
"mcp__meta-ads__ads_update_entity"
],
"deny": [
"mcp__meta-ads__ads_activate_entity"
]
}
}| Surface | Allow | Ask a human | Deny |
|---|---|---|---|
| Claude Code settings.json | Read tools | create_*, update_entity | activate_entity |
| Agent SDK | READ_ONLY set | Other meta-ads tools | activate_entity |
| Messages API MCP connector | configs enabled: true | Your own approval step | default_config enabled: false |
| PreToolUse hook | — | — | Any budget above ceiling |

Layer 5: a hook as the second lock
A PreToolUse hook receives the tool input as JSON and can return permissionDecision: "deny" with a reason (hooks). This one blocks any budget field above 200.00, wherever it appears in the input:
// .claude/settings.json (excerpt) - a PreToolUse hook as a second lock
{
"hooks": {
"PreToolUse": [
{
"matcher": "mcp__meta-ads__ads_update_entity",
"hooks": [{ "type": "command", "command": ".claude/hooks/budget-guard.py" }]
}
]
}
}#!/usr/bin/env python3
# .claude/hooks/budget-guard.py - deny any budget value above a ceiling (cents)
import json, sys
CEILING = 20000 # 200.00 in the account currency
def budgets(obj):
if isinstance(obj, dict):
for k, v in obj.items():
if "budget" in k and str(v).isdigit():
yield int(v)
yield from budgets(v)
elif isinstance(obj, list):
for v in obj:
yield from budgets(v)
event = json.load(sys.stdin)
if any(b > CEILING for b in budgets(event.get("tool_input", {}))):
print(json.dumps({"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "Budget above ceiling: needs a media buyer"}}))
sys.exit(0)Field names inside MCP tool inputs can differ from the Marketing API, so the script scans every key containing “budget”. Test it against a real tool call in a sandbox ad account before trusting it.
Layer 6: audit what happened
Meta’s ads MCP server includes activity log tools such as ads_account_get_activity_logs, which read the ad account’s change history (available tools). Combine it with your own log of every tool call the SDK approved: who approved, the input, the result ID.
A sensible rollout
- Week 1: read-only. Reporting tools only, compare Claude’s summary with your own.
- Week 2: drafts. Allow create tools with approval; humans activate in Ads Manager.
- Week 3+: small edits with the hook in place, capped and logged.
- Never: unattended activation or uncapped budget changes.
For reporting-only automation, see Claude reporting and budget rules. For a Codex version of the same idea, see Codex config.toml approvals.
How PandaWM uses Claude, Codex and Facebook ad accounts to speed up client ad delivery
This guide focuses on Claude, but in day-to-day client work PandaWM combines Claude, Codex and Facebook business ad accounts to help companies going global move faster through the repetitive loop of account setup → campaign structure → creatives → reporting → budget changes, so media buyers spend their time on strategy and creative judgement.
- Ad accounts: the client’s own Facebook ad account, or a business ad account opened compliantly through PandaWM’s account-opening service. The account belongs to the client and is never rented or shared.
- Claude: reading long docs and reports, drafting media plans and ad copy, drafting campaign structures in a paused state through Meta’s ads MCP server, and rule-based anomaly checks.
- Codex: writing and maintaining automation scripts (Marketing API, Insights reports, bulk uploads, budget rules) that run in a sandbox, on a schedule or in CI.
- Human sign-off: anything that spends money (activating ads, raising budgets) is approved by a media buyer, and a person makes the final call on Meta policy and creative compliance.
This describes a service capability only. There are no prices or rebates here, and PandaWM is not an official partner of Meta, Anthropic or OpenAI. See Facebook ads account opening & management (PandaWM service page) for account opening and management.
FAQ
Can I use an Admin system user token with the ads MCP server?
No. Meta’s docs say only Employee-role system user tokens are supported.
Does can_use_tool run for every tool?
Only for calls not already allowed by rules or allowed_tools, which is why gated tools stay out of allowed_tools.
Can the agent run unattended?
Reads and drafts can. Activation and large budget changes should stay with a human.
What if a hook script fails?
Test it. A hook that crashes may not block the call, so keep the permission rules as the first lock.
Is this compliant with Meta policies?
The guardrails don’t replace policy review. Ads must still follow Meta’s Advertising Standards.
Compliance note: Use every workflow in this guide only on ad accounts, Pages and pixels that your company owns or is formally authorised to manage, through Meta’s official Marketing API, the ads MCP server or Ads CLI, with Business Manager system users and least-privilege permissions. Respect Meta’s rate limits and Advertising Standards, and keep a human review step before anything that can spend money. PandaWM does not sell, rent, share or transfer ad accounts, Business Managers or API keys, does not help anyone bypass ad review, regional restrictions, KYC, business verification or payment controls, and is not an official partner of Meta, Anthropic or OpenAI. Claude and OpenAI services are only offered to customers in their supported countries and regions; the account holder should be an entity legitimately established and operating in a supported region.
Related guides
- Facebook ads account opening & management (PandaWM service page)
- Overseas AI Token service: account setup + API access (PandaWM)
- Claude Facebook ads reporting and budget-rule automation
- How to connect Claude to Facebook Ads (step by step)
- Connect the Claude API to the Facebook Marketing API with a system user token
- Meta ads MCP server: let AI agents manage your ads
- Facebook ad account setup checklist
- Facebook ad not approved? Fixes
Talk to PandaWM: Facebook ad accounts + AI-assisted delivery
Tell us where your company is registered, your industry, target countries, landing page and expected monthly budget, and which part you want to automate first (account structure, creatives, reporting or budget rules). We pre-check eligibility and creatives, help you open a compliant Facebook business ad account, and build Claude or Codex workflows that run on your own accounts. We never sell, rent or share ad accounts.
WhatsApp: +852 5904 8602Telegram: @PANDA0134WeChat: szcwh99

Official sources
- Meta: Ads MCP server – get started
- Meta: Ads MCP server – ad creation and management tools
- Anthropic: Agent SDK overview
- Anthropic: Agent SDK Python reference
- Anthropic: Claude Code permissions
- Anthropic: Claude Code hooks reference
- Anthropic: Connect Claude Code to tools via MCP
- Meta Advertising Standards
All official pages checked on 2026-11-16. API versions, tool names and permission requirements change; the official pages prevail.

微信扫一扫打赏
支付宝扫一扫打赏
