Skip to main content
Glama
cmendezs

mcp-facturacion-electronica-es

es__build_sii_invoice_record

Builds an XML SII invoice record for Spanish AEAT, supporting issued/received invoices with alta, modificación, or baja communication types.

Instructions

Construye un registro XML AEAT SII en formato SOAP (emisión FacturaExpedida o recepción FacturaRecibida) conforme a la guía técnica SII v3.0 (abril 2024). Soporta TipoComunicacion A0 (alta), A1 (modificación) y A4 (baja).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceYesDatos de la factura.
record_typeYesDirección: 'issued' (expedida) o 'received' (recibida).
communication_typeNoTipoComunicacion: A0 alta (por defecto), A1 modificación, A4 baja.A0

Implementation Reference

  • The handler function 'handle_es_build_sii_invoice_record' that executes the tool logic. It parses invoice data, record type, and communication type, then calls build_sii_issued_record or build_sii_received_record to produce the SOAP XML envelope.
    async def handle_es_build_sii_invoice_record(
        arguments: dict[str, Any],
    ) -> list[types.TextContent]:
        try:
            invoice_data = arguments.get("invoice")
            if not invoice_data:
                return err("invoice is required", "MISSING_PARAM")
    
            record_type_str = arguments.get("record_type", "issued")
            comm_type_str = arguments.get("communication_type", "A0")
    
            try:
                record_type = SIIRecordType(record_type_str)
            except ValueError:
                return err(f"Invalid record_type: {record_type_str!r}")
            try:
                comm_type = SIICommunicationType(comm_type_str)
            except ValueError:
                return err(f"Invalid communication_type: {comm_type_str!r}")
    
            invoice = parse_invoice(invoice_data)
    
            if record_type == SIIRecordType.issued:
                xml_bytes = build_sii_issued_record(invoice, comm_type.value)
            else:
                xml_bytes = build_sii_received_record(invoice, comm_type.value)
    
            logger.info(
                "SII %s record built for %s / %s (comm_type=%s)",
                record_type.value, invoice.seller.tax_id.identifier, invoice.number, comm_type.value,
            )
    
            return ok({
                "xml": xml_bytes.decode("utf-8"),
                "record_type": record_type.value,
                "communication_type": comm_type.value,
                "invoice_number": invoice.number,
            })
    
        except EInvoicingError as exc:
            return err(str(exc))
        except Exception as exc:
            logger.exception("es__build_sii_invoice_record failed")
            return err(str(exc))
  • The tool definition 'TOOL_ES_BUILD_SII_INVOICE_RECORD' with name, description, and inputSchema. Defines the invoice object, record_type (issued/received), and communication_type (A0/A1/A4) parameters.
    TOOL_ES_BUILD_SII_INVOICE_RECORD = types.Tool(
        name="es__build_sii_invoice_record",
        description=(
            "Construye un registro XML AEAT SII en formato SOAP (emisión FacturaExpedida o "
            "recepción FacturaRecibida) conforme a la guía técnica SII v3.0 (abril 2024). "
            "Soporta TipoComunicacion A0 (alta), A1 (modificación) y A4 (baja)."
        ),
        inputSchema={
            "type": "object",
            "properties": {
                "invoice": {
                    "type": "object",
                    "description": "Datos de la factura.",
                },
                "record_type": {
                    "type": "string",
                    "enum": ["issued", "received"],
                    "description": "Dirección: 'issued' (expedida) o 'received' (recibida).",
                },
                "communication_type": {
                    "type": "string",
                    "enum": ["A0", "A1", "A4"],
                    "description": "TipoComunicacion: A0 alta (por defecto), A1 modificación, A4 baja.",
                    "default": "A0",
                },
            },
            "required": ["invoice", "record_type"],
        },
    )
  • Import of TOOL_ES_BUILD_SII_INVOICE_RECORD and handle_es_build_sii_invoice_record from the sii module into server.py.
    from mcp_facturacion_electronica_es.tools.sii import (
        TOOL_ES_BUILD_SII_INVOICE_RECORD,
        TOOL_ES_GENERATE_SII_CORRECTION,
        TOOL_ES_QUERY_SII_STATUS,
        TOOL_ES_SUBMIT_SII_BATCH,
        handle_es_build_sii_invoice_record,
        handle_es_generate_sii_correction,
        handle_es_query_sii_status,
        handle_es_submit_sii_batch,
    )
    from mcp_facturacion_electronica_es.tools.ticketbai import (
        TOOL_ES_GENERATE_TICKETBAI_XML,
        TOOL_ES_SUBMIT_TICKETBAI,
  • Tool registered in the _ALL_TOOLS list that is returned by list_tools().
    _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,
  • Handler mapped in _TOOL_HANDLERS dict, dispatched by call_tool() when the tool is invoked.
    _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,
Behavior2/5

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

No annotations are provided, so the description must bear the full burden of behavioral disclosure. It describes building an XML record but does not mention side effects, authentication requirements, rate limits, or what the output is (e.g., returns the XML string or validates it). The lack of output schema exacerbates this gap.

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

Conciseness5/5

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

The description is two sentences long and front-loaded with the core purpose. Every word serves a purpose: format, technical reference, and supported types. No redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of SII XML building and the many sibling tools, the description covers the essential details: format, guide version, and communication types. However, it lacks information on the return value or any post-processing steps, which would enhance completeness.

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 description coverage is 100%, so all parameters have descriptions. The description adds context by mentioning the SII guide and communication types, which aligns with the enum. However, it does not clarify the structure of the 'invoice' object beyond 'Datos de la factura', so the added value is marginal.

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 clearly states the tool builds an XML AEAT SII record in SOAP format, specifying the technical guide version (v3.0) and supported communication types (A0, A1, A4). It differentiates from sibling tools that generate other XML formats like Facturae or TicketBAI.

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

Usage Guidelines3/5

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

The description implies usage for building SII records but does not provide explicit guidance on when to use this tool versus siblings (e.g., generate_facturae_xml for Facturae format). No when-not-to-use or alternative scenarios are mentioned.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cmendezs/mcp-facturacion-electronica-es'

If you have feedback or need assistance with the MCP directory API, please join our Discord server