Skip to main content
Glama
MaurizioLisanti

fatturapa-mcp-server

find_invoice_anomalies

Detect inconsistencies and anomalies in FatturaPA XML documents to validate invoice totals, VAT, dates, P.IVA, destination codes, line items, negative amounts, and payment data.

Instructions

Detect inconsistencies and anomalies in a FatturaPA XML document.

Checks eight anomaly categories: document total mismatch, VAT calculation error, future invoice date, invalid Italian P.IVA checksum, missing or suspicious destination code, incomplete line items, unjustified negative amount, and missing payment data. Never logs or persists XML content.

When file_path is given the document is read from disk; the path is checked against the roots configured in FATTURAPA_ALLOWED_ROOTS before any read is attempted. Pass xml_content directly to skip file I/O.

Args: xml_content: Raw XML string of the FatturaPA document. ctx: Optional MCP context for structured log emission. file_path: Optional filesystem path to read the document from. Checked against allowed roots before reading.

Returns: A FindAnomaliesResult with keys: anomalies_found (int): Total number of anomalies detected. anomalies (list): All anomaly records. warnings (list): Only warning-severity anomalies. errors (list): Only error-severity anomalies. is_clean (bool): True when no anomalies are found.

Raises: PermissionError: If file_path is outside the configured allowed roots. ValueError: If neither xml_content nor file_path is provided. lxml.etree.XMLSyntaxError: If the XML is not well-formed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathNo
xml_contentNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
errorsYes
is_cleanYes
warningsYes
anomaliesYes
anomalies_foundYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.2

TDQS

A3.6/5.0
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It discloses that XML is never logged or persisted, that file_path is checked against FATTURAPA_ALLOWED_ROOTS, and it lists PermissionError, ValueError, and XMLSyntaxError, which is valuable operational context. It does not explicitly state read-only semantics, but the behavioral body is strong.

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?

Front-loads purpose, then uses Args/Returns/Raises sections efficiently. The Returns block duplicates the existing output schema, and the Args block includes a non-schema ctx parameter, but the description is well organized and not bloated relative to the tool's complexity.

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?

Covers purpose, parameter usage, security constraints, error cases, and a return summary, which is sufficient for correct invocation. The main gap is sibling routing: nothing tells the agent when this tool is preferable to validate_invoice or check_piva.

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 description coverage is 0%, so the description must compensate. It explains xml_content as a raw XML string and file_path as an optional path checked against allowed roots and skippable by passing XML directly, adding real meaning beyond the bare schema. It also lists a 'ctx' parameter that is not in the schema, a minor mismatch.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb ('Detect') and resource ('inconsistencies and anomalies in a FatturaPA XML document') and enumerates eight anomaly categories, so the agent knows exactly what it does. However, it does not distinguish itself from sibling tools like validate_invoice or check_piva.

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

Usage Guidelines2/5

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

No guidance on when to choose this tool over validate_invoice, check_piva, or other siblings. The only usage notes concern file_path versus xml_content input, not tool selection.

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