首页 AI Claude Agent SDK + Meta Ads: Guardrails and Human Approval for an Autonomous Facebook Ads Agent (2026)

Claude Agent SDK + Meta Ads: Guardrails and Human Approval for an Autonomous Facebook Ads Agent (2026)

Build a Claude agent that drafts Facebook campaigns safely: can_use_tool approvals, permission rules, hooks, budget ceilings and audit logs.

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

LayerMechanismWhat it stops
Meta tokenEmployee-role system user, minimum permissionsAccess beyond assigned ad accounts
Meta serverWrite tools create PAUSED; activation asks firstAds going live by accident
Tool listallowed / denied MCP toolsAgent calling tools it never needs
Approvalcan_use_tool callback or ask rulesUnreviewed writes
HookPreToolUse budget checkBudgets above your ceiling
AuditActivity logs + your own logChanges nobody can explain
Six guardrail layers for a Claude Meta ads agent

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=True ignores 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"
    ]
  }
}
SurfaceAllowAsk a humanDeny
Claude Code settings.jsonRead toolscreate_*, update_entityactivate_entity
Agent SDKREAD_ONLY setOther meta-ads toolsactivate_entity
Messages API MCP connectorconfigs enabled: trueYour own approval stepdefault_config enabled: false
PreToolUse hook——Any budget above ceiling
Where to set allow, ask and deny rules for each Claude surface

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

  1. Week 1: read-only. Reporting tools only, compare Claude’s summary with your own.
  2. Week 2: drafts. Allow create tools with approval; humans activate in Ads Manager.
  3. Week 3+: small edits with the hook in place, capped and logged.
  4. 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

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

PandaWM WeChat QR code szcwh99

Official sources

All official pages checked on 2026-11-16. API versions, tool names and permission requirements change; the official pages prevail.

本文来自网络,不代表熊猫出海立场。转载请注明出处: https://www.pandawm.com/blog/claude-agent-sdk-meta-ads-guardrails-human-approval-en.html
上一篇
下一篇

作者: 熊猫出海编辑团队

熊猫出海(PandaWM)编辑团队,来自香港出海服务商熊猫出海,专注 Facebook、TikTok、Google 等海外广告开户与代投,以及 GEO/AI 搜索优化、多语言独立站建设。有Facebook白名单牌照户、TikTok加白户、Google G2认证户等核心资源 。

为您推荐

发表回复

联系我们

联系我们

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部