Skip to main content
Glama
OrtaMarco

mx-fiscal-mcp-server

by OrtaMarco

Parse CFDI 4.0 XML

parse_cfdi
Read-onlyIdempotent

Convert Mexican CFDI 4.0 invoice XML into structured JSON with labeled SAT codes, validated RFCs, and checked totals.

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.

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 …>").

Input Schema

TableJSON 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

TableJSON 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.4/5.0
Behavior4/5

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

Annotations already declare readOnly/idempotent/non-destructive/closed-world, so the bar is lower, yet the description still adds real substance: code labeling, modulus-11 RFC validation, arithmetic checking with a stated tolerance, namespace-agnostic walking, and the explicit limits (no signature verification, no SAT contact). It stops short of describing pagination/size limits or failure modes on malformed XML, so not quite a 5.

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?

Well front-loaded and organized with a numbered list, a negative-scope callout, and an example. However, the lengthy 'Returns' block largely re-enumerates a field list that already exists as an output schema, which is redundant padding.

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 two-parameter, fully-annotated tool with an output schema, the description covers purpose, scope limits, validation behavior, and routing to the sibling SAT-check tool. Nothing needed to invoke it correctly is missing.

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 coverage is 100% and both parameters are fully documented in the schema, so baseline 3 applies. The Args section merely restates the schema definitions without adding format or edge-case detail beyond what is already structured.

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?

Opens with a specific verb+resource ('Turn the XML of a Mexican electronic invoice (CFDI 4.0) into structured JSON') and enumerates exactly what is extracted (header, issuer, receiver, line items, taxes, timbre). An agent can immediately distinguish this parsing tool from cfdi_status without opening any schema.

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?

Explicitly states when to use this versus the alternative: it does not ask the SAT, and 'Use cfdi_status for the SAT's own answer.' It also pre-empts a major misuse case by clarifying that a clean parse does not mean the document is valid or uncancelled.

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