Skip to main content
Glama

Encerrar MDF-e

mdfe_encerrar
Destructive

Encerra um MDF-e já autorizado (evento tipo 3). Obrigatório ao final de cada transporte. Sem encerramento, novos MDF-e podem ser bloqueados pela SEFAZ.

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": {
      "tipoAmbiente": "<tipoAmbiente>",
      "chave": "<chave>"
    },
    "name": "mdfe_encerrar"
  }
}

Input Schema

NameRequiredDescriptionDefault
ufNoSigla da UF de encerramento. Opcional: acompanha codMunicipio e, quando enviada, deve ser a UF desse município.
chaveYesChave de acesso de 44 dígitos do MDF-e a encerrar.
protocoloNoProtocolo de autorização do MDF-e original. Opcional - se omitido, o sistema localiza pela chave.
codMunicipioNoCódigo IBGE (7 dígitos) do município onde o MDF-e foi encerrado. Se omitido, usa o último município de descarga do MDF-e (a sede da empresa, só quando o MDF-e não foi emitido por este sistema).
tipoAmbienteYesAmbiente do MDF-e original (DEVE bater com o ambiente onde o manifesto foi emitido). IMPORTANTE: passe explicitamente. ATENÇÃO: encerramento é DEFINITIVO - revise os dados antes. Valores: 1 - Produção; 2 - Homologação
dataEncerramentoNoData do encerramento. Se omitida, usa a data do envio.
numeroSequencialNoNúmero sequencial do evento. Se omitido, o sistema usa o próximo disponível.

Output Schema

NameRequiredDescriptionDefault
ErrorNoMensagem de erro da operação. Vazia ("") quando foi bem-sucedida.
AvisosNoAvisos não bloqueantes. Pode vir preenchida mesmo em emissão bem-sucedida.
StatusNo1 - Evento Processado; 2 - Aguardando processamento do evento; 3 - Ocorreu um erro ao processar o evento
DsEventoNo
DsMotivoNo
Base64XmlNoXML do evento processado (procEventoNFe) em Base64. Preenchido quando o evento e autorizado (cStat 135) na Carta de Correcao da NF-e, na manifestacao do destinatario e no ECONF (NF-e e NFC-e). Nulo nos demais casos.
Base64FileNoPDF do documento auxiliar do evento (ex.: Carta de Correcao) em Base64. Preenchido apenas quando o evento e autorizado e a nota existe na base. Nulo nos demais casos.
DsAmbienteNo
NuProtocoloNo
NumeroSequencialNo
CodStatusRespostaSefazNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedOutput schema / properties / Base64Xml / description
      Previous value: -"XML do evento processado (procEventoNFe) em Base64. Preenchido apenas quando o evento e autorizado (cStat 135) e o documento e NF-e (modelo 55). Nulo nos demais casos."New value: +"XML do evento processado (procEventoNFe) em Base64. Preenchido quando o evento e autorizado (cStat 135) na Carta de Correcao da NF-e, na manifestacao do destinatario e no ECONF (NF-e e NFC-e). Nulo nos demais casos."
  2. Changed3 schema fields changed
    • addedInput schema / properties / codMunicipio
      Added value: +{
      +  "description": "Código IBGE (7 dígitos) do município onde o MDF-e foi encerrado. Se omitido, usa o último município de descarga do MDF-e (a sede da empresa, só quando o MDF-e não foi emitido por este sistema).",
      +  "type": [
      +    "integer",
      +    "null"
      +  ]
      +}
    • addedInput schema / properties / dataEncerramento
      Added value: +{
      +  "description": "Data do encerramento. Se omitida, usa a data do envio.",
      +  "type": [
      +    "string",
      +    "null"
      +  ]
      +}
    • addedInput schema / properties / uf
      Added value: +{
      +  "description": "Sigla da UF de encerramento. Opcional: acompanha codMunicipio e, quando enviada, deve ser a UF desse município.",
      +  "type": [
      +    "string",
      +    "null"
      +  ]
      +}
  3. Changed2 schema fields changed
    • addedOutput schema / properties / Base64File
      Added value: +{
      +  "description": "PDF do documento auxiliar do evento (ex.: Carta de Correcao) em Base64. Preenchido apenas quando o evento e autorizado e a nota existe na base. Nulo nos demais casos.",
      +  "type": [
      +    "string",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / Base64Xml
      Added value: +{
      +  "description": "XML do evento processado (procEventoNFe) em Base64. Preenchido apenas quando o evento e autorizado (cStat 135) e o documento e NF-e (modelo 55). Nulo nos demais casos.",
      +  "type": [
      +    "string",
      +    "null"
      +  ]
      +}
  4. Changed8 schema fields changed
    • changedInput schema / properties / numeroSequencial / type
      Previous value: -"integer"New value: +[
      +  "integer",
      +  "null"
      +]
    • changedInput schema / properties / protocolo / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
    • changedOutput schema / properties / Avisos / type
      Previous value: -"array"New value: +[
      +  "array",
      +  "null"
      +]
    • changedOutput schema / properties / DsAmbiente / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
    • changedOutput schema / properties / DsEvento / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
    • changedOutput schema / properties / DsMotivo / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
    • changedOutput schema / properties / Error / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
    • changedOutput schema / properties / NuProtocolo / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
  5. First observed

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already declare destructiveHint=true and openWorldHint=true (SEFAZ round-trip), so the safety bar is lower. The description adds real behavioral context beyond them: the sequencial event type and the downstream side effect that unclosed manifests get blocked. It stops short of stating irreversibility in the description body itself, though that warning lives in the schema.

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?

Three short sentences, zero filler, with the core action and its obligation front-loaded. Nothing in it could be removed without losing information.

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

Completeness4/5

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

With an output schema present and fully documented parameters, the description only needs to cover purpose, obligation and consequence — which it does. Minor gaps: no mention of what happens when the manifest is already closed or what errors to expect from SEFAZ.

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

Parameters3/5

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

Schema description coverage is 100%, including defaults, enum values and fallback behavior for every parameter, so the baseline of 3 applies. The description contributes nothing about parameters such as chave or tipoAmbiente, leaving the schema to carry that load entirely.

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

Purpose5/5

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

States a specific verb and resource ('Encerra um MDF-e já autorizado') plus the SEFAZ event type (3), which cleanly separates it from mdfe_emitir and the generic evento_cancelar sibling. The precondition ('já autorizado') tells an agent this only applies to existing manifests.

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 strong when-to-use guidance: 'Obrigatório ao final de cada transporte', and explains the consequence of skipping it (new MDF-e may be blocked by SEFAZ). It does not name an alternative for the abort/cancel case (e.g. evento_cancelar), so it stops short of full routing guidance.

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.