Skip to main content
Glama

mcp-cfdi-mx 🇲🇽

English | Español

License PyPI version Python mcp-cfdi-mx MCP server

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

pip install mcp-cfdi-mx

Or without prior installation using uvx:

uvx mcp-cfdi-mx

From source

git clone https://github.com/cmendezs/mcp-cfdi-mx.git
cd mcp-cfdi-mx
uv sync --all-extras

Configuration (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.json

  • Per 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.json

  • Workspace: .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

mx__build_cfdi

Build a well-formed, unsealed CFDI 4.0 Comprobante XML (Ingreso or Egreso) from structured input

mx__build_pago

Build a Complemento de Pagos 2.0 CFDI (TipoDeComprobante="P"), composing the fixed single-Concepto wrapper SAT's guide mandates

Validate and seal

Tool

Description

mx__validate_cfdi

Full XSD validation against cfdv40.xsd, plus TimbreFiscalDigitalv11.xsd.xml and/or Pagos20.xsd.xml when those complements are present

mx__seal_cfdi

Compute the Sello Digital via SelloDigitalSigner, sealing_mode-aware ("local" | "pac")

mx__verify_tfd

Parse a PAC-returned Timbre Fiscal Digital 1.1 stamp, and cryptographically verify SelloSAT when the PAC's certificate is supplied

Scope

Tool

Description

mx__get_supported_scope

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/ -v

Contributing

Contributions are welcome — see CONTRIBUTING.md for guidelines.

Other e-invoicing MCP servers

Country

Server

🌍 Global

mcp-einvoicing-core

🇧🇪 Belgium

mcp-einvoicing-be

🇧🇷 Brazil

mcp-nfe-br

🇫🇷 France

mcp-facture-electronique-fr

🇩🇪 Germany

mcp-einvoicing-de

🇮🇳 India

mcp-einvoicing-in

🇮🇹 Italy

mcp-fattura-elettronica-it

🇲🇽 Mexico

mcp-cfdi-mx

🇵🇱 Poland

mcp-ksef-pl

🇸🇬 Singapore

mcp-invoicenow-sg

🇪🇸 Spain

mcp-facturacion-electronica-es

🇦🇪 United Arab Emirates

mcp-einvoicing-ae

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 tools
mx__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 string

  • total: the computed Total attribute (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 string

  • sealing_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 passed

  • comprobante: the cfdv40.xsd validation result

  • tfd: the TFD validation result, present only if a TimbreFiscalDigital element was found

  • pagos: the Pagos 2.0 validation result, present only if a Pagos element 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 no TimbreFiscalDigital element exists in xml

  • fields: the TFD's own attributes

  • cadena_original: the recomputed cadena original string

  • sello_sat_verified: True/False if pac_certificado_der_b64 was 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

    A4.6/5.0

    Scored across 6 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Model 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.
      34
      1
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      Model 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.
      43
      74 PyPI
      2
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      Model Context Protocol (MCP) server for Polish Electronic Invoicing (KSeF / FA(2)). Provides tools to validate, generate, and explore API specifications for KSeF interoperability.
      10
      102 PyPI
      3
      Apache 2.0
    • A
      license
      B
      quality
      B
      maintenance
      Model 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.
      20
      161 PyPI
      3
      Apache 2.0