Skip to main content
Glama

cancel_invoice

Destructive

Cancel an authorized invoice.

Legal cancellation, with fiscal and accounting effect, inside a window the NFS-e authorizer enforces for the municipality. Ask the human to confirm before calling; never call it speculatively. The reason reaches the tax authority verbatim and must be at least 15 characters.

Pass idempotency_key to make a retry safe: repeating the same key with the same access key and reason replays the first answer instead of cancelling a second time. Reuse the key only when retrying that exact call; a genuinely new cancellation needs a new key, or none. Nothing generates one for you — two calls without a key are two cancellations.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "access_key": "<access_key>",
      "document_type": "<document_type>",
      "reason": "<reason>"
    },
    "name": "cancel_invoice"
  }
}

Input Schema

NameRequiredDescriptionDefault
reasonYesWhy the document is cancelled, 15 to 256 characters. It reaches the tax authority verbatim, e.g. Erro no valor do servico prestado.
access_keyYesThe access key (chave de acesso) the authorizer assigned, as issue_invoice and list_invoices return it. An NF-e key has 44 characters; the issuer's CNPJ inside it may carry letters since July 2026, so copy it exactly.
company_idNoUUID of the company acted for. Omit for a single company; else see list_authorized_companies. Send one, never both.
document_typeYesnfse for a service invoice, nfe for goods.
company_tax_idNoCNPJ or CPF of the company acted for, never the recipient or a taxpayer looked up. Omit for a single company; else see list_authorized_companies. Send one, never both.
idempotency_keyNoOne per business event, e.g. order-1042. Printable ASCII up to 255, no leading or trailing space.

Output Schema

NameRequiredDescriptionDefault
idNoLocal id. Use it for reissue and for submissions, and when a document was rejected and has no key.
statusNoissued, rejected or cancelled.
protocolNoThe authorization protocol, when granted.
access_keyNoThe authorizer's key. Absent while the document is not authorized.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changed
    • changedInput schema / properties / company_id / description
      Previous value: -"UUID of the company acted for. Omit it if the connection covers a single company; else see list_authorized_companies. company_id or company_tax_id, never both."New value: +"UUID of the company acted for. Omit for a single company; else see list_authorized_companies. Send one, never both."
    • changedInput schema / properties / company_tax_id / description
      Previous value: -"CNPJ or CPF of the company acted for, never the recipient or a taxpayer looked up. Omit it if the connection covers a single company; else see list_authorized_companies. company_id or company_tax_id, never both."New value: +"CNPJ or CPF of the company acted for, never the recipient or a taxpayer looked up. Omit for a single company; else see list_authorized_companies. Send one, never both."
    • changedInput schema / properties / idempotency_key / description
      Previous value: -"One per business event, e.g. order-1042. Sent as an HTTP header: printable ASCII up to 255, no leading or trailing space."New value: +"One per business event, e.g. order-1042. Printable ASCII up to 255, no leading or trailing space."
  2. Changed2 schema fields changed
    • changedInput schema / properties / company_id / description
      Previous value: -"UUID of the company this call acts for. Omit it when the connection covers a single company; with several it is required (see list_authorized_companies). Send company_id or company_tax_id, never both."New value: +"UUID of the company acted for. Omit it if the connection covers a single company; else see list_authorized_companies. company_id or company_tax_id, never both."
    • changedInput schema / properties / company_tax_id / description
      Previous value: -"CNPJ or CPF of the company this call acts for, never the recipient or a taxpayer being looked up. Omit it when the connection covers a single company; with several it is required (see list_authorized_companies). Send company_id or company_tax_id, never both."New value: +"CNPJ or CPF of the company acted for, never the recipient or a taxpayer looked up. Omit it if the connection covers a single company; else see list_authorized_companies. company_id or company_tax_id, never both."
  3. Changed1 schema field changed
    • changedInput schema / properties / access_key / description
      Previous value: -"The access key (chave de acesso) the authorizer assigned, digits only, as issue_invoice and list_invoices return it. An NF-e key has 44 digits."New value: +"The access key (chave de acesso) the authorizer assigned, as issue_invoice and list_invoices return it. An NF-e key has 44 characters; the issuer's CNPJ inside it may carry letters since July 2026, so copy it exactly."
  4. Changed2 schema fields changed
    • changedInput schema / properties / idempotency_key / anyOf
      Previous value: -[
      -  {
      -    "minLength": 1,
      -    "type": "string"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "maxLength": 255,
      +    "minLength": 1,
      +    "pattern": "^[!-~](?:[ -~]*[!-~])?$",
      +    "type": "string"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • changedInput schema / properties / idempotency_key / description
      Previous value: -"One per business event. An empty key protects nothing, so it is refused rather than ignored."New value: +"One per business event, e.g. order-1042. Sent as an HTTP header: printable ASCII up to 255, no leading or trailing space."
  5. Changed17 schema fields changed
    • addedInput schema / properties / access_key / description
      Added value: +"The access key (chave de acesso) the authorizer assigned, digits only, as issue_invoice and list_invoices return it. An NF-e key has 44 digits."
    • removedInput schema / properties / access_key / title
      Removed value: -"Access Key"
    • changedInput schema / properties / company_id / description
      Previous value: -"UUID of the company this call acts for, as list_authorized_companies shows it. Omit it when the connection covers a single company: that company is used. Required when the connection covers several — call list_authorized_companies to see them, with their ids and what each one allows. Give company_id or company_tax_id, never both."New value: +"UUID of the company this call acts for. Omit it when the connection covers a single company; with several it is required (see list_authorized_companies). Send company_id or company_tax_id, never both."
    • removedInput schema / properties / company_id / title
      Removed value: -"Company Id"
    • changedInput schema / properties / company_tax_id / description
      Previous value: -"CNPJ or CPF of the company this call acts for — the company using Stackin, never the recipient or a taxpayer being looked up. Punctuation is ignored. Omit it when the connection covers a single company: that company is used. Required when the connection covers several — call list_authorized_companies to see them, with their ids and what each one allows. Give company_id or company_tax_id, never both."New value: +"CNPJ or CPF of the company this call acts for, never the recipient or a taxpayer being looked up. Omit it when the connection covers a single company; with several it is required (see list_authorized_companies). Send company_id or company_tax_id, never both."
    • removedInput schema / properties / company_tax_id / title
      Removed value: -"Company Tax Id"
    • addedInput schema / properties / document_type / description
      Added value: +"nfse for a service invoice, nfe for goods."
    • removedInput schema / properties / document_type / title
      Removed value: -"Document Type"
    • removedInput schema / properties / idempotency_key / title
      Removed value: -"Idempotency Key"
    • addedInput schema / properties / reason / description
      Added value: +"Why the document is cancelled, 15 to 256 characters. It reaches the tax authority verbatim, e.g. Erro no valor do servico prestado."
    • removedInput schema / properties / reason / title
      Removed value: -"Reason"
    • removedInput schema / title
      Removed value: -"cancel_invoiceArguments"
    • removedOutput schema / properties / access_key / title
      Removed value: -"Access Key"
    • removedOutput schema / properties / id / title
      Removed value: -"Id"
    • removedOutput schema / properties / protocol / title
      Removed value: -"Protocol"
    • removedOutput schema / properties / status / title
      Removed value: -"Status"
    • removedOutput schema / title
      Removed value: -"InvoiceResult"
  6. Changed2 schema fields changed
    • addedInput schema / properties / company_id
      Added value: +{
      +  "anyOf": [
      +    {
      +      "maxLength": 64,
      +      "minLength": 1,
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "UUID of the company this call acts for, as list_authorized_companies shows it. Omit it when the connection covers a single company: that company is used. Required when the connection covers several — call list_authorized_companies to see them, with their ids and what each one allows. Give company_id or company_tax_id, never both.",
      +  "title": "Company Id"
      +}
    • addedInput schema / properties / company_tax_id
      Added value: +{
      +  "anyOf": [
      +    {
      +      "maxLength": 18,
      +      "minLength": 11,
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "CNPJ or CPF of the company this call acts for — the company using Stackin, never the recipient or a taxpayer being looked up. Punctuation is ignored. Omit it when the connection covers a single company: that company is used. Required when the connection covers several — call list_authorized_companies to see them, with their ids and what each one allows. Give company_id or company_tax_id, never both.",
      +  "title": "Company Tax Id"
      +}
  7. Changed2 schema fields changed
    • changedInput schema / properties / idempotency_key / anyOf
      Previous value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "minLength": 1,
      +    "type": "string"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • addedInput schema / properties / idempotency_key / description
      Added value: +"One per business event. An empty key protects nothing, so it is refused rather than ignored."
  8. First observed

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare destructiveHint=true, idempotentHint=false, and openWorldHint=true, and the description goes further by disclosing the fiscal/accounting effect, the municipal window, and that the reason text reaches the tax authority verbatim. The idempotency paragraph is genuinely informative because it explains that no key is generated for you and two keyless calls are two cancellations, consistent with idempotentHint=false. What is missing is any statement about irreversibility after the window or what an already-cancelled invoice returns.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads the verb and legal effect, then the safety precondition, then the parameter caveat, in three tight blocks with no filler. The only mild redundancy is restating the 15-character minimum already in the schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive, open-world mutation with an output schema present, the description covers the precondition (human confirmation), the side effect (fiscal and accounting cancellation), the environmental constraint (municipal window), and the retry model. Return-value explanation is correctly omitted since an output schema exists.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real semantics the schema lacks: the retry-replay behavior of idempotency_key, the rule to reuse a key only for the exact same call, and that omitting it yields a duplicate cancellation. The verbatim-delivery note for reason adds meaning beyond the schema's length constraint, though access_key and document_type semantics are left entirely to the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ("Cancel an authorized invoice") and immediately qualifies it as a legal cancellation with fiscal and accounting effect, which separates it from read-only siblings like consult_invoice or get_invoice_pdf. It does not explicitly route an agent to correct_invoice or reissue_invoice as the alternative when the goal is fixing rather than voiding, so sibling differentiation is only partial.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear usage conditions: require human confirmation before calling and never call speculatively, plus the constraint that cancellation must fall inside the authorizer-enforced window. It stops short of naming which sibling to reach for when cancellation is not the right remedy.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.