---
title: "corestack_varnish_purge"
url: https://docs.corefinity.com/mcp/tools/corestack_varnish_purge
type: tool
last_updated: 2026-11-13
feature: varnish
related:
  - https://docs.corefinity.com/api/reference/varnish/purge-site-varnish.md
  - https://docs.corefinity.com/guides/sites/software-and-services/varnish.md
---
# corestack_varnish_purge

**Purge a site's Varnish cache.** Purge a Magento 2 row's Varnish cache: all, by tag, by address or by pattern. Prefer tags or addresses. Ten an hour per site. Scope: write. Long-running: answers with a task.

- Scope: `write`
- Runs as a task: yes

## When to use it

Purge a Magento 2 row's Varnish cache after content changed outside a deployment: everything, by Magento cache tag, by address or by pattern. Prefer a tag or an address to everything, so the rest of the store stays cached. Deployments purge Varnish themselves, and Magento purges its own tags when products and categories are saved, so neither needs this tool.

Ten purges an hour for each site, counted across the Corefinity Control Panel, the API and MCP together. Magento's own purges, deployments and the "Purge Varnish first" step of `corestack_site_cloudflare_purge` are not counted. When Cloudflare also caches the site, purge Varnish first, then Cloudflare.

The call answers a task on the purge command; follow it with `corestack_command_get`. Varnish confirms each purge but gives no count of the pages removed, so the result reports what was sent and that it was confirmed: `{mode, count, hosts, confirmed, seconds}`.

## Inputs

- `site_id` (integer, ≥ 1, required): the row, a Magento 2 site or one of its environments.
- `mode` (string, required): `all`, `tags`, `urls` or `patterns`. Send the list that matches the mode and no other. `all` empties the whole cache, also files Magento does not tag (`robots.txt`, sitemaps, verification files).
- `tags` (array of string, 1–50 items): with `tags`. Magento cache tags such as `cat_p_1180` or `cat_c_27`: letters, digits and underscores, up to 64 characters each.
- `urls` (array of string, 1–30 items, up to 2048 characters each): with `urls`. A path (`/gravel-bikes`) or an absolute address on one of the row's own hosts (`https://example.co.uk/gravel-bikes`). Each is purged exactly, its query included; Varnish ignores tracking parameters (`utm_*`, `gclid`, `fbclid` and the like) and the order of the others, as it does when it stores pages.
- `patterns` (array of string, 1–5 items, up to 256 characters each): with `patterns`. Regular expressions (PCRE2) on the stored path and query, each starting with `/`; Varnish anchors them at the start, so `/gravel-bikes(/|\?|$)` purges that category and everything under it. `/`, `/.*` and `.*` purge almost everything: use `mode: all` instead.
- `host` (string or null): with `urls` or `patterns`, one of the row's storefront hosts (`corestack_site_storefront_domains_list`), without a port. Absent or null purges every host of the row. An absolute address in `urls` names its own host.

A page that one of your nginx rules rewrote is stored under the rewritten address: purge it by tag or by pattern.

### Input schema

```json
{
  "additionalProperties": false,
  "properties": {
    "host": {
      "description": "One host for urls or patterns; null: all.",
      "maxLength": 253,
      "type": [
        "string",
        "null"
      ]
    },
    "mode": {
      "description": "Send the matching list.",
      "enum": [
        "all",
        "tags",
        "urls",
        "patterns"
      ],
      "type": "string"
    },
    "patterns": {
      "description": "Regexes on path and query, starting with /.",
      "items": {
        "maxLength": 256,
        "type": "string"
      },
      "maxItems": 5,
      "minItems": 1,
      "type": "array"
    },
    "site_id": {
      "minimum": 1,
      "type": "integer"
    },
    "tags": {
      "description": "Magento cache tags, e.g. cat_p_1180.",
      "items": {
        "maxLength": 64,
        "type": "string"
      },
      "maxItems": 50,
      "minItems": 1,
      "type": "array"
    },
    "urls": {
      "description": "Paths or addresses on the row's hosts.",
      "items": {
        "maxLength": 2048,
        "type": "string"
      },
      "maxItems": 30,
      "minItems": 1,
      "type": "array"
    }
  },
  "required": [
    "site_id",
    "mode"
  ],
  "type": "object"
}
```

## Refusals

- `varnish_off`: Varnish is switched off on this row; Magento's built-in cache serves pages (flush it with `corestack_function_run` `flush_cache`). Switch Varnish on with `corestack_varnish_set` first.
- `varnish_not_offered`: the row is not a Magento 2 site.
- `invalid_tags`: a tag is not a Magento cache tag; `fields.tags` and `details.offenders` name each one.
- `invalid_urls`: an address is not a path or an address on this row, is longer than 2048 bytes, or holds spaces, quotes or control characters; `details.offenders` names each one.
- `host_not_owned`: `host`, or an absolute address's host, is not one of this row's storefront hosts.
- `invalid_pattern`: a pattern does not start with `/`, is longer than 256 bytes, holds spaces or quotes, or does not compile; the message carries the PCRE2 error and its offset.
- `invalid_arguments`: no mode, or a list that does not match the mode.
- `rate_limited`: the ten purges this hour are used; `retry_after_seconds` says when the next one is available. A purge Varnish never received does not count.
- `deleted`: the site is deleted (in its grace period); restore it with corestack_site_restore_deleted first.
- `provisioning`: the site is still being created; wait for corestack_site_provisioning_get to finish.
- `managed_elsewhere` (message: "This site is managed by another control panel"): another control panel manages this site, so use that control panel for it. This is refused before anything else about the site, as in the Control Panel and the API. Nothing was done.
- The refusals every tool can answer: `invalid_arguments`, `tenant_mismatch`, `scope_required`, `pin_refused`, `rate_limited`, `temporarily_unavailable`, `internal_error` (corestack://guides/how-this-server-works).

A task that fails says why: Varnish not answering right now (the site is applying a change; try again in a minute) or a purge that could not be confirmed.

## Example

```json
{
  "name": "corestack_varnish_purge",
  "arguments": {
    "site_id": 4211,
    "mode": "tags",
    "tags": [
      "cat_p_1180",
      "cat_c_27"
    ]
  }
}
```

The task's result: `{"mode": "tags", "count": 2, "hosts": [], "confirmed": true, "seconds": 3.1}`.

## Prompt

```text
Using the Corefinity MCP server, call corestack_varnish_purge with site_id 4211, mode tags, tags ["cat_p_1180","cat_c_27"]. (Purge a site's Varnish cache.) Tell me what it returned.
```

## The same task elsewhere

- Endpoint: [POST /api/corestack/sites/{site}/varnish/purge](https://docs.corefinity.com/api/reference/varnish/purge-site-varnish.md)
- Guide: [Varnish](https://docs.corefinity.com/guides/sites/software-and-services/varnish.md)
