- AI and MCP
- Issuing NF-e with the agent
AI and MCP
Issuing NF-e with the agent
Recommended flow, NF-e tools, and example requests for the agent.
With the MCP connected, you ask for the invoice in natural language and the agent calls the Treeunfe tools. Underneath, they use the same routes as the NF-e API. The connection operates in production. See Environment.
Recommended flow
Check that the company is ready
get_nfe_checklist checks the certificate, the series and number settings, and the tax rules.
Is my company ready to issue NF-e?
Make sure the NCM has a tax rule
Issuance calculates the taxes from the tax rule that covers the item’s NCM.
Is there a tax rule for NCM 85176241 on a sale to GO?
Ask for the invoice
Give the customer, the items, and the operation. The agent fills the issuer with the company data and lets Treeunfe calculate the taxes (calculateTaxes: true).
Issue a sales NF-e for customer 11222333000181, with 2 units
of product PROD-001 at R$ 500.00 each, with no freight. Before sending,
show me the customer, the items, the CFOP, and the total so I can confirm.
Check the result
After issuing, the agent reads the invoice with get_nfe and, if it was authorized, gets the DANFE with get_nfe_danfe_url.
Was the invoice authorized? Give me the access key and the DANFE link.
Always ask the agent to show the data before issuing. The MCP operates in production: use a series and a number that have not been used yet, so the invoice is not rejected as a duplicate.
NF-e tools
| Tool | What it does | API route |
|---|---|---|
get_nfe_checklist | Checks whether the company is ready to issue. | NF-e checklist |
emit_nfe | Issues a model 55 NF-e. | Issue NF-e |
list_nfe | Lists the company’s NF-e. | List NF-e |
get_nfe | Reads one NF-e and its status. | Get NF-e |
get_nfe_items | Lists the items with the calculated taxes. | NF-e items |
get_nfe_xml | Returns the invoice XML. | NF-e XML |
get_nfe_danfe_url | Returns the DANFE link of an authorized invoice. | DANFE da NF-e |
cancel_nfe | Cancels an authorized NF-e. | Cancel NF-e |
create_nfe_cce | Registers a correction letter. | Issue CC-e |
list_nfe_cce | Lists the invoice’s correction letters. | Get CC-e |
create_nfe_inutilization | Invalidates a number range. | Inutilizar numeração |
list_nfe_inutilizations | Lists number invalidations. | Listar inutilizações |
Supporting tools
The agent also reaches the data issuance uses:
| Group | Tools |
|---|---|
| Company and settings | get_current_organization, get_settings_nfe, update_settings_nfe |
| Tax rules | list_tax_rules, list_default_tax_rules, get_tax_rule, create_tax_rule, update_tax_rule, delete_tax_rule |
| Customers | list_customers, get_customer, create_customer, update_customer, delete_customer |
| Products | list_products, get_product, create_product, update_product, delete_product |
| Carriers | list_carriers, get_carrier, create_carrier, update_carrier, delete_carrier |
| Certificate | get_current_certificate, upload_certificate, delete_certificate |
| CNPJ lookup | lookup_cnpj_rfb |
| Webhooks | list_webhooks, get_webhook, create_webhook, update_webhook, delete_webhook |
Events
Cancel NF-e 006f917a-21a5-491d-90b4-f745d96385e7.
Justification: the amount on the invoice was wrong.
Register a correction letter on the last NF-e issued: the correct
delivery address is Rua das Flores, 100.
Invalidate numbers 15 through 20 of series 1. Justification: a system
failure skipped the numbering.
The rules are the same as the API: a justification of 15 to 255 characters on cancellation and number invalidation, and a correction of 15 to 1000 characters on the CC-e. See NF-e events.
Cancellation, CC-e, and number invalidation are sent to SEFAZ and cannot be undone. Confirm the invoice ID and the text before you authorize the agent.
Useful lookups
List the NF-e issued today, with number, customer, amount, and status.
Why was the last NF-e rejected? Show the reason and what to fix.
Show the taxes calculated on each item of NF-e 006f917a-21a5-491d-90b4-f745d96385e7.