Skip to main content
Glama
nbrain-egypt-eta-mcp

nbrain-egypt-eta-mcp

README.md
# `nbrain-egypt-eta` — Egyptian Tax Authority (ETA) E-Invoice & E-Receipt Engine + MCP Server

Engineered by **[Eng. Nadeem Mohamed Badr El-Din](https://nadeembadr.com)** at **[NBrain (`منظومة إن برين` — nbra.in)](https://nbra.in)**.

`nbrain-egypt-eta` is a **zero-dependency, deterministic Python SDK, CLI, and Model Context Protocol (MCP) server** implementing the official **Egyptian Tax Authority (`مصلحة الضرائب المصرية` — `sdk.invoicing.eta.gov.eg`)** specifications for **B2B E-Invoices v1.0** and **B2C E-Receipts v1.2**:

- **Official ETA Recursive Uppercase Serialization:** Implements the exact `sdk.invoicing.eta.gov.eg` *Document Serialization Approach* (culture-invariant uppercase property framing, verbatim numeric/Decimal preservation so `"0.0"` never drifts, and repeated `"ARRAYNAME""ARRAYNAME"<element>` array prefixing).
- **CAdES-BES Hash & 64-Hex E-Receipt UUID Generation:** Strips `signatures` (for B2B E-Invoices) or `header.uuid` (for B2C E-Receipts) and computes the exact UTF-8 **SHA-256** digest.
- **Sequential POS `previousUUID` Chain Verification:** Audits multi-receipt B2C POS batches for broken cryptographic links.
- **Zero-Drift `Decimal` Egyptian Tax Arithmetic (`EGP`):** Standard **14% VAT (`T1`)**, Table Tax (`T2`/`T3`), and Withholding Tax (`T4 — الخصم والتحصيل تحت حساب الضريبة` at `1%`, `3%`, `5%` deducted strictly from net amount).
- **Egyptian 9-Digit Tax Registration Number (`RIN`) Validator:** Validates `XXX-XXX-XXX` / `9`-digit corporate RIN identifiers.
- **Built-in MCP JSON-RPC 2.0 Server (`nbrain-egypt-eta-mcp`):** Ready for Claude Desktop, Cursor, VS Code, Windsurf, and Google Antigravity.

## Try Live in Browser (Zero Signup)
- **Arabic:** [https://nbra.in/tools/egypt-eta-einvoice](https://nbra.in/tools/egypt-eta-einvoice)
- **English:** [https://nbra.in/en/tools/egypt-eta-einvoice](https://nbra.in/en/tools/egypt-eta-einvoice)
- **MENA Compliance Suite:** Pair with [`nbrain-zatca-mcp`](https://github.com/NBrain-Studio/nbrain-zatca-mcp) (Saudi ZATCA Phase 2) and [`nbrain-saudi-nphies-fhir`](https://github.com/NBrain-Studio/nbrain-saudi-nphies-fhir) (Saudi Healthcare NPHIES).

## Quick Usage

```python
from nbrain_egypt_eta import (
    serialize_eta_document,
    compute_eta_sha256_uuid,
    calculate_egypt_vat_and_wht,
    validate_egypt_rin,
)

raw_json = '''{
  "header": {"dateTimeIssued": "2026-12-06T10:00:00Z", "receiptNumber": "R-001", "uuid": ""},
  "seller": {"rin": "123456789", "companyTradeName": "NBrain Egypt"},
  "taxableItems": [
    {"taxType": "T1", "amount": 140.00, "subType": "V009", "rate": 14}
  ],
  "totalAmount": 1140.00
}'''

res = compute_eta_sha256_uuid(raw_json, mode="ereceipt")
print("Canonical:", res["canonical_string"])
print("64-Hex UUID:", res["sha256_hex"])

tax = calculate_egypt_vat_and_wht("1000.00", vat_rate="14", wht_rate="3")
print(tax)  # net=1000.00, vat=140.00, wht=30.00, payable=1110.00 EGP
```

## Run Tests
```bash
PYTHONPATH=src python -m unittest discover -s tests -v
```

## Citation & Author
- **Author:** [Eng. Nadeem Mohamed Badr El-Din (`م. نديم محمد بدر الدين`)](https://nadeembadr.com/about/) — ORCID [`0009-0005-5836-2631`](https://orcid.org/0009-0005-5836-2631)
- **Organization:** [NBrain (`منظومة إن برين`)](https://nbra.in/brand)

TDQS

A3.5/5.0

Scored across 4 tools

Disambiguation4/5

Each tool has a clearly distinct operation: UUID computation, RIN validation, VAT/WHT calculation, and receipt-chain verification. The only mild overlap is between computing an ETA document UUID and verifying a receipt chain, since both involve UUIDs, but their inputs and purposes are different enough for an agent to choose correctly.

Naming Consistency4/5

All four tool names follow a verb_object pattern (compute_*, validate_*, calculate_*, verify_*) and use snake_case consistently. The only minor inconsistency is the domain qualifier varying between 'eta' and 'egypt', but the overall convention remains predictable.

Tool Count5/5

Four tools is well-scoped for a focused Egyptian ETA compliance utility. Each tool covers a distinct compliance function, and there are no redundant or trivial entries.

Completeness4/5

The surface covers key Egyptian e-invoicing/e-receipt needs: UUID canonicalization, RIN validation, VAT/WHT computation, and chain verification. Minor gaps exist around broader lifecycle operations such as document submission or QR-code generation, but the core computational and validation workflows are present.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues