nfse-sdk
AGENTS.md4 starsChanged 20 days agoMITView on GitHub
Guidance for AI coding agents working on this repository. To use the SDK from another project, read llms.txt instead. @useinvio/nfse-sdk is the protocol layer for Brazil's NFS-e Nacional: DPS and event XML, official XSD validation (libxml2 in WebAssembly), XMLDSIG, GZip/Base64, mTLS to SEFIN and ADN, typed results and errors. It must not become a tax engine: never add fiscal defaults or choose codes for the user. All tests run offline: the SEFIN transport is mocked (testing.ts and test/httpsMock.ts). - Fiscal…
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,196 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- llms.txtllms.txt
The file
We split this AGENTS.md into the rules it gives an agent
7 rules. About 1 is common, 0 are distinctive, and 6 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 23
All tests run offline: the SEFIN transport is mocked (testing.ts and test/httpsMock.ts).
- Very specific: line 52
Fiscal neutrality: No silent defaults for tributacaoMunicipal, totTrib, cTribNac or regime.
- Common: line 55
Never log, serialize or return key material, PFX bytes or passwords.
- Very specific: line 56
Network: Only sefinClient.ts talks to the network.
- Very specific: line 63
Public API: Keep names exported by index.ts stable.
- Very specific: line 79
Never edit the generated file by hand, and keep the official text verbatim.
- Very specific: line 80
After regenerating, run npm run build:rejection-pages to refresh docs/rejeicoes/.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Guidance for AI coding agents working on this repository. To use the SDK
from another project, read llms.txt instead.
What this is
@useinvio/nfse-sdk is the protocol layer for Brazil's NFS-e Nacional: DPS and
event XML, official XSD validation (libxml2 in WebAssembly), XMLDSIG, GZip/Base64,
mTLS to SEFIN and ADN, typed results and errors. It must not become a tax
engine: never add fiscal defaults or choose codes for the user.
Commands
npm install
npm run typecheck # library
npm run typecheck:examples # examples/*.ts against the source
npm test # build + all tests (node:test), including the MCP stdio interop test
npm pack --dry-run # what gets publishedAll tests run offline: the SEFIN transport is mocked (testing.ts and test/httpsMock.ts).
Layout
| Path | Role |
index.ts | Public API. Everything exported here is supported. |
client.ts | NfseClient facade over the functions below. |
dpsJson.ts, fiscalValidation.ts, dpsJsonSchema.ts, fiscalDomains.ts | JSON input, validation, JSON Schema, DPS XML builder. |
emissaoNota.ts | Emission flow: prepare (XSD, validity, sign, verify) and transmit. |
eventoJson.ts, eventosNfse.ts | Cancellation events: builders and send flow. |
consultas.ts, nfseXml.ts | Typed query, recovery by DPS id, NFS-e XML reader. |
sefinClient.ts | The only module that does network I/O: endpoints, timeouts, GET retries, path validation, metrics, test transport seam. |
certificate.ts, certificateValidation.ts, loadPfx.ts | NfseCertificate and certificate checks. |
xsdValidation.ts, xmlInspection.ts, signXml.ts, xmlBuild.ts, gzipB64.ts | XML, XSD and crypto helpers. |
rejeicoes.ts, rejeicoesCatalog.ts | Official rejection catalog. The catalog is generated; see below. |
agent.ts | Framework-neutral agent tools and the prepare/confirm toolkit. |
mcpServer.ts, mcpCli.ts | Dependency-free MCP stdio server and its CLI. |
testing.ts | Public test helpers: createTestCertificate, installMockSefin. |
cli.ts, cliBin.ts, cliExample.ts | The nfse command line and its sample payload. |
playground/ | Browser playground. Edit playground/src/; npm run build:playground writes playground/index.html; pages.yml deploys it to GitHub Pages on push to main. |
docs/rejeicoes/ | One page per rejection code, generated by npm run build:rejection-pages. Never edit by hand. |
mcp/ | The @useinvio/nfse-mcp wrapper package (a bin that calls mcpServer.ts). |
plugin/, .claude-plugin/marketplace.json | Claude Code plugin (skill + MCP server) and its marketplace. |
docs/ | pt-BR docs: tutoriais/, guias/, referencia/, conceitos/. |
schemas/ | Official XSD v1.01. Never edit these files. |
Rules
- Fiscal neutrality. No silent defaults for
tributacaoMunicipal,totTrib,cTribNacor regime. Reject unsupported shapes instead of guessing. - Certificates. Accept
CertificateInputand go throughresolveCredentials. Never log, serialize or return key material, PFX bytes or passwords. - Network. Only
sefinClient.tstalks to the network. POSTs are never retried. Validate every URL path parameter before the request. - XML order follows the XSD; tests compare snippets. Every generated XML must
pass
validateDpsXmlAgainstXsdorvalidatePedRegEventoXmlAgainstXsd. - Agent tools. Certificate and environment come from
NfseAgentContext, never from tool input. Anything that sends to SEFIN must be aconfirm_*tool behind aprepare_*step andallowWrite. - Public API. Keep names exported by
index.tsstable. A new export needs a test, an entry indocs/referencia/api.mdand, when relevant,llms.txt. - Docs. README stays short; details go to
docs/.test/documentation.test.tschecks snippet payloads against the XSD, imported names and every relative link.
Rejection catalog
rejeicoesCatalog.ts is generated from the official gov.br annexes. To update it,
download the current anexo_i-...xlsx and anexo_ii-...xlsx from
https://www.gov.br/nfse/pt-br/biblioteca/documentacao-tecnica/documentacao-atual
and run:
node scripts/build-rejection-catalog.mjs "anexo_i.xlsx|Anexo I ... v1.01 (09/02/2026)|<url>" "anexo_ii.xlsx|Anexo II ... v1.01 (22/01/2026)|<url>"Never edit the generated file by hand, and keep the official text verbatim.
After regenerating, run npm run build:rejection-pages to refresh docs/rejeicoes/.
Releases
The SDK publishes from publish.yml on a tag matching package.json. The MCP
wrapper in mcp/ depends on the SDK version that contains mcpServer.ts, so
publish the SDK first, then mcp/ (npm publish from that folder), then update
mcp/server.json in the MCP Registry.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

