fin-app-mcp 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/docs/guia.md +16 -14
  2. package/index.mjs +51 -16
  3. package/package.json +1 -1
package/docs/guia.md CHANGED
@@ -61,27 +61,29 @@ Cada cartão de crédito tem:
61
61
 
62
62
  O ciclo de uma fatura vai do fechamento anterior até o fechamento atual. Transações dentro desse período pertencem a essa fatura.
63
63
 
64
- ### `reference_month` — ATENÇÃO
64
+ ### `reference_month`
65
65
 
66
- O FIN usa `reference_month` baseado no **mês do vencimento**, NÃO no mês dos gastos.
66
+ O FIN usa `reference_month` baseado no **mês dos gastos / mês de fechamento do ciclo**, NÃO no mês do vencimento. Geralmente coincide com o label que o banco usa para a fatura (quando o banco rotula pelo mês dos gastos).
67
67
 
68
- **Isso é diferente de como os bancos nomeiam faturas.**
69
-
70
- Exemplo concreto — cartão com `closing_day=1` e `due_day=9`:
68
+ **Exemplo concreto cartão com `closing_day=1` e `due_day=9`:**
71
69
  - Ciclo: 1 de março a 1 de abril
72
70
  - Vencimento: 9 de abril
73
- - **Banco chama:** "Fatura de Março" (mês dos gastos)
74
- - **FIN chama:** `reference_month: 2026-04` (mês do vencimento)
71
+ - `reference_month: 2026-04` (o mês onde o ciclo fecha)
72
+
73
+ **Exemplo concreto — cartão com `closing_day=19` e `due_day=26`:**
74
+ - Ciclo: 20 de março a 19 de abril
75
+ - Vencimento: 26 de abril
76
+ - `reference_month: 2026-04` (o mês onde o ciclo fecha — abril)
77
+
78
+ **Regra prática:** o `reference_month` é o mês em que a fatura **fecha** (atinge o `closing_day`). Não é o mês da compra mais antiga da fatura, e não é o mês do vencimento quando o cartão fecha e vence em meses diferentes.
75
79
 
76
- **Regra prática:** quando o banco diz "Fatura de Março", no FIN é `reference_month` do mês seguinte. Ou seja:
77
- - Fatura Março (banco) → `reference_month: 2026-04` (FIN)
78
- - Fatura Abril (banco) → `reference_month: 2026-05` (FIN)
80
+ Se o banco rotula a fatura pelo mês de vencimento (raro), some -1 para chegar ao `reference_month`.
79
81
 
80
82
  ### Em qual fatura cai uma transação?
81
83
 
82
84
  Uma transação cai na fatura cujo ciclo contém a `tx_date`:
83
- - Compra em 15/03 com ciclo 01/03–01/04 → fatura de `reference_month: 2026-04`
84
- - Compra em 31/03 com ciclo 01/03–01/04 → fatura de `reference_month: 2026-04`
85
+ - Cartão fecha dia 1: compra em 15/03 com ciclo 01/03–01/04 → fatura que fecha em abril → `reference_month: 2026-04`
86
+ - Cartão fecha dia 19: compra em 25/03 com ciclo 20/03–19/04 → fatura que fecha em abril → `reference_month: 2026-04`
85
87
 
86
88
  **Detalhe:** transação feita exatamente no dia do fechamento (`closing_day`) é empurrada para o **próximo** ciclo.
87
89
 
@@ -221,8 +223,8 @@ Resultado: refund + ajuste se anulam → líquido bate com o banco.
221
223
 
222
224
  ### `cycle_end` vs `reference_month`
223
225
 
224
- - **`cycle_end`** é a data de fechamento do ciclo (ex: `2026-04-01` para um cartão que fecha dia 1). É o identificador usado internamente pelo FIN e na tool `fin_ajuste_fatura`.
225
- - **`reference_month`** é o mês do vencimento (ex: `2026-04` para uma fatura que vence em abril). É usado nas tools `fin_fatura_cartao` e `fin_fatura_transacoes`.
226
+ - **`cycle_end`** é a data exata de fechamento do ciclo (ex: `2026-04-01` para um cartão que fecha dia 1). É o identificador usado internamente pelo FIN e na tool `fin_ajuste_fatura`.
227
+ - **`reference_month`** é o mês em que o ciclo fecha (ex: `2026-04` para uma fatura com `cycle_end: 2026-04-01`). É usado nas tools `fin_fatura_cartao` e `fin_fatura_transacoes`. Ver seção 4 para a regra completa.
226
228
 
227
229
  Para descobrir o `cycle_end` de uma fatura, use `fin_fatura_transacoes` — a resposta inclui o `cycle_end`.
228
230
 
package/index.mjs CHANGED
@@ -182,17 +182,16 @@ CAMPOS:
182
182
  - reference_month: string YYYY-MM — mês de referência da fatura.
183
183
 
184
184
  REGRAS DE NEGÓCIO:
185
- - ATENÇÃO: reference_month = mês do VENCIMENTO da fatura, NÃO o mês dos gastos.
186
- - Bancos nomeiam faturas pelo mês dos gastos. O FIN nomeia pelo mês do vencimento. ~1 mês de diferença.
187
- - Exemplo: "Fatura de Março" do banco = reference_month 2026-04 no FIN (se vence em abril).
188
- - Regra prática: some +1 ao mês que o banco informa.
185
+ - reference_month = mês dos GASTOS / mês de fechamento do ciclo da fatura (NÃO é o mês do vencimento).
186
+ - Exemplo: uma fatura com ciclo 20/03–19/04 e vencimento 26/04 está em reference_month "2026-04". Normalmente coincide com o label que o banco usa (ex: "Fatura de Abril" quando o banco rotula pelo mês dos gastos).
187
+ - Se o banco rotula pelo mês de vencimento, some -1 mês para chegar ao reference_month.
189
188
  - net_total já desconta estornos.
190
189
  - Valores em centavos.`,
191
190
  inputSchema: {
192
191
  type: "object",
193
192
  properties: {
194
193
  card_name: { type: "string", description: "Nome do cartão" },
195
- reference_month: { type: "string", description: "YYYY-MM" },
194
+ reference_month: { type: "string", description: "YYYY-MM (mês dos gastos / fechamento)" },
196
195
  },
197
196
  },
198
197
  },
@@ -303,14 +302,14 @@ CAMPOS:
303
302
  - reference_month: string YYYY-MM — mês de referência (default: mês atual).
304
303
 
305
304
  REGRAS DE NEGÓCIO:
306
- - ATENÇÃO: reference_month segue a mesma regra de fin_fatura_cartao é o mês do VENCIMENTO, não dos gastos. Some +1 ao mês que o banco informa.
305
+ - reference_month = mês dos GASTOS / mês de fechamento do ciclo (NÃO é o mês do vencimento). Ver fin_fatura_cartao para exemplos.
307
306
  - Estornos aparecem com kind: 'refund' e signedAmount negativo.
308
307
  - Valores em centavos.`,
309
308
  inputSchema: {
310
309
  type: "object",
311
310
  properties: {
312
311
  card_name: { type: "string", description: "Nome do cartão (obrigatório)" },
313
- reference_month: { type: "string", description: "YYYY-MM (default: mês atual)" },
312
+ reference_month: { type: "string", description: "YYYY-MM (mês dos gastos / fechamento; default: mês atual)" },
314
313
  },
315
314
  required: ["card_name"],
316
315
  },
@@ -365,7 +364,7 @@ CAMPOS:
365
364
  - tx_date: string YYYY-MM-DD — data (default: hoje, timezone America/Sao_Paulo).
366
365
  - essential: boolean — se é despesa essencial.
367
366
  - installments: number — número de parcelas (2-48). Gera N transações separadas automaticamente.
368
- - current_installment: number — parcela inicial (default: 1). Útil para entrar no meio de um parcelamento.
367
+ - current_installment: number — parcela inicial (default: 1). Passar 1 é equivalente ao default o sistema cria todas as N parcelas começando da primeira. Use valores > 1 APENAS quando registrando uma compra parcelada que já está em andamento e você quer criar apenas as parcelas futuras (ex: installments=10, current_installment=3 cria 8 transações, da parcela 3 à 10).
369
368
  - reversal_of_id: string UUID — ID da transação original para estorno.
370
369
  - reversal_kind: string — 'full' ou 'partial' (obrigatório quando reversal_of_id é informado).
371
370
 
@@ -872,7 +871,9 @@ CAMPOS:
872
871
  - name: string — nome da conta (obrigatório, ex: "Nubank", "Inter", "Carteira").
873
872
  - institution: string — nome da instituição financeira.
874
873
  - type: string — 'cash' (corrente/carteira/poupança) ou 'credit' (cartão de crédito) (obrigatório).
875
- - initial_balance_cents: number — saldo inicial em centavos (default: 0).
874
+ - initial_balance_cents: number — saldo inicial em centavos (default: 0). Para cartão credit, é o valor de uma fatura preexistente (use com initial_invoice_date).
875
+ - initial_invoice_date: string YYYY-MM-DD — data da fatura inicial (cutoff histórico). OMITIR é o comportamento recomendado para cartões novos — significa "sem cutoff", ou seja, transações com qualquer tx_date (inclusive anteriores à criação) contam no total da fatura.
876
+ - initial_invoice_amount_cents: number — alias de initial_balance_cents quando se refere a fatura inicial de cartão. Use junto com initial_invoice_date.
876
877
  - closing_day: number — dia de fechamento da fatura, 1-28 (obrigatório para type 'credit').
877
878
  - due_day: number — dia de vencimento da fatura, 1-28 (obrigatório para type 'credit').
878
879
  - credit_limit_cents: number — limite de crédito em centavos (para type 'credit').
@@ -880,7 +881,14 @@ CAMPOS:
880
881
  REGRAS DE NEGÓCIO:
881
882
  - Cartão de crédito (type 'credit') EXIGE closing_day e due_day.
882
883
  - closing_day e due_day devem estar entre 1 e 28.
883
- - Valores em centavos.`,
884
+ - Valores em centavos.
885
+ - **Para cartão de crédito**: por padrão (quando initial_invoice_date é omitido), o cartão é criado SEM cutoff histórico. Transações com qualquer tx_date contam no total da fatura. Use initial_invoice_date + initial_invoice_amount_cents apenas se o usuário tem um saldo de fatura preexistente vindo de outro sistema.
886
+
887
+ EXEMPLO — cartão novo (sem fatura preexistente):
888
+ { "name": "Nubank", "type": "credit", "closing_day": 19, "due_day": 26, "credit_limit_cents": 500000 }
889
+
890
+ EXEMPLO — cartão migrado com fatura já aberta:
891
+ { "name": "Itaú", "type": "credit", "closing_day": 1, "due_day": 9, "initial_invoice_date": "2026-03-15", "initial_invoice_amount_cents": 350000 }`,
884
892
  inputSchema: {
885
893
  type: "object",
886
894
  properties: {
@@ -888,6 +896,8 @@ REGRAS DE NEGÓCIO:
888
896
  institution: { type: "string", description: "Nome da instituição financeira" },
889
897
  type: { type: "string", description: "'cash' ou 'credit'" },
890
898
  initial_balance_cents: { type: "number", description: "Saldo inicial em centavos (default: 0)" },
899
+ initial_invoice_date: { type: ["string", "null"], description: "YYYY-MM-DD — data da fatura inicial. Omitir ou passar null para cartão sem cutoff histórico (recomendado)." },
900
+ initial_invoice_amount_cents: { type: "number", description: "Valor da fatura inicial em centavos. Use com initial_invoice_date." },
891
901
  closing_day: { type: "number", description: "Dia de fechamento da fatura (1-28, obrigatório para credit)" },
892
902
  due_day: { type: "number", description: "Dia de vencimento da fatura (1-28, obrigatório para credit)" },
893
903
  credit_limit_cents: { type: "number", description: "Limite de crédito em centavos (para credit)" },
@@ -899,21 +909,27 @@ REGRAS DE NEGÓCIO:
899
909
  name: "fin_editar_conta",
900
910
  description: `Edita uma conta bancária existente. Campos omitidos permanecem inalterados.
901
911
 
902
- QUANDO USAR: corrigir nome, instituição, limites ou dias de fechamento/vencimento.
912
+ QUANDO USAR: corrigir nome, instituição, limites, dias de fechamento/vencimento, OU corrigir a data/valor da fatura inicial em cartões criados com cutoff errado.
903
913
 
904
914
  CAMPOS:
905
915
  - account_id: string UUID — ID da conta (obrigatório).
906
916
  - name: string — novo nome.
907
917
  - institution: string — nova instituição.
908
918
  - type: string — 'cash' ou 'credit'.
909
- - initial_balance_cents: number — novo saldo inicial em centavos.
919
+ - initial_balance_cents: number — novo saldo inicial / fatura inicial em centavos.
920
+ - initial_invoice_date: string YYYY-MM-DD ou null — data da fatura inicial (cutoff histórico). Passe null para remover o cutoff (transações antigas voltam a contar no total).
921
+ - initial_invoice_amount_cents: number — alias de initial_balance_cents quando se refere a fatura inicial de cartão.
910
922
  - closing_day: number — novo dia de fechamento (1-28).
911
923
  - due_day: number — novo dia de vencimento (1-28).
912
924
  - credit_limit_cents: number — novo limite de crédito em centavos.
913
925
 
914
926
  REGRAS DE NEGÓCIO:
915
927
  - Valores em centavos.
916
- - Campos omitidos não são alterados.`,
928
+ - Campos omitidos não são alterados.
929
+ - Use initial_invoice_date: null para remover o cutoff histórico de um cartão (caso transações antigas estejam aparecendo fora da fatura no app).
930
+
931
+ EXEMPLO — remover cutoff de um cartão criado errado:
932
+ { "account_id": "uuid-do-cartao", "initial_invoice_date": null, "initial_invoice_amount_cents": 0 }`,
917
933
  inputSchema: {
918
934
  type: "object",
919
935
  properties: {
@@ -922,6 +938,8 @@ REGRAS DE NEGÓCIO:
922
938
  institution: { type: "string", description: "Nova instituição" },
923
939
  type: { type: "string", description: "'cash' ou 'credit'" },
924
940
  initial_balance_cents: { type: "number", description: "Novo saldo inicial em centavos" },
941
+ initial_invoice_date: { type: ["string", "null"], description: "YYYY-MM-DD ou null — data da fatura inicial (cutoff histórico). Passe null para remover o cutoff." },
942
+ initial_invoice_amount_cents: { type: "number", description: "Valor da fatura inicial em centavos" },
925
943
  closing_day: { type: "number", description: "Novo dia de fechamento (1-28)" },
926
944
  due_day: { type: "number", description: "Novo dia de vencimento (1-28)" },
927
945
  credit_limit_cents: { type: "number", description: "Novo limite de crédito em centavos" },
@@ -1158,10 +1176,27 @@ async function handleTool(name, args) {
1158
1176
  return ok(await api("GET", `/api/genius/accounts`));
1159
1177
  }
1160
1178
  case "fin_criar_conta": {
1161
- return ok(await api("POST", `/api/genius/accounts`, args));
1179
+ // Map user-friendly names to Genius API field names.
1180
+ // initial_invoice_date / initial_invoice_amount_cents → initial_balance_date / initial_balance_cents
1181
+ const { initial_invoice_date, initial_invoice_amount_cents, ...rest } = args;
1182
+ const mapped = { ...rest };
1183
+ if (initial_invoice_date !== undefined) {
1184
+ mapped.initial_balance_date = initial_invoice_date;
1185
+ }
1186
+ if (initial_invoice_amount_cents !== undefined) {
1187
+ mapped.initial_balance_cents = initial_invoice_amount_cents;
1188
+ }
1189
+ return ok(await api("POST", `/api/genius/accounts`, mapped));
1162
1190
  }
1163
1191
  case "fin_editar_conta": {
1164
- const { account_id, ...body } = args;
1192
+ const { account_id, initial_invoice_date, initial_invoice_amount_cents, ...rest } = args;
1193
+ const body = { ...rest };
1194
+ if (initial_invoice_date !== undefined) {
1195
+ body.initial_balance_date = initial_invoice_date;
1196
+ }
1197
+ if (initial_invoice_amount_cents !== undefined) {
1198
+ body.initial_balance_cents = initial_invoice_amount_cents;
1199
+ }
1165
1200
  return ok(await api("PATCH", `/api/genius/accounts/${account_id}`, body));
1166
1201
  }
1167
1202
  case "fin_listar_categorias": {
@@ -1189,7 +1224,7 @@ async function handleTool(name, args) {
1189
1224
  // ── Server ──────────────────────────────────────────────────────────
1190
1225
 
1191
1226
  const server = new Server(
1192
- { name: "fin-app", version: "2.2.0" },
1227
+ { name: "fin-app", version: "2.3.1" },
1193
1228
  { capabilities: { tools: {}, resources: {} } }
1194
1229
  );
1195
1230
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fin-app-mcp",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "MCP server para o FIN App — finanças pessoais. Expõe tools para agents LLM operarem contas, despesas, faturas de cartão, bills recorrentes e mais.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",