Skip to content

Browser-agent fallback for gated platform APIs #16

Description

@gidutz

Why

Several high-value ad-platform capabilities are gated behind program approvals or limited OAuth scopes that take days–weeks to obtain — and a self-hosted YieldAgent user may never get them. Concrete examples already in the codebase:

  • LinkedIn Lead Sync (r_marketing_leadgen_automation) — separate program approval; required for pull_lead_responses / subscribe_lead_webhook.
  • LinkedIn Matched Audiences (rw_dmp_segments) — separate Audiences-program approval; required for create_dmp_segment, upload_audience_csv, add_dmp_users.
  • LinkedIn Advertising API itself is a Vetted Product — even creating campaigns requires partner-tier access.
  • Google Ads Developer Token — starts at Test access (test accounts only); Basic/Standard needs application.
  • Meta Marketing API App Review — dev-mode apps can only authenticate Admins/Devs/Testers.

When scope is missing, the agent should not silently fail. It should fall back to driving the platform's web UI through a browser — Playwright session via the existing mcp-browser-control tool registry entry (browser.run_playwright_flow, risk: credential_sensitive, approval: required).

Proposed pattern

Every MCP tool that wraps a gated API surface gets a paired `*_via_browser` fallback, OR the existing tool detects 403 / scope errors and emits a structured `needs_browser_fallback` response the agent can route on. The agent's tool-selection logic should:

  1. Try the official MCP tool first (cheaper, reversible, no UI breakage risk).
  2. On 403 `USER_NOT_AUTHORIZED` / unmapped-scope error, surface the option to retry via browser.
  3. Browser path always goes through the approval gate (`credential_sensitive` risk) — never auto-triggered.

Where this matters next

  • LinkedIn Lead Sync pull → if the org hasn't been approved for `r_marketing_leadgen_automation`, scrape Campaign Manager's Lead Center.
  • LinkedIn Matched Audiences upload → if `rw_dmp_segments` is missing, drive the Audiences UI to attach the CSV.
  • Google Ads Developer Token at Test level → fall back to driving Google Ads UI for any production-account action.
  • Meta App Review pending → drive Meta Ads Manager UI for any non-allowlisted advertiser.

Acceptance

  • A single rule documented in CLAUDE.md / agent system prompt: "When a platform API returns a scope/approval error, propose the browser fallback via the existing browser-control tool rather than returning the error to the user."
  • Each MCP tool that touches a gated surface either auto-retries through the browser path or returns a structured `{ needs_browser_fallback: true, reason, fallback_tool }` payload.
  • The browser fallback always emits a dry-run preview first and routes through the approval gate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions