Sign inGet started
Back to blog
Integration

MCP for invoices: issue Brazilian NF-e and NFS-e from Claude and ChatGPT

How to connect the Stackin MCP server to Claude, ChatGPT, Codex and Cursor, which tools an assistant uses to issue NF-e and NFS-e, and the safeguards that stop an invoice issued by accident.

An MCP server for Brazilian invoices exposes fiscal document issuance as tools an AI assistant can call. Stackin runs one at https://mcp.stackin.io/mcp: once it is connected to Claude, ChatGPT, Codex or Cursor, you ask "issue an NFS-e for R$ 450 of consulting for this client" and the assistant builds the request, validates the data and issues the NF-e (goods) or NFS-e (services) through the same API the SDKs use.

It is not a shortcut around fiscal rules. The assistant calls the same API operations, with the company, environment and permissions you authorized on the connection, and the document goes to the SEFAZ or the national NFS-e system like any other. This post covers how to connect, which tools exist and, above all, which safeguards separate a homologation test from a real invoice issued by mistake.

How to connect Stackin to Claude, ChatGPT and Cursor

There is one address, https://mcp.stackin.io/mcp, over streamable HTTP. The default path is OAuth: you sign in to Stackin in the browser, choose the company, the environment and the permissions on a consent screen, and the client stores the token. Where there is no browser (APIs, automations), the alternative is an API key in the Authorization: Bearer header.

  • Claude (claude.ai and Desktop): under Customize → Connectors → Add custom connector, enter the URL and sign in with Stackin. On Team and Enterprise plans an Owner adds the connector first, in the organization settings.
  • Claude Code: install the Stackin plugin, which already points at the server and brings skills with the order of operations (issue, consult, cancel, diagnose a rejection). Then run /mcp in the session and authorize in the browser.
  • ChatGPT: turn on developer mode, register the URL as a custom MCP server with OAuth authentication and authorize on the Stackin screen. ChatGPT does not take an API key header, so OAuth is the only way in.
  • Codex and Cursor: codex mcp add detects OAuth and opens the sign-in by itself; in Cursor the URL in mcp.json is enough.
Claude Code (plugin or claude mcp add) and Codex
Copy
claude plugin marketplace add stackin-io/stackin-mcp-plugin
claude plugin install stackin@stackin

claude mcp add --transport http stackin https://mcp.stackin.io/mcp

codex mcp add stackin --url https://mcp.stackin.io/mcp
~/.cursor/mcp.json
Copy
{
  "mcpServers": {
    "stackin": {
      "url": "https://mcp.stackin.io/mcp"
    }
  }
}

ChatGPT only takes custom connectors with developer mode on, and on Business, Enterprise and Edu workspaces an admin allows creating them first. The step-by-step, with video, is at docs.stackin.io/mcp.

Which tools the assistant sees

The server publishes more than 40 tools, and any MCP client lists them all with tools/list. That particular call needs no credential, so you can inspect the catalog before connecting anything:

List the server's tools
Copy
curl -s -X POST https://mcp.stackin.io/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

The ones that matter for issuing fall into groups. Issuance and lifecycle: issue_invoice (NF-e or NFS-e), reissue_invoice (a new attempt at a rejected document), consult_invoice, list_invoices, get_invoice_pdf (DANFE or DANFSe), get_invoice_submissions and explain_rejection, which translates the authority's refusal and says what to change. Events: cancel_invoice, and for NF-e only correct_invoice (correction letter) and invalidate_numbering. Received invoices (NF-e): list_received_invoices, sync_received_invoices and manifest_received_invoice.

Lookups before issuing: list_clients and list_items find the recipient and the product already on file, search_fiscal_codes and lookup_fiscal_code resolve NCM and CFOP, lookup_taxpayer confirms who a CNPJ belongs to, search_cities finds a municipality's IBGE code, validate_invoice_payload checks the data without issuing anything and calculate_ibs_cbs simulates IBS/CBS per item without creating a document. get_company_readiness says whether the company can issue yet and, if not, what is missing. There are also tools to manage clients, items and webhooks.

How to issue an NF-e or NFS-e from the conversation

The flow the assistant follows is that of a careful issuer. It asks get_company_readiness once, finds the recipient with list_clients, runs validate_invoice_payload and only then calls issue_invoice, returning the status and the access key. The same validation can be called with cURL and an API key, and the result is what the assistant would see:

validate_invoice_payload over JSON-RPC
Copy
curl -s -X POST https://mcp.stackin.io/mcp \
  -H "Authorization: Bearer $STACKIN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "validate_invoice_payload",
      "arguments": {
        "document_type": "nfse",
        "items": [{"description": "Consultoria em tecnologia", "amount": 450}]
      }
    }
  }'

The difference between the two documents shows up here. An NFS-e needs a description, an amount, and the client's name and CPF/CNPJ; the address is optional and the service code falls back to the company's fiscal profile. An NF-e requires NCM and CFOP on every item and the recipient's full address, with street, number, neighborhood, city, state, zip code and IBGE city code, because the SEFAZ refuses a partial document. The server's instructions tell the assistant never to infer those codes: NCM and CFOP decide the tax owed, and a plausible but wrong classification is authorized today and only surfaces later, as a cancellation.

issue_invoice arguments for an NFS-e
Copy
{
  "document_type": "nfse",
  "client_name": "Cliente Exemplo Ltda",
  "tax_id": "11222333000181",
  "items": [
    {"description": "Consultoria em tecnologia", "amount": 450}
  ],
  "idempotency_key": "nfse-cliente-exemplo-2026-11"
}

classify_item suggests an NCM, CFOP, CST/CSOSN, CEST or service code from a description, but only as a suggestion: the assistant shows what it found and puts the code on the item after you confirm it. If an item was saved earlier, item_id fills in the description, price and fiscal codes from the company's catalog.

Which safeguards stop an invoice issued by accident

An authorized invoice is a legally binding document, so the conversation needs brakes that do not depend on the model's judgment. These are the ones that exist today:

  • Homologation or production belongs to the connection, not to the conversation. The environment is chosen on the consent screen, where the default is homologation, and with an API key it is fixed when the key is created. No tool switches environment: to go to production you reconnect and choose Production. A guest limited to homologation cannot authorize production.
  • Homologation is a test with no fiscal value and costs no credit. Production consumes a credit per authorized document, and get_usage shows the allowance and the balance before you issue.
  • The tools that change a document declare themselves destructive. issue_invoice, reissue_invoice, cancel_invoice, correct_invoice, invalidate_numbering and manifest_received_invoice carry destructiveHint, and issue_invoice and cancel_invoice also carry openWorldHint, because they transmit to the authority. MCP clients use these annotations to ask a human to confirm.
  • Confirming the data. The server's instructions and the skills tell the assistant to read the data back before issuing, cancelling, invalidating numbering or manifesting, and never to infer an NCM, a CFOP or an address. A cancellation requires a reason of at least 15 characters, which reaches the authority as written.
  • Idempotency key. Issuing and cancelling accept idempotency_key: repeating the call with the same key and the same data returns the first answer instead of issuing or cancelling a second time. Without it, a lost response followed by a retry issues another invoice.
  • Permissions by scope. The token carries only what you approved among read, issue, cancel and event-writing, and the API checks the scope against the operation on every call. The webhook tools ask for a separate authorization on first use.

ChatGPT's connector permission

ChatGPT has one more safeguard, and it catches many people. Each connector has a Permissions setting. On the default, low-risk actions go through, and a tool that writes and transmits to an external system, such as issue_invoice, can be refused by the platform before it reaches Stackin: the conversation shows a block, and nothing appears in our logs, because the request never left ChatGPT. OpenAI describes that confirmation of write actions depends on the app's permissions and the action's context, and that some risky actions are blocked rather than presented for approval.

Before issuing from ChatGPT, open the connector's Permissions and choose the ask-on-every-use option ("Ask every time" in English, "Perguntar sempre" in Portuguese). With it, every write call stops until you approve, and the invoice is only issued after your click.

Through the model APIs that call remote MCP servers, such as OpenAI's Responses API, the equivalent is requiring approval on every tool call (require_approval: always) and keeping a human in front of issue_invoice and cancel_invoice.

What if the connection covers more than one company

An OAuth connection may cover several companies, each with its own permissions: read-only on one, issuing on another. With a single company nothing changes. With several, every tool that touches documents takes company_id or company_tax_id (one or the other, never both), and list_authorized_companies shows what the connection covers and what each company allows. Without the company the call is refused with the list to choose from; a company outside the connection or a missing permission is refused too, and retrying does not change the result.

A call with the company chosen
Copy
list_invoices({
  "document_type": "nfe",
  "company_tax_id": "11222333000181"
})

The name is company_tax_id, not tax_id, on purpose: issue_invoice already uses tax_id for the recipient's CPF or CNPJ, and two fields with the same name would have the model fill in the wrong one.

When to use MCP and when to use the API or an SDK

MCP fits on-demand issuing, where a person describes the invoice and checks the result: a professional who issues a few invoices a week, a finance team that looks up documents and diagnoses rejections, or a developer testing the flow in homologation without writing code. For volume issuing triggered by a system, the REST API and the SDKs are the right path, with a fixed contract and no model in the middle. The contract is the same in both: MCP calls the official SDK underneath.

For a first test, connect in homologation, ask for a test NFS-e and read the result with consult_invoice; see also how environments work and the NF-e issuance guide. The full reference for scopes, tools and prompts is at /mcp.