ts-anaf
TypeScript SDK, CLI, and MCP server for Romania's ANAF e-Factura system.
Upload invoices, check statuses, download responses, validate XML, generate UBL, and look up company data — from code, the command line, or directly from an AI agent.
Packages
| Package | Description | Install |
|---|
| @florinszilagyi/anaf-ts-sdk | TypeScript SDK — OAuth, upload, status, download, UBL builder, company lookup | pnpm add @florinszilagyi/anaf-ts-sdk |
| @florinszilagyi/anaf-cli | Command-line tool — wraps the SDK with context management and JSON output | npm i -g @florinszilagyi/anaf-cli |
| @florinszilagyi/anaf-mcp | MCP server — exposes all SDK operations as tools for AI agents (Claude, etc.) | npx @florinszilagyi/anaf-mcp |
Agentic flows (Claude Code / Claude Desktop)
The MCP server lets an AI agent handle the full e-Factura workflow on your behalf — authenticate, build UBL invoices, validate, upload, poll status, and download — without writing any code.
Install via Claude Code plugin marketplace
/plugin marketplace add florin-szilagyi/ts-anaf
/plugin install anaf-mcp@ts-anaf # MCP server + skills
/plugin install anaf-cli@ts-anaf # CLI skills (manifest mode, scripting)
You need an OAuth application registered in the ANAF portal — see the official registration guide.
After install, set your ANAF OAuth credentials in the MCP server env (via /mcp settings):
{
"ANAF_CLIENT_ID": "your-client-id",
"ANAF_CLIENT_SECRET": "your-client-secret",
"ANAF_REDIRECT_URI": "https://localhost:9002/callback",
"ANAF_ENV": "prod"
}
Test vs Production: Set ANAF_ENV to "test" to use the ANAF sandbox — no real invoices are submitted. Switch to "prod" when ready for live use.
Manual setup (Claude Desktop / Claude Code)
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"anaf": {
"command": "npx",
"args": ["-y", "@florinszilagyi/anaf-mcp"],
"env": {
"ANAF_CLIENT_ID": "your-client-id",
"ANAF_CLIENT_SECRET": "your-client-secret",
"ANAF_REDIRECT_URI": "https://localhost:9002/callback",
"ANAF_ENV": "prod"
}
}
}
}
Or for Claude Code:
claude mcp add anaf -- npx -y @florinszilagyi/anaf-mcp
Available tools
| Tool | Auth needed | Description |
|---|
anaf_auth_login | — | Start OAuth flow — returns URL to open in browser |
anaf_auth_complete | — | Finish OAuth — waits for callback, stores token |
anaf_switch_company | — | Switch active company CUI (no re-auth needed) |
anaf_lookup_company | — | Public ANAF company registry lookup by CUI |
anaf_build_ubl | — | Generate CIUS-RO UBL 2.1 invoice XML |
anaf_validate_xml | Yes | Validate UBL XML against ANAF rules |
anaf_upload_invoice | Yes | Upload UBL XML to e-Factura (B2B or B2C) |
anaf_invoice_status | Yes | Poll upload processing status |
anaf_download_invoice | Yes | Download the processed ZIP archive |
anaf_list_messages | Yes | List sent/received/error messages |
Example agentic workflows
First-time authentication:
"Authenticate me for ANAF company CUI 12345678"
The agent calls anaf_auth_login → returns the ANAF OAuth URL → you open it in your browser and sign with your digital certificate → agent calls anaf_auth_complete → done. Tokens are stored at ~/.local/share/anaf-cli/tokens/_default.json.
Create and submit an invoice:
"Create a B2B invoice for client Acme SRL (CUI 87654321) for 5 days of consulting at 800 RON/day, due in 30 days. Validate and upload it."
The agent calls anaf_build_ubl to generate the XML, anaf_validate_xml to check it, then anaf_upload_invoice and returns the upload index.
Check upload status:
"What's the status of upload 5003456789?"
The agent calls anaf_invoice_status and reports back.
See received invoices from suppliers:
"Show me all invoices I received this month"
The agent calls anaf_list_messages with filter: "C" and lists them.
Switch between companies:
"Switch to company CUI 99887766"
The agent calls anaf_switch_company — no re-authentication needed.
CLI quick start
# Install
npm i -g @florinszilagyi/anaf-cli
# Save your ANAF OAuth app credentials
anaf-cli cred add --name my-app \
--client-id $ANAF_CLIENT_ID \
--client-secret $ANAF_CLIENT_SECRET \
--redirect-uri https://localhost:9002/callback
# Add a company
anaf-cli ctx add --name my-company --cui 12345678 --credential my-app
anaf-cli ctx use my-company
# Authenticate (opens browser automatically)
anaf-cli auth login