ConsentLayer
Guides

AI Agent Integration

ConsentLayer provides an MCP (Model Context Protocol) server that lets AI coding agents set up cookie consent end-to-end — create sites, scan for trackers, configure consent, and generate install code — without touching the dashboard.

Setup

Claude Code

Run this in your terminal:

npx @consentlayer/mcp setup

This auto-configures Claude Code to connect to the ConsentLayer MCP server.

Alternatively, run manually:

claude mcp add consentlayer --transport http "https://api.consentlayer.com/mcp"

Cursor / Windsurf / Other MCP Clients

Add to your MCP configuration file:

{
  "mcpServers": {
    "consentlayer": {
      "url": "https://api.consentlayer.com/mcp"
    }
  }
}

Authentication

ConsentLayer uses browser-based OAuth — no API keys needed. On the first tool call, your browser opens for login (or signup). Tokens are cached locally for future sessions.

Usage

Once connected, tell your agent what you need:

"Set up cookie consent on my website example.com"

The agent will use the MCP tools to handle everything automatically.

The get_started tool returns the full guided workflow, but here's the overview:

StepToolWhat it does
1setup_siteProvisions the site, scans for trackers, auto-configures categories, returns the install snippet with the real project key
2—Place the snippet in <head> of every page (no defer, no async) and deploy
3check_installationVerifies the tag on the live site and returns the compliance punch list

Fine-grained tools (create_site, scan_site, configure_from_scan, update_banner_config, update_site_behavior, add_geolocation_group_from_template) exist for step-by-step control — get_started documents them all.

Copy-paste prompt

Paste this into your agent, swapping in your domain:

Set up ConsentLayer cookie consent on <your-domain>. If the ConsentLayer MCP server isn't connected, add it first: https://api.consentlayer.com/mcp. Call setup_site with my domain, add the returned snippet to the <head> of every page without defer or async, deploy, then call check_installation and report the compliance score and remaining action items.

Builder platforms (Replit, Lovable, Bolt)

Replit supports MCP connectors natively — add ConsentLayer to your Replit account with one click and Replit Agent runs the full setup itself. Follow the Replit guide.

Lovable and Bolt run their own sandboxed agent and can't connect to external MCP servers, so the MCP flow above won't work there. Instead, create the site in the dashboard: go to Sites → Set up through an AI agent → Lovable / Bolt. That gives you a ready-made prompt containing your site's real install snippet — paste that prompt into the builder's chat. Never hand a builder a snippet with a placeholder project key; it will produce a non-functional integration.

The prompt tells the builder's agent to:

  • Put the plain <script> tag first in the shared document <head>: the root route's document (src/routes/__root.tsx, before <HeadContent />) in a TanStack Start app — the default for new Lovable projects — or index.html in a Vite app. Server rendering stays as it is.
  • Never add async or defer, never load the tag from useEffect, and never swap it for a framework script helper.
  • Add every later analytics or ad tag as <script type="text/plain" data-cl-category="statistics"> or data-cl-category="marketing", or load it only after hasConsent() from @consentlayer/sdk returns true.

Then publish. The install check runs on the published domain (yourapp.lovable.app or your custom domain), not the editor preview. See the Lovable guide for a project Knowledge entry that keeps these rules in place for later edits.

Example Prompts

Full setup:

"Add GDPR cookie consent to my site example.com. Scan it for trackers and give me the install code."

Customize banner:

"Change my consent banner to a floating style in the bottom-right corner with blue buttons."

Add a service:

"Add Google Analytics to my site's statistics category."

Check status:

"Show me what tracking services are configured on my site."

Available Tools

Site Management

  • list_sites — List all your sites
  • create_site — Create a site with name and domain
  • add_site_domain — Add a domain to an existing site, e.g. a staging or preview copy, or the www host. The domain uses the site's banner, categories and consent log. Adding a domain the site already has returns it unchanged
  • update_site — Rename a site
  • delete_site — Delete a site and all its data (requires the site's domain as confirmation; refused while consent records exist)

Scanner

  • scan_site — Scan a website for tracking scripts and cookies
  • list_scans — View scan history
  • get_scan — Get detailed scan results
  • configure_from_scan — Auto-import detected services
  • search_library — Browse known services (Google Analytics, Meta Pixel, Hotjar, etc.)
  • get_library_service — Get full details about a library service
  • import_service — Import a service into a site

Services

  • list_site_services — List all services with their cookies
  • add_custom_service — Add a custom tracking service
  • remove_service — Remove a service
  • get_banner_config — Get current banner configuration
  • update_banner_config — Update template, position, colors, text

Categories

  • list_categories — List consent categories (essential, statistics, marketing)
  • create_category — Create a new category
  • delete_category — Delete a custom category

Setup & verification

  • get_started — Get the recommended workflow and see existing sites
  • get_setup_snippet — Generate the install code for any framework
  • check_installation — Verify the deployed snippet on the live site and return the compliance summary

Plan limits

Free and Solo include 1 site, Studio 10 and Agency 30. A second site needs Studio. Staging and preview domains do not count toward any limit (see Domains and staging).

When a call goes over a limit, the tool returns a normal result (not a tool error) with error: "PLAN_LIMIT_REACHED":

{
  "error": "PLAN_LIMIT_REACHED",
  "message": "Your Free plan includes 1 site, and you already have 1. Upgrade to add another site.",
  "resource": "sites",
  "plan": "free",
  "limit": 1,
  "required_plan": "studio",
  "upgrade_url": "https://app.consentlayer.com/checkout?tier=studio&interval=monthly",
  "requested_domain": "new-site.com",
  "existing_sites": [{ "id": "…", "name": "Example", "domain": "example.com" }],
  "next_steps": ["…"],
  "agent_guidance": "…"
}
FieldMeaning
resourcesites (from setup_site / create_site) or domains (from add_site_domain). A paid feature returns feature instead
required_plan, upgrade_urlThe cheapest plan that removes the block, and its checkout link. Both are null when no self-serve plan does
existing_sitesThe organization's sites, so the agent can check whether the new domain is a copy of one
next_stepsWhat to tell the user and which tool to call next
agent_guidanceWhat the agent must not do

What the agent must do:

  1. Tell the user which limit they reached and give them upgrade_url.
  2. If the requested domain is a staging or preview copy of a site in existing_sites, call add_site_domain with that site's id. It uses no new site slot.
  3. After the user upgrades, call the same tool again.

What the agent must never do:

  • change the ConsentLayer banner with its own code;
  • copy another site's snippet onto the new domain. That snippet loads the other site's rules and does not run on hosts its site does not list;
  • delete a site, unless the user names the exact domain and says yes.

Important Notes

  • The <script> tag must be placed in <head> without defer or async — it needs to run synchronously to block tracking scripts before they execute.
  • The banner is served as a static JS file per site, regenerated on every config change. No server-side rendering per page view.
  • Default consent categories (essential, statistics, marketing) are created automatically and cannot be deleted.
  • Script blocking uses DOM mutation observers to intercept dynamically-created scripts.
  • The banner runs only on the site's domains, their subdomains and localhost. On any other host it does nothing. See Domains and staging.