es__submit_verifactu_to_aeat
Submit signed VERI*FACTU XML invoices to the AEAT real-time endpoint using MTLS authentication with FNMT-RCM certificate. Requires sender NIF and signed XML.
Instructions
Envía un registro VERI*FACTU firmado al endpoint en tiempo real de la AEAT mediante MTLS (certificado FNMT-RCM). Requiere AEAT_ENV, AEAT_CERTIFICATE_PATH y AEAT_CERTIFICATE_PASSWORD.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xml | Yes | Registro VERI*FACTU XML firmado. | |
| nif | Yes | NIF del remitente. |
Implementation Reference
- Handler function `handle_es_submit_verifactu_to_aeat` — sends a signed VERI*FACTU XML to the AEAT endpoint via MTLS (FNMT-RCM certificate). Validates required params (xml, nif), reads AEAT_CERTIFICATE_PATH/PASSWORD from env, picks endpoint based on AEAT_ENV, uses BaseEInvoicingClient with AuthMode.MTLS, POSTs the XML as a multipart file upload, returns status_code, env, and response_text.
async def handle_es_submit_verifactu_to_aeat( arguments: dict[str, Any], ) -> list[types.TextContent]: try: from mcp_einvoicing_core.http_client import AuthMode, BaseEInvoicingClient xml_str = arguments.get("xml", "") nif = arguments.get("nif", "") if not xml_str: return err("xml is required", "MISSING_PARAM") if not nif: return err("nif is required", "MISSING_PARAM") cert_path = os.environ.get("AEAT_CERTIFICATE_PATH") cert_password = os.environ.get("AEAT_CERTIFICATE_PASSWORD") if not cert_path: return err( "AEAT_CERTIFICATE_PATH no está configurado. " "Proporcione la ruta al certificado FNMT-RCM PKCS#12.", "MISSING_CONFIG", ) env = aeat_env() base_url = VERIFACTU_ENDPOINTS[env] client = BaseEInvoicingClient( base_url=base_url, auth_mode=AuthMode.MTLS, cert_path=cert_path, cert_password=cert_password, ) xml_bytes = xml_str.encode() if isinstance(xml_str, str) else xml_str response = await client._request( "POST", "", data=None, json=None, files={"xml": ("registro.xml", xml_bytes, "application/xml")}, ) # [NEED: parse AEAT VERI*FACTU response — use es__parse_aeat_response] return ok({ "status_code": response.status_code, "environment": env, "response_text": response.text[:2000], "note": ( "Use es__parse_aeat_response to parse the response XML " "and extract EstadoEnvio and CSV." ), }) except Exception as exc: logger.exception("es__submit_verifactu_to_aeat failed") return err(str(exc)) - Tool definition `TOOL_ES_SUBMIT_VERIFACTU_TO_AEAT` — declares the tool name 'es__submit_verifactu_to_aeat', description about MTLS submission to AEAT, and inputSchema requiring 'xml' (signed XML string) and 'nif' (sender NIF).
TOOL_ES_SUBMIT_VERIFACTU_TO_AEAT = types.Tool( name="es__submit_verifactu_to_aeat", description=( "Envía un registro VERI*FACTU firmado al endpoint en tiempo real de la AEAT mediante MTLS " "(certificado FNMT-RCM). Requiere AEAT_ENV, AEAT_CERTIFICATE_PATH y AEAT_CERTIFICATE_PASSWORD." ), inputSchema={ "type": "object", "properties": { "xml": {"type": "string", "description": "Registro VERI*FACTU XML firmado."}, "nif": {"type": "string", "description": "NIF del remitente."}, }, "required": ["xml", "nif"], }, ) - mcp_facturacion_electronica_es/server.py:77-106 (registration)Tool list `_ALL_TOOLS` includes TOOL_ES_SUBMIT_VERIFACTU_TO_AEAT on line 81, registering it as an available MCP tool.
_ALL_TOOLS: list[types.Tool] = [ # VERI*FACTU TOOL_ES_GENERATE_VERIFACTU_RECORD, TOOL_ES_VALIDATE_VERIFACTU_RECORD, TOOL_ES_SUBMIT_VERIFACTU_TO_AEAT, TOOL_ES_GENERATE_QR_VERIFACTU, TOOL_ES_CANCEL_VERIFACTU_RECORD, # Facturae / FACe TOOL_ES_GENERATE_FACTURAE_XML, TOOL_ES_SIGN_FACTURAE_XADES, TOOL_ES_SUBMIT_TO_FACE, TOOL_ES_GET_FACE_INVOICE_STATUS, TOOL_ES_VALIDATE_FACTURAE_SCHEMA, # SII TOOL_ES_BUILD_SII_INVOICE_RECORD, TOOL_ES_SUBMIT_SII_BATCH, TOOL_ES_QUERY_SII_STATUS, TOOL_ES_GENERATE_SII_CORRECTION, # TicketBAI TOOL_ES_GENERATE_TICKETBAI_XML, TOOL_ES_SUBMIT_TICKETBAI, TOOL_ES_VALIDATE_TICKETBAI_SCHEMA, # Crea y Crece / B2B TOOL_ES_GENERATE_B2B_EINVOICE_ES, TOOL_ES_CHECK_B2B_MANDATE_APPLICABILITY, # Utilities TOOL_ES_DETECT_REGIONAL_REGIME, TOOL_ES_GET_COMPLIANCE_STATUS, TOOL_ES_PARSE_AEAT_RESPONSE, ] - mcp_facturacion_electronica_es/server.py:108-137 (registration)Handler map `_TOOL_HANDLERS` maps the string 'es__submit_verifactu_to_aeat' to the function handle_es_submit_verifactu_to_aeat on line 112.
_TOOL_HANDLERS: dict[str, Any] = { # VERI*FACTU "es__generate_verifactu_record": handle_es_generate_verifactu_record, "es__validate_verifactu_record": handle_es_validate_verifactu_record, "es__submit_verifactu_to_aeat": handle_es_submit_verifactu_to_aeat, "es__generate_qr_verifactu": handle_es_generate_qr_verifactu, "es__cancel_verifactu_record": handle_es_cancel_verifactu_record, # Facturae / FACe "es__generate_facturae_xml": handle_es_generate_facturae_xml, "es__sign_facturae_xades": handle_es_sign_facturae_xades, "es__submit_to_face": handle_es_submit_to_face, "es__get_face_invoice_status": handle_es_get_face_invoice_status, "es__validate_facturae_schema": handle_es_validate_facturae_schema, # SII "es__build_sii_invoice_record": handle_es_build_sii_invoice_record, "es__submit_sii_batch": handle_es_submit_sii_batch, "es__query_sii_status": handle_es_query_sii_status, "es__generate_sii_correction": handle_es_generate_sii_correction, # TicketBAI "es__generate_ticketbai_xml": handle_es_generate_ticketbai_xml, "es__submit_ticketbai": handle_es_submit_ticketbai, "es__validate_ticketbai_schema": handle_es_validate_ticketbai_schema, # Crea y Crece / B2B "es__generate_b2b_einvoice_es": handle_es_generate_b2b_einvoice_es, "es__check_b2b_mandate_applicability": handle_es_check_b2b_mandate_applicability, # Utilities "es__detect_regional_regime": handle_es_detect_regional_regime, "es__get_compliance_status": handle_es_get_compliance_status, "es__parse_aeat_response": handle_es_parse_aeat_response, } - VERIFACTU_ENDPOINTS dictionary mapping sandbox/production environments to AEAT VERI*FACTU submission URLs. Used by the handler to determine the target endpoint.
VERIFACTU_ENDPOINTS: dict[str, str] = { "sandbox": ( "https://prewww2.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/FactSistemaFacturacion" ), "production": ( "https://www2.agenciatributaria.gob.es" "/wlpl/TIKE-CONT/ws/SistemaFacturacion/FactSistemaFacturacion" ), # [NEED: verify production URL against published AEAT technical guide]