validate_ereporting_xml
Validate a DGFiP e-reporting FRR XML payload against the official schema and identify structural errors before submission.
Instructions
Validate a DGFiP e-reporting (Flux 10) FRR XML payload.
Checks the XML against the DGFiP Spécifications Externes v3.2 ereporting.xsd. Returns validation result with errors if any. Use this before submitting to catch structural problems early.
Validation levels (in order of preference):
xsd — full schema validation (requires lxml)
wellformedness — basic XML parsing only (stdlib fallback)
none — XSD files not found on disk
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xml_content | Yes | FRR XML content to validate. Must be a complete Report document per DGFiP Spécifications Externes v3.2 ereporting.xsd. Full XSD validation requires lxml (`pip install lxml`); otherwise well-formedness is checked. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- tools/ereporting_tools.py:507-531 (handler)Main async handler for the 'validate_ereporting_xml' MCP tool. Accepts 'xml_content' parameter and delegates to _validate_against_xsd().
async def validate_ereporting_xml( xml_content: Annotated[ str, Field( description=( "FRR XML content to validate. Must be a complete Report document " "per DGFiP Spécifications Externes v3.2 ereporting.xsd. " "Full XSD validation requires lxml (`pip install lxml`); " "otherwise well-formedness is checked." ) ), ], ) -> dict[str, Any]: """Validate a DGFiP e-reporting (Flux 10) FRR XML payload. Checks the XML against the DGFiP Spécifications Externes v3.2 ereporting.xsd. Returns validation result with errors if any. Use this before submitting to catch structural problems early. Validation levels (in order of preference): - xsd — full schema validation (requires lxml) - wellformedness — basic XML parsing only (stdlib fallback) - none — XSD files not found on disk """ return _validate_against_xsd(xml_content) - tools/ereporting_tools.py:75-127 (helper)Core validation helper that checks XML against DGFiP ereporting.xsd. Falls back to well-formedness check if lxml is not installed, or 'none' if XSD files not found on disk.
def _validate_against_xsd(xml_content: str) -> dict[str, Any]: """Validate XML against DGFiP ereporting.xsd. Falls back to well-formedness check if lxml is not installed. """ xsd_path = _XSD_DIR / "ereporting.xsd" if not xsd_path.exists(): return { "valid": None, "level": "none", "message": ( f"XSD files not found at {_XSD_DIR}. " "Install the package from source to enable XSD validation." ), } # Try well-formedness first (always available) import xml.etree.ElementTree as ET # noqa: PLC0415 try: ET.fromstring(xml_content.encode("utf-8")) except ET.ParseError as exc: return {"valid": False, "level": "wellformedness", "errors": [str(exc)]} # Try lxml XSD validation try: from lxml import etree # type: ignore[import-not-found] # noqa: PLC0415 xml_doc = etree.fromstring(xml_content.encode("utf-8")) xsd_doc = etree.parse(str(xsd_path)) schema = etree.XMLSchema(xsd_doc) is_valid = schema.validate(xml_doc) errors = [str(e) for e in schema.error_log] return { "valid": is_valid, "level": "xsd", "errors": errors if not is_valid else [], } except ImportError: return { "valid": True, "level": "wellformedness", "message": ( "Well-formed XML. Full XSD validation requires lxml " "(`pip install lxml`). Install it for strict DGFiP schema checks." ), } except Exception as exc: # noqa: BLE001 return { "valid": None, "level": "error", "message": f"Validation error: {exc}", } - tools/ereporting_tools.py:503-532 (registration)Registration function that decorates the function with @mcp.tool() to register it with the FastMCP server.
def register_ereporting_tools(mcp: FastMCP) -> None: """Register all e-reporting tools with the MCP server.""" @mcp.tool() async def validate_ereporting_xml( xml_content: Annotated[ str, Field( description=( "FRR XML content to validate. Must be a complete Report document " "per DGFiP Spécifications Externes v3.2 ereporting.xsd. " "Full XSD validation requires lxml (`pip install lxml`); " "otherwise well-formedness is checked." ) ), ], ) -> dict[str, Any]: """Validate a DGFiP e-reporting (Flux 10) FRR XML payload. Checks the XML against the DGFiP Spécifications Externes v3.2 ereporting.xsd. Returns validation result with errors if any. Use this before submitting to catch structural problems early. Validation levels (in order of preference): - xsd — full schema validation (requires lxml) - wellformedness — basic XML parsing only (stdlib fallback) - none — XSD files not found on disk """ return _validate_against_xsd(xml_content) - tools/ereporting_tools.py:508-518 (schema)Parameter schema for xml_content using Annotated type with Pydantic Field description, defining the input structure for this tool.
xml_content: Annotated[ str, Field( description=( "FRR XML content to validate. Must be a complete Report document " "per DGFiP Spécifications Externes v3.2 ereporting.xsd. " "Full XSD validation requires lxml (`pip install lxml`); " "otherwise well-formedness is checked." ) ), ],