Skip to main content
Glama
cmendezs

mcp-einvoicing-de

invoice_parse

Extract structured JSON data from ZUGFeRD 2.x or XRechnung 3.x invoices. Accepts raw XML, base64 XML, or base64 PDF (hybrid) and returns a structured invoice data model.

Instructions

Extract structured data from a ZUGFeRD 2.x or XRechnung 3.x invoice. Accepts raw XML (CII or UBL), base64-encoded XML, or base64-encoded PDF (ZUGFeRD hybrid — the XML is extracted from the PDF/A-3 attachment). Returns a structured JSON object matching the invoice data model.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xml_contentNoRaw XML string.
xml_base64NoBase64-encoded XML.
pdf_base64NoBase64-encoded PDF (ZUGFeRD hybrid).
include_raw_xmlNo

Implementation Reference

  • MCP handler for invoice_parse: validates input, resolves XML bytes (from raw/base64/PDF), detects syntax & profile, dispatches to CII or UBL parser, and returns structured output as JSON.
    async def handle_invoice_parse(arguments: dict[str, Any]) -> list[types.TextContent]:
        """MCP handler for invoice_parse."""
        try:
            params = InvoiceParseInput.model_validate(arguments)
        except Exception as exc:
            return [types.TextContent(type="text", text=json.dumps(format_error(str(exc))))]
    
        # Resolve input to XML bytes
        xml_bytes: bytes
        if params.pdf_base64 is not None:
            try:
                pdf_bytes = base64.b64decode(params.pdf_base64)
                xml_bytes = _extract_xml_from_pdf(pdf_bytes)
            except (NotImplementedError, EInvoicingError, Exception) as exc:
                return [types.TextContent(type="text", text=json.dumps(format_error(str(exc))))]
        else:
            try:
                xml_bytes = resolve_xml_input(params.xml_content, params.xml_base64)
            except (ValueError, EInvoicingError) as exc:
                return [types.TextContent(type="text", text=json.dumps(format_error(str(exc))))]
    
        try:
            syntax = detect_invoice_syntax(xml_bytes)
            profile = detect_zugferd_profile(xml_bytes)
        except ValueError as exc:
            return [types.TextContent(type="text", text=json.dumps(format_error(str(exc))))]
    
        if syntax == "CII" or syntax.value == "CII":
            invoice_data = _parse_cii_xml(xml_bytes)
        else:
            invoice_data = _parse_ubl_xml(xml_bytes)
    
        output = InvoiceParseOutput(
            profile=profile.name if profile else "UNKNOWN",
            syntax=syntax.value if hasattr(syntax, "value") else str(syntax),
            invoice_data=invoice_data,
            raw_xml=xml_bytes.decode("utf-8", errors="replace") if params.include_raw_xml else None,
        )
    
        return [types.TextContent(type="text", text=output.model_dump_json(indent=2))]
  • Input schema — accepts raw XML, base64-encoded XML, or base64-encoded PDF, with an option to include raw XML in output.
    class InvoiceParseInput(BaseModel):
        """Input schema for invoice_parse."""
    
        xml_content: str | None = Field(None, description="Raw XML string.")
        xml_base64: str | None = Field(None, description="Base64-encoded XML bytes.")
        pdf_base64: str | None = Field(
            None,
            description=(
                "Base64-encoded PDF bytes. The tool will extract the embedded XML "
                "attachment (ZUGFeRD hybrid PDF/A-3)."
            ),
        )
        include_raw_xml: bool = Field(
            False, description="Include the raw XML string in the response."
        )
  • Output schema — profile, syntax, key summary fields, full parsed invoice_data, and optional raw XML.
    class InvoiceParseOutput(BaseModel):
        """Output schema for invoice_parse."""
    
        profile: str
        syntax: str
        invoice_number: str | None = None
        invoice_date: str | None = None
        seller_name: str | None = None
        buyer_name: str | None = None
        tax_inclusive_amount: str | None = None
        currency_code: str | None = None
        invoice_data: dict[str, Any] = Field(
            default_factory=dict, description="Full parsed invoice matching ZUGFeRDInvoice schema."
        )
        raw_xml: str | None = None
  • Tool definition object TOOL_INVOICE_PARSE with name, description, and JSON Schema input schema (oneOf xml_content, xml_base64, pdf_base64).
    TOOL_INVOICE_PARSE = types.Tool(
        name="invoice_parse",
        description=(
            "Extract structured data from a ZUGFeRD 2.x or XRechnung 3.x invoice. "
            "Accepts raw XML (CII or UBL), base64-encoded XML, or base64-encoded PDF "
            "(ZUGFeRD hybrid — the XML is extracted from the PDF/A-3 attachment). "
            "Returns a structured JSON object matching the invoice data model."
        ),
        inputSchema={
            "type": "object",
            "properties": {
                "xml_content": {"type": "string", "description": "Raw XML string."},
                "xml_base64": {"type": "string", "description": "Base64-encoded XML."},
                "pdf_base64": {"type": "string", "description": "Base64-encoded PDF (ZUGFeRD hybrid)."},
                "include_raw_xml": {"type": "boolean", "default": False},
            },
            "anyOf": [
                {"required": ["xml_content"]},
                {"required": ["xml_base64"]},
                {"required": ["pdf_base64"]},
            ],
        },
    )
  • Server registration: TOOL_INVOICE_PARSE imported and added to _ALL_TOOLS list, handle_invoice_parse mapped in _TOOL_HANDLERS dict.
    from mcp_einvoicing_de.tools.invoice_parse import TOOL_INVOICE_PARSE, handle_invoice_parse
    from mcp_einvoicing_de.tools.invoice_validate import TOOL_INVOICE_VALIDATE, handle_invoice_validate
    from mcp_einvoicing_de.tools.peppol_check import TOOL_PEPPOL_CHECK, handle_peppol_check
    from mcp_einvoicing_de.tools.tax_rules import TOOL_TAX_RULES, handle_tax_rules
    
    LOG_LEVEL = os.environ.get("EINVOICING_DE_LOG_LEVEL", "INFO").upper()
    logging.basicConfig(level=getattr(logging, LOG_LEVEL, logging.INFO))
    logger = logging.getLogger(__name__)
    
    _ALL_TOOLS: list[types.Tool] = [
        TOOL_INVOICE_CREATE,
        TOOL_INVOICE_VALIDATE,
        TOOL_INVOICE_PARSE,
        TOOL_INVOICE_CONVERT,
        TOOL_PEPPOL_CHECK,
        TOOL_TAX_RULES,
    ]
    
    _TOOL_HANDLERS: dict[str, Any] = {
        "invoice_create": handle_invoice_create,
        "invoice_validate": handle_invoice_validate,
        "invoice_parse": handle_invoice_parse,
        "invoice_convert": handle_invoice_convert,
        "peppol_check": handle_peppol_check,
        "tax_rules": handle_tax_rules,
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It describes inputs and outputs but does not mention non-destructive nature, required permissions, or any limitations. Adequate but could be more explicit about side effects.

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?

Description is three sentences, front-loaded with purpose, and contains no fluff. Every sentence adds value, making it efficient for an agent to parse.

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 no output schema and no annotations, the description covers core functionality well. However, it lacks details on error handling, file size limits, or encoding requirements, which would be beneficial for a parsing tool.

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

Parameters4/5

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

Schema has 75% coverage; description adds context beyond schema by explaining PDF extraction from ZUGFeRD hybrid and that output is structured JSON. The description clarifies that only one input method is required, which is not explicit in schema.

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?

Description clearly states the verb 'extract structured data' and specifies the specific invoice standards (ZUGFeRD 2.x, XRechnung 3.x) and input formats. This distinguishes it from sibling tools like invoice_create or invoice_validate.

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 parsing invoices but does not explicitly state when to use this tool versus alternatives like invoice_convert or invoice_validate. No exclusion criteria or context provided.

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-einvoicing-de'

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