Skip to main content
Glama
mx-fiscal-mcp-server

mx-fiscal-mcp-server

by OrtaMarco

Parse CFDI XML

parse_cfdi
Read-onlyIdempotent

Turn the XML of a Mexican electronic invoice (CFDI 4.0) into structured JSON: header, issuer, receiver, every line item with its transferred and withheld taxes, the tax totals, and the Timbre Fiscal Digital (UUID, stamp date, SAT…

Instructions

Turn the XML of a Mexican electronic invoice (CFDI 4.0) into structured JSON: header, issuer, receiver, every line item with its transferred and withheld taxes, the tax totals, and the Timbre Fiscal Digital (UUID, stamp date, SAT certificate number, PAC's RFC) — or timbre: null when the document was never stamped.

Three things this does beyond reading attributes:

  1. It labels the catalogue codes. '601' becomes 'General de Ley Personas Morales', 'G03' becomes 'Gastos en general', 'PPD' becomes 'Pago en parcialidades o diferido'. An unknown code is reported as unknown rather than guessed at.

  2. It validates both RFCs (issuer and receiver) with the full modulus-11 check, and flags the SAT generics.

  3. It checks the arithmetic: subtotal − discount + transferred − withheld should equal the declared total. A mismatch is a warning, not a verdict — rounding at the line level is allowed within a centavo.

It walks the document by local element name, so it does not care whether the PAC used the cfdi: and tfd: prefixes, different ones, or none.

Which documents it takes. Any XML whose root is Comprobante: CFDI 4.0 (including tipo P with the Pagos 2.0 complement and tipo N with Nómina), and 3.3 with a version warning. Of the complements it reads only the Timbre Fiscal Digital and local taxes (ImpuestosLocales); any other present is named in findings but its content is not extracted. A 'Retenciones e información de pagos' document is a different SAT document and is refused with that explanation. Input is capped (default 2,000,000 characters, 200,000 elements), a DOCTYPE is refused, and attribute values are cut at 4,000 characters.

What this does NOT do: it does not verify the digital signature, and it does not ask the SAT anything. A document that parses cleanly can still be cancelled, or have been fabricated wholesale. Use cfdi_status for the SAT's own answer.

Args:

  • xml (string): the CFDI XML.

  • response_format ('markdown' | 'json'): output format (default 'markdown').

Returns: { version, serie, folio, fecha, tipo(+label), forma_pago(+label), metodo_pago(+label), moneda, tipo_cambio, sub_total, descuento, total, lugar_expedicion, exportacion, condiciones_de_pago, no_certificado, emisor{rfc, nombre, regimen(+label), rfc_valid, rfc_kind, rfc_errors}, receptor{… domicilio, uso(+label)}, conceptos[{descripcion, clave_prod_serv, cantidad, clave_unidad, unidad, valor_unitario, importe, descuento, objeto_imp(+label), traslados[], retenciones[]}], concepto_count, total_trasladados, total_retenidos, stamped, timbre{uuid, fecha_timbrado, no_certificado_sat, rfc_prov_certif} | null, arithmetic{…}, findings[] }.

Example: "Read this invoice and tell me who issued it and for how much" -> parse_cfdi(xml="<cfdi:Comprobante …>").

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": {
      "xml": "<xml>"
    },
    "name": "parse_cfdi"
  }
}

Input Schema

NameRequiredDescriptionDefault
xmlYesThe complete CFDI XML as a string, from '<cfdi:Comprobante' (or '<?xml') to the closing tag.
response_formatNoOutput format: 'markdown' for a human-readable summary (default) or 'json' for the full structured payload.markdown

Output Schema

NameRequiredDescriptionDefault
tipoYes
fechaYes
folioYes
serieYes
totalYes
emisorYes
monedaYes
timbreYes
stampedYes
versionYes
findingsYes
receptorYes
conceptosYes
descuentoYes
sub_totalYes
arithmeticYes
forma_pagoYes
tipo_labelYes
exportacionYes
metodo_pagoYes
tipo_cambioYes
concepto_countYes
no_certificadoYes
total_retenidosYes
forma_pago_labelYes
lugar_expedicionYes
metodo_pago_labelYes
total_trasladadosYes
conceptos_truncatedYes
condiciones_de_pagoYes
total_traslados_localesYes
total_retenciones_localesYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.9/5.0
Behavior5/5

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

The description provides deep insight into internal logic far beyond annotations, detailing specific behaviors like Modulus-11 RFC validation, arithmetic checks, and automatic catalogue code labeling. This prevents common edge-case failures an agent might otherwise encounter.

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

Conciseness4/5

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

The definition is highly verbose, but this verbosity is justified by the extreme complexity of the CFDI format. The structure is excellent, grouping related constraints (What it does, What it takes, What it doesn't do) logically.

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?

Given the complexity of parsing CFDI, the description is remarkably complete. It outlines the specific fields in the return object (e.g., `concepto_count`, `timbre.uuid`), input limits (2M characters), and the specific XML elements it expects.

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

Parameters5/5

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

While the input schema is 100% covered, the description adds essential semantic value by defining the required format of the XML (must contain 'Comprobante'), detailing the purpose of the `response_format` parameter (markdown vs. json), and clarifying the nature of the `xml` string input.

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?

The description is exceptionally clear, stating its purpose is to 'Turn the XML... into structured JSON'. It precisely defines the scope of the output (header, issuer, line items, taxes, Timbre Fiscal Digital) and explicitly differentiates itself from sibling tools like cfdi_status.

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

Usage Guidelines5/5

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

The usage guidelines are exhaustive. It details acceptable document types (CFDI 4.0, 3.3), refusal criteria (e.g., 'Retenciones e información de pagos' or DOCTYPE), and crucial when-not instructions, such as using `cfdi_status` for signature verification.

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