mcp-cfdi-mx
Summary: A PAC-agnostic Python MCP server for Mexican CFDI 4.0 e-invoicing that lets AI agents build, XSD-validate, seal, and verify electronic invoices and payment complements.
mx__get_supported_scope— report supported document types, complementos, and sealing modesmx__build_cfdi— build well-formed, unsealed CFDI 4.0 Ingreso/Egreso XML (returns XML + computed Total)mx__build_pago— build a Complemento de Pagos 2.0 CFDI (TipoDeComprobante="P") with the mandated fixed Concepto wrappermx__validate_cfdi— XSD validation againstcfdv40.xsd, plus TFD 1.1 and/or Pagos 2.0 schemas when those complements are presentmx__seal_cfdi— compute Sello/NoCertificado/Certificado from your CSD (local) or return XML unchanged for a PAC to seal (pac)mx__verify_tfd— parse a PAC-returned Timbre Fiscal Digital 1.1, recompute the cadena original, and cryptographically verifySelloSATwhen the PAC certificate is suppliedRFC validation is applied automatically during document construction via
TaxIdentifier.validate_mx_rfcNot supported: PAC submission transport, Carta Porte, Complemento de Nómina, Retenciones, Comercio Exterior
mcp-cfdi-mx 🇲🇽
A Python MCP server providing tools for Mexican electronic invoicing compliant with CFDI 4.0 and Complemento de Pagos 2.0, per SAT's Anexo 20 technical standard. It enables AI agents (Claude, IDEs) to build, XSD-validate, and seal CFDI 4.0 documents (Ingreso, Egreso, and Complemento de Pagos 2.0), verify a PAC-returned Timbre Fiscal Digital stamp, and validate Mexican RFC tax identifiers.
Phase 1 scope. This package covers CFDI 4.0 Ingreso, Egreso, and Complemento de Pagos 2.0 only — Carta Porte, Complemento de Nómina, Retenciones, and Comercio Exterior are not yet supported, and it does not submit to any PAC. See Available tools for exactly what is implemented today.
Introduction
This package is built on mcp-einvoicing-core, the shared base library for e-invoicing MCP servers. It provides the InvoiceDocument model base, the TaxIdentifier.validate_mx_rfc RFC validator, and SelloDigitalSigner — the MX-specific concrete implementation of core's document-signing abstraction (SHA-256 digest of the cadena original, RSA-PKCS#1v1.5-signed with the emisor's CSD, per SAT's Anexo 20).
mcp-einvoicing-core is installed automatically as a dependency, no additional step is required.
CFDI is a clearance-model standard: a CFDI becomes legally valid only once a PAC (Proveedor Autorizado de Certificación) certifies it and returns a Timbre Fiscal Digital (TFD). This package does not submit to a PAC — it is PAC-agnostic, producing either a locally-sealed CFDI (ready to hand to any PAC that accepts pre-sealed documents) or an unsealed, schema-valid CFDI (for a PAC that seals on the emisor's behalf), selected via a sealing_mode parameter.
Related MCP server: mcp-fattura-elettronica-it
Installation
Via PyPI (recommended)
pip install mcp-cfdi-mxOr without prior installation using uvx:
uvx mcp-cfdi-mxFrom source
git clone https://github.com/cmendezs/mcp-cfdi-mx.git
cd mcp-cfdi-mx
uv sync --all-extrasConfiguration (environment variables)
This package has no required environment variables. CSD certificate/key paths and passwords are passed as tool arguments (file paths or environment references — never plaintext key material embedded in a request), not read from a fixed environment variable name.
Claude Desktop integration
Add the following configuration to your claude_desktop_config.json file:
{
"mcpServers": {
"cfdi-mx": {
"command": "uvx",
"args": ["mcp-cfdi-mx"]
}
}
}Cursor integration
Cursor supports MCP servers via stdio. Add the configuration to:
Globally (all projects):
~/.cursor/mcp.jsonPer project (this repository only):
.cursor/mcp.json
{
"mcpServers": {
"cfdi-mx": {
"command": "uvx",
"args": ["mcp-cfdi-mx"]
}
}
}Reload the Cursor window (Ctrl+Shift+P → Reload Window) after saving changes.
Kiro integration
Kiro supports MCP servers through a dedicated configuration file:
Globally:
~/.kiro/settings/mcp.jsonWorkspace:
.kiro/settings/mcp.json
{
"mcpServers": {
"cfdi-mx": {
"command": "uvx",
"args": ["mcp-cfdi-mx"],
"disabled": false,
"autoApprove": []
}
}
}Security tip: if a future tool version accepts credentials via environment reference, use the syntax
"VAR_NAME": "${VAR_NAME}"so Kiro resolves it from the shell rather than storing it in plaintext.
Available tools
Build
Tool | Description |
| Build a well-formed, unsealed CFDI 4.0 |
| Build a Complemento de Pagos 2.0 CFDI ( |
Validate and seal
Tool | Description |
| Full XSD validation against |
| Compute the Sello Digital via |
| Parse a PAC-returned Timbre Fiscal Digital 1.1 stamp, and cryptographically verify |
Scope
Tool | Description |
| Returns the CFDI document types, complementos, and sealing modes this package currently supports |
See docs/TOOLS.md for the full parameter reference of every tool, generated from the live tool registry.
Not yet implemented
PAC submission transport (this package is PAC-agnostic and does not submit to any specific PAC), and later-phase complementos (Carta Porte, Complemento de Nómina, Retenciones, Comercio Exterior).
Architecture
mcp_cfdi_mx.models.CFDIComprobante extends mcp_einvoicing_core.models.InvoiceDocument (the
non-EN 16931 pathway — CFDI predates and has no lineage to CEN TC 434, the same determination
as mcp-nfe-br). RFC validation for both Emisor and Receptor routes through
TaxIdentifier.validate_mx_rfc (core). Sealing routes through
mcp_einvoicing_core.digital_signature.SelloDigitalSigner, the MX-specific concrete
implementation of core's BaseDocumentSigner — the same pattern ES (XAdES), BR (XML-DSig),
and IT (CAdES) use for their own signature standards.
[ ERP System / Application ] <--> [ MCP Server ] <--> [ PAC (any, PAC-agnostic) / SAT ]
^ |
| v
[ AI Agent (Claude) ] <--- (CFDI 4.0 / Pagos 2.0)Vendor neutrality
This server implements the standard itself: it builds, validates, and signs the document locally. It is not a client for a commercial invoicing platform, and your signing keys and credentials never leave your own infrastructure.
A PAC (Proveedor Autorizado de Certificación) must stamp the CFDI; this server seals it locally with your own CSD and hands any PAC an already-sealed document.
Supported standards
Standard | Version | Source |
CFDI (Comprobante Fiscal Digital por Internet) | 4.0 | SAT Anexo 20, DOF 2022-01-13 |
Timbre Fiscal Digital | 1.1 | SAT |
Complemento de Pagos | 2.0 | SAT |
See specs/README.md for the full source bundle and retrieval dates.
Tests
uv run pytest tests/ -vContributing
Contributions are welcome — see CONTRIBUTING.md for guidelines.
Other e-invoicing MCP servers
Country | Server |
🌍 Global | |
🇧🇪 Belgium | |
🇧🇷 Brazil | |
🇫🇷 France | |
🇩🇪 Germany | |
🇮🇳 India | |
🇮🇹 Italy | |
🇲🇽 Mexico | |
🇵🇱 Poland | |
🇸🇬 Singapore | |
🇪🇸 Spain | |
🇦🇪 United Arab Emirates |
License
This project is distributed under the Apache 2.0 license. See the LICENSE file for details. For the full version history, see CHANGELOG.md.
Available Tools
6 toolsmx__build_cfdiMx Build CfdiA
Build a well-formed, unsealed CFDI 4.0 Comprobante XML (Ingreso or Egreso).
comprobante_data is validated against CFDIComprobante — see that
model for the full field list (seller/buyer as MXEmisor/
MXReceptor, lines as CFDIConcepto, tipo_de_comprobante, etc.).
RFC fields are validated via TaxIdentifier.validate_mx_rfc as part of
model construction; a malformed RFC is reported as a validation error,
not a generated document.
The output XML omits Sello/NoCertificado/Certificado — those three
schema-required attributes are populated by mx__seal_cfdi, run
afterward. mx__validate_cfdi run on this output is expected to report
exactly those three attributes missing; that is not a bug in this tool.
For TipoDeComprobante="P" (Complemento de Pagos), use mx__build_pago
instead — this tool only builds Ingreso/Egreso Comprobantes.
Returns a dict with:
xml: the generated, unsealed CFDI 4.0 XML stringtotal: the computedTotalattribute (SubTotal - Descuento + traslados - retenciones)
Inputs: comprobante_data (required). Returns: object
mx__build_pagoMx Build PagoA
Build a well-formed, unsealed Complemento de Pagos 2.0 CFDI.
Composes the fixed single-Concepto wrapper SAT's Guía de llenado de
pagos mandates for a Pago-type Comprobante (ClaveProdServ,
ClaveUnidad, Descripcion, ValorUnitario, Importe, ObjetoImp are
all fixed conventional values — see this module's docstring constants)
with the Pagos20 complement built from pagos_data, and attaches the
complement under cfdi:Complemento.
buyer.uso_cfdi is forced to "CP01" (the schema requires it for every
Pagos CFDI per the same guide, regardless of what the caller passes) —
mirrors how this tool already forces SubTotal/Moneda/etc.
The output XML omits Sello/NoCertificado/Certificado, same as
mx__build_cfdi — seal afterward with mx__seal_cfdi.
Returns a dict with:
xml: the generated, unsealed CFDI XML string (with the Pagos complement attached)
Inputs: pagos_data (required), comprobante_data (required). Returns: object
mx__get_supported_scopeMx Get Supported ScopeA
Return the CFDI document types, complementos, and sealing modes this package supports.
Reflects Phase 1 scope: CFDI 4.0 Ingreso + Egreso + Complemento de Pagos
2.0, PAC-agnostic sealing. Build (mx__build_cfdi/mx__build_pago),
XSD validation (mx__validate_cfdi), sealing (mx__seal_cfdi), and TFD
verification (mx__verify_tfd) are all implemented. PAC submission
transport and later-phase complementos are not.
Returns:
A ScopeInfo describing current scope, for callers to check before
assuming a document type or complemento is supported.
Inputs: no named parameters. Returns: MX's own scope fields on top of the shared base (core v1.32.0, CORE-8). Adds `s…
mx__seal_cfdiMx Seal CfdiA
Seal (or deliberately not seal) a CFDI 4.0 Comprobante, PAC-agnostic.
sealing_mode="local" computes the cadena original via the actual SAT
XSLT transform (resources/cadenaoriginal_4_0.xslt, with its
utilerias.xslt and Pagos20.xslt includes resolved from resources/;
any other complemento
include a document might reference is not in Phase-1 scope and stubs to
a no-op template — see SelloDigitalSigner's docstring), then computes
Sello/NoCertificado/Certificado via
mcp_einvoicing_core.digital_signature.SelloDigitalSigner — no local
reimplementation of the signing algorithm.
sealing_mode="pac" returns xml unchanged: some PACs accept an
unsealed, schema-valid CFDI and seal it on the emisor's behalf. This
tool does not submit to any PAC — see the package README for the
PAC-agnostic design.
CSD key material is always a file path, never accepted as plaintext key content in a tool argument.
Returns a dict with:
xml: the sealed (or, for"pac", unchanged) XML stringsealing_mode: echoes the mode used
Inputs: xml (required), sealing_mode (required), key_path, cert_path, +2 more. Returns: object
mx__validate_cfdiMx Validate CfdiA
Validate a CFDI 4.0 document against the official SAT XSD schemas.
Always validates the root Comprobante against cfdv40.xsd. If a
TimbreFiscalDigital complement is present (i.e. the document has been
stamped by a PAC), it is additionally validated against
TimbreFiscalDigitalv11.xsd.xml. If a Pagos complement is present
(TipoDeComprobante="P"), it is additionally validated against
Pagos20.xsd.xml.
This is XSD-only — business-rule checks from SAT's Matriz de errores
(specs/MatrizDeErrores_CFDI_v40_20260325.xls) are not run, mirroring
mcp-nfe-br's br__validate_nfe_xml precedent (XSD-first, business
rules deferred). A document that passes this validator is structurally
conformant but not guaranteed to pass PAC certification.
Returns a dict with:
valid: True only if every schema that applies passedcomprobante: thecfdv40.xsdvalidation resulttfd: the TFD validation result, present only if aTimbreFiscalDigitalelement was foundpagos: the Pagos 2.0 validation result, present only if aPagoselement was found
Inputs: xml (required). Returns: object
mx__verify_tfdMx Verify TfdA
Parse a Timbre Fiscal Digital 1.1 stamp and, optionally, verify SelloSAT.
Always returns the TFD's own attributes (UUID, FechaTimbrado,
RfcProvCertif, SelloCFD, NoCertificadoSAT, SelloSAT, ...) and the
recomputed cadena original (via cadenaoriginal_TFD_1_1.xslt, per
Anexo 20 Rubro III.B). If pac_certificado_der_b64 is supplied,
additionally verifies SelloSAT (SHA-256 + RSA-PKCS#1v1.5, the same
algorithm as the emisor's own Sello) against that certificate's public
key. Without it, sello_sat_verified is null — parsing succeeded but
cryptographic verification was not attempted, not "passed".
Returns a dict with:
found: False if noTimbreFiscalDigitalelement exists in xmlfields: the TFD's own attributescadena_original: the recomputed cadena original stringsello_sat_verified: True/False ifpac_certificado_der_b64was supplied, else null
Inputs: xml (required), pac_certificado_der_b64. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool maps to a distinct pipeline stage: build (cfdi/pago), seal, validate, verify, and scope introspection. The only adjacent pair, build_cfdi and build_pago, is explicitly differentiated by document type (Ingreso/Egreso vs Complemento de Pagos). No overlapping purposes remain.
All tools use a consistent namespace prefix (mx__) plus a snake_case verb_noun pattern: build_cfdi, seal_cfdi, validate_cfdi, build_pago, verify_tfd, get_supported_scope. No mixing of conventions.
Six tools cleanly cover the described Phase-1 CFDI lifecycle without redundancy. Each tool earns its place and the count is well within the 3-15 ideal range.
The surface covers building (both document types), sealing, XSD validation, and TFD verification, which is a coherent end-to-end flow for the stated scope. PAC submission transport and later-phase complementos are deliberately absent, a minor gap agents must work around externally.
Maintenance
Related MCP Connectors
CFDI 4.0 invoicing for Mexico: invoices, payments, receipts and SAT catalogs, stamped with SAT
Official Timbrix MCP server: stamp, cancel, and query Mexican CFDI 4.0 invoices from AI agents.
Brazilian fiscal MCP server - issue NF-e, NFC-e, NFS-e, CT-e, MDF-e and DC-e via SEFAZ.
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Related MCP Servers
- AlicenseAqualityBmaintenanceModel Context Protocol (MCP) server for French Electronic Invoicing (NF XP Z12-013). Provide tools to validate, generate, and explore API specifications for PDP/OD interoperability.341Apache 2.0
- AlicenseAqualityBmaintenanceModel Context Protocol (MCP) server for Italian Electronic Invoicing (FatturaPA / SDI). Provide tools to validate, generate, and explore API specifications for Sistema di Interscambio (SDI) interoperability.4374 PyPI2Apache 2.0
- AlicenseAqualityBmaintenanceModel Context Protocol (MCP) server for Polish Electronic Invoicing (KSeF / FA(2)). Provides tools to validate, generate, and explore API specifications for KSeF interoperability.10102 PyPI3Apache 2.0
- AlicenseBqualityBmaintenanceModel Context Protocol (MCP) server for Spanish Electronic Invoicing. Provides tools to generate, validate, and submit invoices across VERI\*FACTU, Facturae/FACe, SII, TicketBAI, and Crea y Crece B2B.20161 PyPI3Apache 2.0