Skip to main content
Glama
cmendezs

mcp-fattura-elettronica-it

build_transmission_header

Builds the required DatiTrasmissione block for FatturaPA invoices. Validates transmission format and recipient code, returning the header ready for XML generation.

Instructions

Build the DatiTrasmissione block required in every FatturaPA header.

Use this as step 3 in the invoice generation workflow, after generate_progressivo_invio() and before validate_cedente_prestatore(). Use lookup_codice_destinatario() first to confirm the recipient code format.

Validates: formato_trasmissione must be 'FPA12' or 'FPR12'; progressivo_invio must be 1–10 alphanumeric characters; pec_destinatario is required when codice_destinatario is '0000000'.

On success returns {'DatiTrasmissione': {...}} ready to pass to generate_fattura_xml(). On failure returns {'error': ''} — do not proceed to XML generation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
id_paeseYesTwo-letter ISO 3166-1 country code of the transmitter (e.g. 'IT'). Usually 'IT' for Italian entities.
id_codiceYesTax identifier of the transmitter: Partita IVA (11 digits) for Italian entities, or foreign tax ID (max 28 chars) for cross-border.
progressivo_invioYesUnique sequential send identifier, max 10 alphanumeric characters. Use generate_progressivo_invio() to obtain one automatically.
formato_trasmissioneYesTransmission format: 'FPA12' for invoices to Public Administration (PA), 'FPR12' for invoices to private parties (B2B / B2C).
codice_destinatarioYes6-character alphanumeric SDI recipient code assigned to the buyer's intermediary. Use '0000000' (7 zeros) when routing via PEC email instead.
pec_destinatarioNoPEC (certified email) address of the recipient. Required only when codice_destinatario is '0000000'.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function that builds the DatiTrasmissione block. It validates inputs (formato_trasmissione, progressivo_invio, pec_destinatario requirement), constructs the result dict, and returns it.
    def build_transmission_header(
        id_paese: Annotated[
            str,
            Field(
                description=(
                    "Two-letter ISO 3166-1 country code of the transmitter (e.g. 'IT'). "
                    "Usually 'IT' for Italian entities."
                )
            ),
        ],
        id_codice: Annotated[
            str,
            Field(
                description=(
                    "Tax identifier of the transmitter: Partita IVA (11 digits) for Italian "
                    "entities, or foreign tax ID (max 28 chars) for cross-border."
                )
            ),
        ],
        progressivo_invio: Annotated[
            str,
            Field(
                description=(
                    "Unique sequential send identifier, max 10 alphanumeric characters. "
                    "Use generate_progressivo_invio() to obtain one automatically."
                )
            ),
        ],
        formato_trasmissione: Annotated[
            str,
            Field(
                description=(
                    "Transmission format: 'FPA12' for invoices to Public Administration (PA), "
                    "'FPR12' for invoices to private parties (B2B / B2C)."
                )
            ),
        ],
        codice_destinatario: Annotated[
            str,
            Field(
                description=(
                    "6-character alphanumeric SDI recipient code assigned to the buyer's "
                    "intermediary. Use '0000000' (7 zeros) when routing via PEC email instead."
                )
            ),
        ],
        pec_destinatario: Annotated[
            Optional[str],
            Field(
                default=None,
                description=(
                    "PEC (certified email) address of the recipient. "
                    "Required only when codice_destinatario is '0000000'."
                ),
            ),
        ] = None,
    ) -> dict:
        """Build the DatiTrasmissione block required in every FatturaPA header.
    
        Use this as step 3 in the invoice generation workflow, after
        generate_progressivo_invio() and before validate_cedente_prestatore().
        Use lookup_codice_destinatario() first to confirm the recipient code format.
    
        Validates: formato_trasmissione must be 'FPA12' or 'FPR12'; progressivo_invio
        must be 1–10 alphanumeric characters; pec_destinatario is required when
        codice_destinatario is '0000000'.
    
        On success returns {'DatiTrasmissione': {...}} ready to pass to generate_fattura_xml().
        On failure returns {'error': '<reason>'} — do not proceed to XML generation.
        """
        if formato_trasmissione not in ("FPA12", "FPR12"):
            return {"error": f"Invalid formato_trasmissione '{formato_trasmissione}'. Must be 'FPA12' or 'FPR12'."}
    
        if len(progressivo_invio) > 10 or not re.match(r"^[A-Za-z0-9]+$", progressivo_invio):
            return {"error": "progressivo_invio must be 1–10 alphanumeric characters."}
    
        if codice_destinatario == "0000000" and not pec_destinatario:
            return {"error": "pec_destinatario is required when codice_destinatario is '0000000'."}
    
        result: dict = {
            "DatiTrasmissione": {
                "IdTrasmittente": {
                    "IdPaese": id_paese.upper(),
                    "IdCodice": id_codice,
                },
                "ProgressivoInvio": progressivo_invio,
                "FormatoTrasmissione": formato_trasmissione,
                "CodiceDestinatario": codice_destinatario,
            }
        }
        if pec_destinatario:
            result["DatiTrasmissione"]["PECDestinatario"] = pec_destinatario
    
        return result
  • The input schema/type definitions for the tool, using Pydantic Field annotations to describe each parameter (5 required + 1 optional).
    def build_transmission_header(
        id_paese: Annotated[
            str,
            Field(
                description=(
                    "Two-letter ISO 3166-1 country code of the transmitter (e.g. 'IT'). "
                    "Usually 'IT' for Italian entities."
                )
            ),
        ],
        id_codice: Annotated[
            str,
            Field(
                description=(
                    "Tax identifier of the transmitter: Partita IVA (11 digits) for Italian "
                    "entities, or foreign tax ID (max 28 chars) for cross-border."
                )
            ),
        ],
        progressivo_invio: Annotated[
            str,
            Field(
                description=(
                    "Unique sequential send identifier, max 10 alphanumeric characters. "
                    "Use generate_progressivo_invio() to obtain one automatically."
                )
            ),
        ],
        formato_trasmissione: Annotated[
            str,
            Field(
                description=(
                    "Transmission format: 'FPA12' for invoices to Public Administration (PA), "
                    "'FPR12' for invoices to private parties (B2B / B2C)."
                )
            ),
        ],
        codice_destinatario: Annotated[
            str,
            Field(
                description=(
                    "6-character alphanumeric SDI recipient code assigned to the buyer's "
                    "intermediary. Use '0000000' (7 zeros) when routing via PEC email instead."
                )
            ),
        ],
        pec_destinatario: Annotated[
            Optional[str],
            Field(
                default=None,
                description=(
                    "PEC (certified email) address of the recipient. "
                    "Required only when codice_destinatario is '0000000'."
                ),
            ),
        ] = None,
    ) -> dict:
  • Tool is registered via the @mcp.tool() decorator inside register_header_tools() which is called from server.py.
    @mcp.tool()
    def build_transmission_header(
  • Registration wrapper function that decorates build_transmission_header (and 6 other tools) with @mcp.tool().
    def register_header_tools(mcp: FastMCP) -> None:
        """Register the 7 FatturaElettronicaHeader tools on the FastMCP instance."""
  • The output of build_transmission_header() is consumed by generate_fattura_xml() as the dati_trasmissione parameter.
                "DatiTrasmissione block from build_transmission_header(). "
                "Must contain IdTrasmittente, ProgressivoInvio, FormatoTrasmissione, "
                "and CodiceDestinatario."
            )
        ),
    ],
    cedente_prestatore: Annotated[
        dict,
        Field(
            description=(
                "CedentePrestatore block from validate_cedente_prestatore(). "
                "Contains seller's tax ID, name, address, and fiscal regime."
            )
        ),
    ],
    cessionario_committente: Annotated[
        dict,
        Field(
            description=(
                "CessionarioCommittente block from validate_cessionario(). "
                "Contains buyer's tax ID, name, and address."
            )
        ),
    ],
    dati_generali: Annotated[
        dict,
        Field(
            description=(
                "DatiGenerali block from build_dati_generali(). "
                "Contains document type, date, number, and currency."
            )
        ),
    ],
    dettaglio_linee: Annotated[
        list,
        Field(
            description=(
                "List of DettaglioLinee dicts from add_linea_dettaglio(). "
                "Each entry must have NumeroLinea, Descrizione, PrezzoUnitario, "
                "PrezzoTotale, and AliquotaIVA."
            )
        ),
    ],
    dati_riepilogo: Annotated[
        list,
        Field(
            description=(
                "List of DatiRiepilogo dicts from compute_totali(). "
                "Contains VAT summary grouped by AliquotaIVA."
            )
        ),
    ],
    dati_pagamento: Annotated[
        Optional[dict],
Behavior5/5

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

Discloses validation behavior for formato_trasmissione, progressivo_invio, and pec_destinatario condition. Describes both success and failure outputs, including a warning not to proceed on failure. With no annotations, the description fully carries the transparency burden.

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?

The description is mostly concise with clear workflow steps and validation rules. It could be slightly more compact, but every sentence adds value and no wasted words.

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?

Given the tool's role in a complex multi-step workflow with 6 parameters and no annotations, the description fully covers usage, validation, output format, and error handling, making it contextually complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds validation rules and context beyond schema descriptions, such as the requirement for pec_destinatario when codice_destinatario is '0000000' and the format constraints for progression_invio.

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 the DatiTrasmissione block for FatturaPA headers, distinguishing it from sibling tools like build_dati_generali and validate_cedente_prestatore by specifying it's step 3 in the workflow.

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 instructs when to use (step 3 after generate_progressivo_invio, before validate_cedente_prestatore) and recommends using lookup_codice_destinatario first. Provides validation rules for parameters.

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-fattura-elettronica-it'

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