---
title: "corestack_company_agency_detach"
url: https://docs.corefinity.com/mcp/tools/corestack_company_agency_detach
type: tool
last_updated: 2026-11-13
feature: agency-links
related:
  - https://docs.corefinity.com/guides/agencies/client-organisations-and-the-switcher.md
---
# corestack_company_agency_detach

**Detach an agency.** Detach one of your company's agencies: its people lose access to your sites, tickets and billing at once. The company's owners only. Send confirm_agency set to the agency's id once the person has agreed; without it nothing changes and the refusal lists what would end. Scope: write.

- Scope: `write`
- Confirmation: `confirm_agency`
- Runs as a task: no

## When to use it

Detach one of your company's agencies, for example one you no longer work with. The agency's people lose access to your
sites, tickets and billing at once. Only your company's owners may detach an agency. Needs the `write` scope. The same as
Detach agency on your organisation page in the Control Panel and `DELETE /api/company/agencies/{agency}`.

What ends with the link: the sites the agency manages come back to you, its people's SSH keys on your environments are
removed, its firewall allowances stop applying to your sites, its people stop following your tickets, and your
environments that deploy through its deployment connections lose that repository and need a new deployment connection
before their next deployment (`corestack_company_agencies_list` lists them under `repository_gaps`). Linking the agency
again later does not bring back removed keys, repositories or subscriptions.

Detaching cannot be undone. First call without `confirm_agency`: nothing changes, and the `confirm_mismatch` refusal
lists what would end in `details.effects`. Show that to the person, ask them, and only once they have agreed call again
with `confirm_agency` set to the agency's id.

## Inputs

- `agency_id` (integer, required): the agency to detach, an `id` from `corestack_company_agencies_list`.
- `confirm_agency` (integer): the same id again, sent only after the person agreed. Without it, or with another id,
  nothing changes.

The answer is `detached` (`agency_id`, `client_id`) and `effects`: what ended, in the preview's shape.

### Input schema

```json
{
  "additionalProperties": false,
  "properties": {
    "agency_id": {
      "description": "The agency to detach (corestack_company_agencies_list).",
      "minimum": 1,
      "type": "integer"
    },
    "confirm_agency": {
      "description": "The same id again, sent only after the person agreed to detach this agency.",
      "minimum": 1,
      "type": "integer"
    }
  },
  "required": [
    "agency_id"
  ],
  "type": "object"
}
```

## Refusals

- `confirm_mismatch`: `confirm_agency` is missing or is not the agency's id; `field` names it. Nothing changed.
  `details.effects` is what the detach would end: `managed_sites` (`count`, `names`), `repositories` (`count`,
  `environments`, `other_environments`), `ssh_keys`, `firewall` (`stop_applying`, `stay_for_review`: allowances the
  agency's people added that belong to you, which stay for you to review), `ticket_subscriptions`, and `summary`, the
  same in plain sentences.
- `forbidden`: you are not one of your company's owners, your company is archived, or the agency is Corefinity itself
  (contact Corefinity support to change that link). Nothing changed.
- `tenant_mismatch`: your company has no such agency, or it was already detached.
- `pin_refused`: a token limited to some sites cannot change company-wide links.
- 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).

## Example

```json
{
  "name": "corestack_company_agency_detach",
  "arguments": {
    "agency_id": 87,
    "confirm_agency": 87
  }
}
```

## Prompt

```text
Using the Corefinity MCP server, call corestack_company_agency_detach with agency_id 87. (Detach an agency.) Tell me what it returned.
```

## The same task elsewhere

- Guide: [Client organisations and the switcher](https://docs.corefinity.com/guides/agencies/client-organisations-and-the-switcher.md)
