ibge-br-mcp 5.2.0 → 5.4.0
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.
- package/README.md +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +5 -9
- package/dist/cache.js.map +1 -1
- package/dist/call-shape.d.ts +34 -0
- package/dist/call-shape.d.ts.map +1 -1
- package/dist/call-shape.js +40 -0
- package/dist/call-shape.js.map +1 -1
- package/dist/metrics.d.ts +4 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +6 -2
- package/dist/metrics.js.map +1 -1
- package/dist/provenance.d.ts +41 -14
- package/dist/provenance.d.ts.map +1 -1
- package/dist/provenance.js +72 -19
- package/dist/provenance.js.map +1 -1
- package/dist/retry.d.ts +81 -25
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +218 -123
- package/dist/retry.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -587,7 +587,7 @@ ibge-br-mcp/
|
|
|
587
587
|
│ ├── types.ts # TypeScript types
|
|
588
588
|
│ ├── config.ts # Configuration and constants
|
|
589
589
|
│ ├── cache.ts # Request caching system
|
|
590
|
-
│ ├── retry.ts #
|
|
590
|
+
│ ├── retry.ts # Trip to the source over @sbissoli/mcp-upstream (retry, timeout, budget, retrieval count)
|
|
591
591
|
│ ├── errors.ts # Standardized error handling
|
|
592
592
|
│ ├── validation.ts # Input validation helpers
|
|
593
593
|
│ ├── metrics.ts # Metrics and logging
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAkC,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAO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AAQ,CACtB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAC7D,MAAM,CAUR;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,CAAC,CAAC,CAkBZ;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM,EACV,UAAU,CAAC,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,CAAC,CAAC,CAMZ;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAEnE"}
|
package/dist/cache.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Simple in-memory cache with TTL support for IBGE API requests
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { fetchJson, RecursoAusenteError } from "./retry.js";
|
|
5
5
|
class RequestCache {
|
|
6
6
|
cache = new Map();
|
|
7
7
|
fetchMeta = new Map();
|
|
@@ -129,14 +129,10 @@ export async function cachedFetch(url, cacheKeyStr, ttlMinutes, retryOptions) {
|
|
|
129
129
|
cache.recordHit(cacheKeyStr);
|
|
130
130
|
return cached;
|
|
131
131
|
}
|
|
132
|
-
// Fetch from API
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// quê, e sem ele o chamador só pode tentar outra combinação às cegas.
|
|
137
|
-
throw new UpstreamError(response.status, response.statusText, await motivoUpstream(response));
|
|
138
|
-
}
|
|
139
|
-
const data = (await response.json());
|
|
132
|
+
// Fetch from API: retry, timeout and the `retrieval` count live in retry.ts.
|
|
133
|
+
// A status error arrives as `UpstreamError` WITH what the source said — it is
|
|
134
|
+
// there that the source names WHICH parameter it refused and why.
|
|
135
|
+
const data = await fetchJson(url, retryOptions);
|
|
140
136
|
// Store in cache
|
|
141
137
|
cache.set(cacheKeyStr, data, ttlMinutes);
|
|
142
138
|
cache.recordFetch(cacheKeyStr, Date.now());
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAqB,MAAM,YAAY,CAAC;AAkB/E,MAAM,YAAY;IACR,KAAK,GAAqC,IAAI,GAAG,EAAE,CAAC;IACpD,SAAS,GAAmE,IAAI,GAAG,EAAE,CAAC;IACtF,UAAU,CAAS;IAE3B,YAAY,iBAAiB,GAAW,EAAE;QACxC,IAAI,CAAC,UAAU,GAAG,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,GAAW;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,IAAS,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,GAAW,E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ACnB,OAAe,EACf,EAAU,EACV,UAAmB,EACnB,YAA2B;IAE3B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAgB,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IAC1F,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,IAAS,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,WAAmB;IAC/C,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/call-shape.d.ts
CHANGED
|
@@ -89,4 +89,38 @@ export declare function errorText(result: unknown): string;
|
|
|
89
89
|
* do erro que NÓS escrevemos.
|
|
90
90
|
*/
|
|
91
91
|
export declare function classifyThrown(error: unknown): ErrorClass;
|
|
92
|
+
/**
|
|
93
|
+
* Classe de um erro JSON-RPC do PROTOCOLO, pelo código antes da mensagem.
|
|
94
|
+
*
|
|
95
|
+
* POR QUE ELE CHEGA AQUI AGORA. Até 24/09/2026 este arquivo só era chamado de
|
|
96
|
+
* dentro do handler, com a exceção da tool na mão — e o cabeçalho acima ainda
|
|
97
|
+
* registra o limite daquele desenho: *erro de validação de esquema NÃO chega a
|
|
98
|
+
* esta camada; o SDK o responde antes do handler, e a chamada não é contada nem
|
|
99
|
+
* como chamada nem como erro*. Era verdade, e era o defeito: a recusa de esquema
|
|
100
|
+
* não gerava linha NENHUMA de telemetria. Medido na produção em 24/09/2026 pela
|
|
101
|
+
* rota do dono, ela sai como HTTP **200** com `result.isError: true` e sem
|
|
102
|
+
* código JSON-RPC; e ferramenta inexistente sai como **200** com o código
|
|
103
|
+
* **−32602** (não −32601, como se supunha). Desde então a telemetria lê o
|
|
104
|
+
* ENVELOPE da resposta (src/envelope.ts) e estes casos passam a existir.
|
|
105
|
+
*
|
|
106
|
+
* Os códigos reservados pela especificação JSON-RPC 2.0 dizem, sem ambiguidade
|
|
107
|
+
* de idioma, de quem é o conserto:
|
|
108
|
+
*
|
|
109
|
+
* - −32700 parse error, −32600 invalid request, −32601 method not found e
|
|
110
|
+
* −32602 invalid params são o CHAMADOR mandando algo que o protocolo
|
|
111
|
+
* recusa. É `contrato` — e o painel exclui `contrato` da taxa de erro
|
|
112
|
+
* (`eh_recusa_de_contrato()`), porque ferramenta que recusa chamada
|
|
113
|
+
* malformada está funcionando;
|
|
114
|
+
* - −32603 internal error é erro NOSSO, que escapou. É `defeito`, e por
|
|
115
|
+
* decisão do dono em 24/09/2026 ele entra na fila de saúde do painel: sem
|
|
116
|
+
* isso passaríamos a medir e continuaríamos a não agir.
|
|
117
|
+
*
|
|
118
|
+
* Código fora dessa faixa (erro definido pelo servidor, −32000 e abaixo) cai
|
|
119
|
+
* na mensagem, que é o caminho de `classifyError`.
|
|
120
|
+
*
|
|
121
|
+
* Cópia FIEL de sih-br-mcp/worker/src/call-shape.ts, onde a função estreou:
|
|
122
|
+
* classe medida por servidor com classificador diferente não é comparável, e
|
|
123
|
+
* comparar os sete é a razão de existir da seção de saúde do painel.
|
|
124
|
+
*/
|
|
125
|
+
export declare function classeDoErroRpc(code: number | undefined, message: string): ErrorClass;
|
|
92
126
|
//# sourceMappingURL=call-shape.d.ts.map
|
package/dist/call-shape.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-shape.d.ts","sourceRoot":"","sources":["../src/call-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,qEAAqE;AACrE,MAAM,MAAM,UAAU;AACpB,gHAAgH;AAC9G,UAAU;AACZ,gFAAgF;GAC9E,gBAAgB;AAClB,sEAAsE;GACpE,OAAO;AACT,mFAAmF;GACjF,SAAS;AACX,yFAAyF;GACvF,OAAO,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAmEzD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAiBjD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAUzD"}
|
|
1
|
+
{"version":3,"file":"call-shape.d.ts","sourceRoot":"","sources":["../src/call-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,qEAAqE;AACrE,MAAM,MAAM,UAAU;AACpB,gHAAgH;AAC9G,UAAU;AACZ,gFAAgF;GAC9E,gBAAgB;AAClB,sEAAsE;GACpE,OAAO;AACT,mFAAmF;GACjF,SAAS;AACX,yFAAyF;GACvF,OAAO,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAmEzD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAiBjD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAUzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAIrF"}
|
package/dist/call-shape.js
CHANGED
|
@@ -165,4 +165,44 @@ export function classifyThrown(error) {
|
|
|
165
165
|
}
|
|
166
166
|
return classifyError(error instanceof Error ? error.message : String(error));
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Classe de um erro JSON-RPC do PROTOCOLO, pelo código antes da mensagem.
|
|
170
|
+
*
|
|
171
|
+
* POR QUE ELE CHEGA AQUI AGORA. Até 24/09/2026 este arquivo só era chamado de
|
|
172
|
+
* dentro do handler, com a exceção da tool na mão — e o cabeçalho acima ainda
|
|
173
|
+
* registra o limite daquele desenho: *erro de validação de esquema NÃO chega a
|
|
174
|
+
* esta camada; o SDK o responde antes do handler, e a chamada não é contada nem
|
|
175
|
+
* como chamada nem como erro*. Era verdade, e era o defeito: a recusa de esquema
|
|
176
|
+
* não gerava linha NENHUMA de telemetria. Medido na produção em 24/09/2026 pela
|
|
177
|
+
* rota do dono, ela sai como HTTP **200** com `result.isError: true` e sem
|
|
178
|
+
* código JSON-RPC; e ferramenta inexistente sai como **200** com o código
|
|
179
|
+
* **−32602** (não −32601, como se supunha). Desde então a telemetria lê o
|
|
180
|
+
* ENVELOPE da resposta (src/envelope.ts) e estes casos passam a existir.
|
|
181
|
+
*
|
|
182
|
+
* Os códigos reservados pela especificação JSON-RPC 2.0 dizem, sem ambiguidade
|
|
183
|
+
* de idioma, de quem é o conserto:
|
|
184
|
+
*
|
|
185
|
+
* - −32700 parse error, −32600 invalid request, −32601 method not found e
|
|
186
|
+
* −32602 invalid params são o CHAMADOR mandando algo que o protocolo
|
|
187
|
+
* recusa. É `contrato` — e o painel exclui `contrato` da taxa de erro
|
|
188
|
+
* (`eh_recusa_de_contrato()`), porque ferramenta que recusa chamada
|
|
189
|
+
* malformada está funcionando;
|
|
190
|
+
* - −32603 internal error é erro NOSSO, que escapou. É `defeito`, e por
|
|
191
|
+
* decisão do dono em 24/09/2026 ele entra na fila de saúde do painel: sem
|
|
192
|
+
* isso passaríamos a medir e continuaríamos a não agir.
|
|
193
|
+
*
|
|
194
|
+
* Código fora dessa faixa (erro definido pelo servidor, −32000 e abaixo) cai
|
|
195
|
+
* na mensagem, que é o caminho de `classifyError`.
|
|
196
|
+
*
|
|
197
|
+
* Cópia FIEL de sih-br-mcp/worker/src/call-shape.ts, onde a função estreou:
|
|
198
|
+
* classe medida por servidor com classificador diferente não é comparável, e
|
|
199
|
+
* comparar os sete é a razão de existir da seção de saúde do painel.
|
|
200
|
+
*/
|
|
201
|
+
export function classeDoErroRpc(code, message) {
|
|
202
|
+
if (code === -32700 || code === -32600 || code === -32601 || code === -32602)
|
|
203
|
+
return "contrato";
|
|
204
|
+
if (code === -32603)
|
|
205
|
+
return "defeito";
|
|
206
|
+
return classifyError(message);
|
|
207
|
+
}
|
|
168
208
|
//# sourceMappingURL=call-shape.js.map
|
package/dist/call-shape.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-shape.js","sourceRoot":"","sources":["../src/call-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAeH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAChC,mEAAmE;IACnE,yEAAyE;IACzE,uEAAuE;IACvE,uEAAuE;IACvE,2EAA2E;IAC3E,4EAA4E;IAC5E,4EAA4E;IAC5E,2EAA2E;IAC3E,4EAA4E;IAC5E,6EAA6E;IAC7E,wEAAwE;IACxE,YAAY;IACZ,MAAM,iBAAiB,GACrB,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,oCAAoC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrF,IACE,iBAAiB;QACjB,wJAAwJ,CAAC,IAAI,CAC3J,CAAC,CACF;QACD,wEAAwE;QACxE,4EAA4E;QAC5E,4EAA4E;QAC5E,qEAAqE;QACrE,2EAA2E;QAC3E,sEAAsE;QACtE,+GAA+G,CAAC,IAAI,CAClH,CAAC,CACF,EACD,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,IACE,gOAAgO,CA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OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,KAAK,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;IAC9E,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IACE,KAAK,YAAY,SAAS;QAC1B,KAAK,YAAY,UAAU;QAC3B,KAAK,YAAY,cAAc;QAC/B,KAAK,YAAY,WAAW,EAC5B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,eAAe,CAAC,IAAwB,EAAE,OAAe;IACvE,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,UAAU,CAAC;IAChG,IAAI,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IACtC,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/metrics.d.ts
CHANGED
|
@@ -79,7 +79,10 @@ declare class MetricsCollector {
|
|
|
79
79
|
}
|
|
80
80
|
export declare const metrics: MetricsCollector;
|
|
81
81
|
/**
|
|
82
|
-
* Helper to measure and record a tool execution
|
|
82
|
+
* Helper to measure and record a tool execution. It is also where the network
|
|
83
|
+
* collector of the call is opened (`comColetorDeRede`): every tool body runs
|
|
84
|
+
* inside it, so every request counts toward the `retrieval` block of the
|
|
85
|
+
* provenance (nested calls reuse the collector already open).
|
|
83
86
|
*/
|
|
84
87
|
export declare function withMetrics<T>(tool: string, api: string | undefined, fn: () => Promise<T>, cached?: boolean): Promise<T>;
|
|
85
88
|
/**
|
package/dist/metrics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,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MAAM,CAKZ;IAEF,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAE9B;IAED,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAEjC;IAED,OAAO,CAAC,SAAS;IAIjB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAI3C;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAI1C;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAI1C;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAI3C;CACF;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
package/dist/metrics.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Cache hit/miss rates
|
|
8
8
|
* - Response sizes
|
|
9
9
|
*/
|
|
10
|
+
import { comColetorDeRede } from "./retry.js";
|
|
10
11
|
class MetricsCollector {
|
|
11
12
|
metrics;
|
|
12
13
|
maxRecentErrors = 50;
|
|
@@ -200,14 +201,17 @@ class MetricsCollector {
|
|
|
200
201
|
// Singleton instance
|
|
201
202
|
export const metrics = new MetricsCollector();
|
|
202
203
|
/**
|
|
203
|
-
* Helper to measure and record a tool execution
|
|
204
|
+
* Helper to measure and record a tool execution. It is also where the network
|
|
205
|
+
* collector of the call is opened (`comColetorDeRede`): every tool body runs
|
|
206
|
+
* inside it, so every request counts toward the `retrieval` block of the
|
|
207
|
+
* provenance (nested calls reuse the collector already open).
|
|
204
208
|
*/
|
|
205
209
|
export async function withMetrics(tool, api, fn, cached = false) {
|
|
206
210
|
const start = Date.now();
|
|
207
211
|
let success = true;
|
|
208
212
|
let errorType;
|
|
209
213
|
try {
|
|
210
|
-
return await fn
|
|
214
|
+
return await comColetorDeRede(fn);
|
|
211
215
|
}
|
|
212
216
|
catch (error) {
|
|
213
217
|
success = false;
|
package/dist/metrics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAqC9C,MAAM,gBAAgB;IACZ,OAAO,CAAgB;IACvB,eAAe,GAAG,EAAE,CAAC;IACrB,OAAO,GAAG,IAAI,CAAC;IAEvB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1C,CAAC;IAEO,iBAAiB;QACvB,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,UAAU,EAAE,CAAC;YACb,cAAc,EAAE,CAAC;YACjB,aAAa,EAAE,CAAC;YAChB,cAAc,EAAE,CAAC;YACjB,gBAAgB,EAAE,CAAC;YACnB,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,YAAY,EAAE,EAAE;SACjB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAgB;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAkB;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAE1B,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAE1B,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAC/B,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,EAAE,C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ACxE,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/provenance.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provenance block (portfolio contract v1.
|
|
2
|
+
* Provenance block (portfolio contract v1.1) — pt-BR adapter over
|
|
3
3
|
* `@sbissoli/mcp-provenance`. The canonical model, the `concise`/`detailed`
|
|
4
4
|
* projections, serialization determinism, timezone handling and the footer
|
|
5
5
|
* wording live in the package; this module binds them to the IBGE server:
|
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
* - `provenienciaIbge(...)`, the per-call builder every tool uses. It pulls
|
|
14
14
|
* the REAL extraction instant (`retrieved_at`) and `served_from_cache` from
|
|
15
15
|
* the cache layer via `lastFetchMeta` (contract: cache hits keep the
|
|
16
|
-
* original fetch instant — it is the legally relevant extraction date)
|
|
16
|
+
* original fetch instant — it is the legally relevant extraction date), and
|
|
17
|
+
* since 5.4.0 the `retrieval` block (v1.1) from the network collector of the
|
|
18
|
+
* call (`@sbissoli/mcp-upstream`, opened by `withMetrics` — see `retry.ts`):
|
|
19
|
+
* how many requests went to the IBGE, how many attempts they took and which
|
|
20
|
+
* anomalies were overcome. `null` when nothing was measured — response served
|
|
21
|
+
* only from cache, or a direct call outside a tool (tests) — never an
|
|
22
|
+
* invented `{ requests: 1, attempts: 1 }`.
|
|
17
23
|
*
|
|
18
24
|
* Emission happens in `toMcpResult` (`structured.ts`): tools attach the
|
|
19
25
|
* canonical block to their `StructuredToolResult` and the handler emits the
|
|
@@ -26,7 +32,7 @@
|
|
|
26
32
|
* (aggregation/rankings computed server-side) → `true` + `derivation_note`.
|
|
27
33
|
*/
|
|
28
34
|
import { z } from "zod";
|
|
29
|
-
import { type CanonicalProvenance, type ConciseBlock } from "@sbissoli/mcp-provenance";
|
|
35
|
+
import { ConciseBlockSchema, type CanonicalProvenance, type ConciseBlock } from "@sbissoli/mcp-provenance";
|
|
30
36
|
/** Single provenance context for the server: `_meta` namespace, locale, timezone, mode. */
|
|
31
37
|
export declare const provenanceContext: import("@sbissoli/mcp-provenance").ProvenanceContext;
|
|
32
38
|
/** Canonical envelope v1.0 (post-validation). */
|
|
@@ -140,18 +146,23 @@ export declare const NOTA_DERIVACAO_ESTATISTICAS = "Estat\u00EDsticas (distribui
|
|
|
140
146
|
* ("2022" or "2020–2023"); no period column → null.
|
|
141
147
|
*/
|
|
142
148
|
export declare function extrairPeriodoSidra(colunas: string[], registros: Array<Record<string, string>>): string | null;
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Concise projection of a block — the shape embedded in `structuredContent`
|
|
151
|
+
* and `_meta`, and the `provenance` node of every tool's `outputSchema`.
|
|
152
|
+
*
|
|
153
|
+
* The shape is the package's `ConciseBlockSchema`, not a transcription. Found
|
|
154
|
+
* on 26/09/2026: this module transcribed the six v1.0 keys by hand, the SDK
|
|
155
|
+
* validates `structuredContent` against the sealed `outputSchema` at runtime,
|
|
156
|
+
* and raising the package to a contract with a new key (v1.1, `retrieval`)
|
|
157
|
+
* without touching the transcription failed EVERY tool call — "must NOT have
|
|
158
|
+
* additional properties", 48 tests. Importing the shape means a new key
|
|
159
|
+
* arrives together with the lib that emits it. Descriptions are the IBGE
|
|
160
|
+
* wording at the top level and the package's own pt-BR text underneath.
|
|
161
|
+
*/
|
|
162
|
+
export declare const provenanceBlockSchema: typeof ConciseBlockSchema;
|
|
152
163
|
/**
|
|
153
164
|
* Extends a tool's output schema with the provenance channel of the contract
|
|
154
|
-
* v1.
|
|
165
|
+
* v1.1: the concise block + the `attribution` URL list (MCP RFC #711). Every
|
|
155
166
|
* successful response carries both (wired in `toMcpResult`).
|
|
156
167
|
*/
|
|
157
168
|
export declare function comProveniencia<T extends z.ZodObject<z.ZodRawShape>>(schema: T): z.ZodObject<{
|
|
@@ -161,9 +172,25 @@ export declare function comProveniencia<T extends z.ZodObject<z.ZodRawShape>>(sc
|
|
|
161
172
|
source_url: z.ZodString;
|
|
162
173
|
data_vintage: z.ZodNullable<z.ZodString>;
|
|
163
174
|
retrieved_at: z.ZodString;
|
|
175
|
+
retrieval: z.ZodNullable<z.ZodObject<{
|
|
176
|
+
requests: z.ZodNumber;
|
|
177
|
+
attempts: z.ZodNumber;
|
|
178
|
+
anomalies: z.ZodArray<z.ZodObject<{
|
|
179
|
+
kind: z.ZodEnum<{
|
|
180
|
+
http_4xx: "http_4xx";
|
|
181
|
+
http_5xx: "http_5xx";
|
|
182
|
+
malformed_body: "malformed_body";
|
|
183
|
+
network: "network";
|
|
184
|
+
rate_limited: "rate_limited";
|
|
185
|
+
timeout: "timeout";
|
|
186
|
+
}>;
|
|
187
|
+
count: z.ZodNumber;
|
|
188
|
+
}, z.core.$strict>>;
|
|
189
|
+
unstable: z.ZodBoolean;
|
|
190
|
+
}, z.core.$strict>>;
|
|
164
191
|
citation: z.ZodString;
|
|
165
192
|
license: z.ZodNullable<z.ZodString>;
|
|
166
|
-
}, z.core.$
|
|
193
|
+
}, z.core.$strict>;
|
|
167
194
|
attribution: z.ZodArray<z.ZodString>;
|
|
168
195
|
}, z.core.$strip>;
|
|
169
196
|
/** Concise projection + attribution list for a block (used by `toMcpResult`). */
|
package/dist/provenance.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../src/provenance.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../src/provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGL,kBAAkB,EAGlB,KAAK,mBAAmB,EACxB,KAA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|
+
* Provenance block (portfolio contract v1.1) — pt-BR adapter over
|
|
3
3
|
* `@sbissoli/mcp-provenance`. The canonical model, the `concise`/`detailed`
|
|
4
4
|
* projections, serialization determinism, timezone handling and the footer
|
|
5
5
|
* wording live in the package; this module binds them to the IBGE server:
|
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
* - `provenienciaIbge(...)`, the per-call builder every tool uses. It pulls
|
|
14
14
|
* the REAL extraction instant (`retrieved_at`) and `served_from_cache` from
|
|
15
15
|
* the cache layer via `lastFetchMeta` (contract: cache hits keep the
|
|
16
|
-
* original fetch instant — it is the legally relevant extraction date)
|
|
16
|
+
* original fetch instant — it is the legally relevant extraction date), and
|
|
17
|
+
* since 5.4.0 the `retrieval` block (v1.1) from the network collector of the
|
|
18
|
+
* call (`@sbissoli/mcp-upstream`, opened by `withMetrics` — see `retry.ts`):
|
|
19
|
+
* how many requests went to the IBGE, how many attempts they took and which
|
|
20
|
+
* anomalies were overcome. `null` when nothing was measured — response served
|
|
21
|
+
* only from cache, or a direct call outside a tool (tests) — never an
|
|
22
|
+
* invented `{ requests: 1, attempts: 1 }`.
|
|
17
23
|
*
|
|
18
24
|
* Emission happens in `toMcpResult` (`structured.ts`): tools attach the
|
|
19
25
|
* canonical block to their `StructuredToolResult` and the handler emits the
|
|
@@ -26,7 +32,8 @@
|
|
|
26
32
|
* (aggregation/rankings computed server-side) → `true` + `derivation_note`.
|
|
27
33
|
*/
|
|
28
34
|
import { z } from "zod";
|
|
29
|
-
import { attributionList, createProvenanceContext, renderConcise, } from "@sbissoli/mcp-provenance";
|
|
35
|
+
import { attributionList, CONCISE_BLOCK_JSON_SCHEMA, ConciseBlockSchema, createProvenanceContext, renderConcise, } from "@sbissoli/mcp-provenance";
|
|
36
|
+
import { currentCall } from "@sbissoli/mcp-upstream/als";
|
|
30
37
|
import { lastFetchMeta } from "./cache.js";
|
|
31
38
|
import { API_ENDPOINTS } from "./config.js";
|
|
32
39
|
/** Single provenance context for the server: `_meta` namespace, locale, timezone, mode. */
|
|
@@ -136,6 +143,10 @@ export function provenienciaIbge(opts) {
|
|
|
136
143
|
derived: opts.derivado !== undefined,
|
|
137
144
|
...(opts.derivado !== undefined ? { derivation_note: opts.derivado.nota } : {}),
|
|
138
145
|
served_from_cache: meta ? meta.servedFromCache : null,
|
|
146
|
+
// The REAL count of this call (requests, attempts, anomalies), measured by
|
|
147
|
+
// the collector `withMetrics` opened; `null` = not measured (cache only, or
|
|
148
|
+
// no collector), which the contract prefers over an invented clean block.
|
|
149
|
+
retrieval: currentCall()?.retrieval() ?? null,
|
|
139
150
|
});
|
|
140
151
|
}
|
|
141
152
|
/** Fixed derivation note for the D2 statistics modes (estatisticas/agruparPor/topN). */
|
|
@@ -159,28 +170,70 @@ export function extrairPeriodoSidra(colunas, registros) {
|
|
|
159
170
|
return null;
|
|
160
171
|
return valores.length === 1 ? valores[0] : `${valores[0]}–${valores[valores.length - 1]}`;
|
|
161
172
|
}
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
citation:
|
|
174
|
-
license:
|
|
175
|
-
}
|
|
173
|
+
/**
|
|
174
|
+
* IBGE wording for the top-level keys of the concise block. Typed against the
|
|
175
|
+
* package's shape on purpose: a key the contract adds and this map does not
|
|
176
|
+
* describe fails to compile, instead of reaching the client undescribed.
|
|
177
|
+
*/
|
|
178
|
+
const DESCRICOES_IBGE = {
|
|
179
|
+
source: "Fonte oficial do dado (API do IBGE consultada)",
|
|
180
|
+
source_url: "URL canônica que reproduz a consulta",
|
|
181
|
+
data_vintage: "Período de referência do dado segundo a fonte; null se a fonte não expõe",
|
|
182
|
+
retrieved_at: "Instante real da extração no upstream (ISO-8601, horário de Brasília)",
|
|
183
|
+
retrieval: "Diagnóstico de origem desta chamada (contrato v1.1): idas à API do IBGE, tentativas somadas e anomalias contornadas; unstable=true quando houve anomalia. null quando nada foi medido (resposta servida só do cache)",
|
|
184
|
+
citation: "Citação pronta para uso",
|
|
185
|
+
license: "Regime legal do dado",
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Grafts descriptions onto a zod schema, node by node, from the JSON Schema
|
|
189
|
+
* the package publishes for the same projection (`overrides` win at the top
|
|
190
|
+
* level). The SHAPE — keys, types, strictness — stays the package's.
|
|
191
|
+
*/
|
|
192
|
+
function descreverPeloJsonSchema(schema, no, overrides = {},
|
|
193
|
+
/** Description of THIS node; `undefined` = the JSON Schema's, `""` = none (the parent carries it). */
|
|
194
|
+
texto = no?.description) {
|
|
195
|
+
let saida;
|
|
196
|
+
if (schema instanceof z.ZodNullable) {
|
|
197
|
+
// `x | null` is `oneOf: [x, null]` (retrieval) or `type: [x, "null"]` (vintage).
|
|
198
|
+
const interno = no?.oneOf ? no.oneOf.find((n) => n.type !== "null") : no;
|
|
199
|
+
saida = descreverPeloJsonSchema(schema.unwrap(), interno, {}, "").nullable();
|
|
200
|
+
}
|
|
201
|
+
else if (schema instanceof z.ZodArray) {
|
|
202
|
+
saida = z.array(descreverPeloJsonSchema(schema.element, no?.items));
|
|
203
|
+
}
|
|
204
|
+
else if (schema instanceof z.ZodObject) {
|
|
205
|
+
saida = z.strictObject(Object.fromEntries(Object.entries(schema.shape).map(([chave, filho]) => [
|
|
206
|
+
chave,
|
|
207
|
+
descreverPeloJsonSchema(filho, no?.properties?.[chave], {}, overrides[chave] ?? no?.properties?.[chave]?.description),
|
|
208
|
+
])));
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
saida = schema;
|
|
212
|
+
}
|
|
213
|
+
return texto ? saida.describe(texto) : saida;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Concise projection of a block — the shape embedded in `structuredContent`
|
|
217
|
+
* and `_meta`, and the `provenance` node of every tool's `outputSchema`.
|
|
218
|
+
*
|
|
219
|
+
* The shape is the package's `ConciseBlockSchema`, not a transcription. Found
|
|
220
|
+
* on 26/09/2026: this module transcribed the six v1.0 keys by hand, the SDK
|
|
221
|
+
* validates `structuredContent` against the sealed `outputSchema` at runtime,
|
|
222
|
+
* and raising the package to a contract with a new key (v1.1, `retrieval`)
|
|
223
|
+
* without touching the transcription failed EVERY tool call — "must NOT have
|
|
224
|
+
* additional properties", 48 tests. Importing the shape means a new key
|
|
225
|
+
* arrives together with the lib that emits it. Descriptions are the IBGE
|
|
226
|
+
* wording at the top level and the package's own pt-BR text underneath.
|
|
227
|
+
*/
|
|
228
|
+
export const provenanceBlockSchema = descreverPeloJsonSchema(ConciseBlockSchema, CONCISE_BLOCK_JSON_SCHEMA, DESCRICOES_IBGE);
|
|
176
229
|
/**
|
|
177
230
|
* Extends a tool's output schema with the provenance channel of the contract
|
|
178
|
-
* v1.
|
|
231
|
+
* v1.1: the concise block + the `attribution` URL list (MCP RFC #711). Every
|
|
179
232
|
* successful response carries both (wired in `toMcpResult`).
|
|
180
233
|
*/
|
|
181
234
|
export function comProveniencia(schema) {
|
|
182
235
|
return schema.extend({
|
|
183
|
-
provenance: provenanceBlockSchema.describe("Bloco de proveniência (contrato v1.
|
|
236
|
+
provenance: provenanceBlockSchema.describe("Bloco de proveniência (contrato v1.1): fonte, URL, período, extração, diagnóstico de origem e licença"),
|
|
184
237
|
attribution: z
|
|
185
238
|
.array(z.string())
|
|
186
239
|
.describe("URLs canônicas das fontes desta resposta (lista de atribuição)"),
|
package/dist/provenance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provenance.js","sourceRoot":"","sources":["../src/provenance.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provenance.js","sourceRoot":"","sources":["../src/provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,yBAAyB,EAC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AE,CAAC,KAAK,CAAC,EACvB,EAAE,EACF,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,WAAW,CACzD;SACF,CAAC,CACH,CACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,MAAM,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAC1D,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,CACa,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAuC,MAAS;IAC7E,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,UAAU,EAAE,qBAAqB,CAAC,QAAQ,CACxC,uGAAuG,CACxG;QACD,WAAW,EAAE,CAAC;aACX,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;aACjB,QAAQ,CAAC,gEAAgE,CAAC;KAC9E,CAAC,CAAC;AACL,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,CAAa;IAIhD,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,kBAAkB,CAAC,CAAa;IAC9C,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
package/dist/retry.d.ts
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A ida à origem: retry, timeout, orçamento — e a CONTAGEM que alimenta o
|
|
3
|
+
* bloco `retrieval` do contrato de proveniência v1.1.
|
|
4
|
+
*
|
|
5
|
+
* Desde a 5.4.0 (27/09/2026) a ida é do `@sbissoli/mcp-upstream`, o fetch
|
|
6
|
+
* comum do portfólio: retry com backoff e `Retry-After`, timeout por
|
|
7
|
+
* tentativa, orçamento total por ida e a contagem de idas, tentativas e
|
|
8
|
+
* anomalias que sai na proveniência de toda resposta. O pacote CLASSIFICA;
|
|
9
|
+
* este módulo DECIDE. O que continua sendo daqui:
|
|
10
|
+
*
|
|
11
|
+
* - os números: 5 tentativas (4 retries) de 2 s → 16 s, 30 s por tentativa
|
|
12
|
+
* (`REQUEST_TIMEOUT_MS`), os presets `QUICK`/`NONE`, sem jitter;
|
|
13
|
+
* - a lista de status que repete (`retryableStatusCodes`) — é ela que deixa
|
|
14
|
+
* o 500 da API de Agregados fora da repetição (`RETRY_SIDRA`);
|
|
15
|
+
* - "o fetch lançou" só repete se for REDE (`isNetworkError` sobre o
|
|
16
|
+
* `cause`): um `Error` que outra camada lançou dentro do fetch não é rede;
|
|
17
|
+
* - corpo em 200 que não é JSON NÃO repete. Nunca foi medido nas APIs do
|
|
18
|
+
* IBGE; o pacote repetiria por padrão porque o bcb mediu HTML-em-200
|
|
19
|
+
* transitório na origem DELE. Quando for medido aqui, é uma linha em
|
|
20
|
+
* `repetir` — até lá, paridade com o que este servidor sempre fez;
|
|
21
|
+
* - os erros tipados que o resto do servidor lê: `TimeoutError`,
|
|
22
|
+
* `UpstreamError` (com o que a fonte disse) e `RecursoAusenteError` (o
|
|
23
|
+
* `[]`-em-200, classe medida — ver `cachedFetchOne`).
|
|
24
|
+
*
|
|
25
|
+
* O que MUDOU com o pacote: 429 passa a honrar `Retry-After`; um pedido não
|
|
26
|
+
* ultrapassa o orçamento total mesmo que a origem responda devagar a cada
|
|
27
|
+
* tentativa; e toda tentativa — superada ou final — fica contada e sai em
|
|
28
|
+
* `retrieval`.
|
|
29
|
+
*
|
|
30
|
+
* O coletor por chamada. `comColetorDeRede` (chamado por `withMetrics`, que
|
|
31
|
+
* envolve o corpo de TODA tool) abre UM `UpstreamCall` por chamada de tool,
|
|
32
|
+
* propagado por `AsyncLocalStorage`; tudo o que `cachedFetch` e
|
|
33
|
+
* `fetchWithRetry` fazem dentro dele conta, e `provenienciaIbge` lê
|
|
34
|
+
* `currentCall()?.retrieval()`. Chamada aninhada (`search`/`fetch` chamam as
|
|
35
|
+
* tools de verdade; `ibge_nomes` mede os sub-passos) REUSA o coletor aberto —
|
|
36
|
+
* senão a contagem da tool de fora perderia as idas de dentro. Fora de um
|
|
37
|
+
* coletor — chamada direta em teste — cada ida ganha um coletor descartável
|
|
38
|
+
* e a proveniência degrada para `retrieval: null` ("não medido"), nunca quebra.
|
|
3
39
|
*/
|
|
40
|
+
import { type RetryContext } from "@sbissoli/mcp-upstream";
|
|
4
41
|
/**
|
|
5
42
|
* Thrown when a request exceeds its configured timeout. Carries the limit so
|
|
6
43
|
* callers (e.g. `parseHttpError`) can render a precise, user-facing message.
|
|
@@ -66,6 +103,9 @@ export declare class UpstreamError extends Error {
|
|
|
66
103
|
* `classifyError` lê para gravar a classe `nao_encontrado` na telemetria, no
|
|
67
104
|
* lugar do `outro` anônimo em que o `TypeError` caía. A forma também evita
|
|
68
105
|
* concordância com o gênero de `recurso` ("a Classe", "o Grupo").
|
|
106
|
+
*
|
|
107
|
+
* O pacote de rede não vê esta classe — para ele, `[]` com 200 é uma ida
|
|
108
|
+
* limpa, e É: a origem respondeu. A ausência é semântica deste servidor.
|
|
69
109
|
*/
|
|
70
110
|
export declare class RecursoAusenteError extends Error {
|
|
71
111
|
/** O que se procurava, em português, para a mensagem ao chamador. Ex.: "Classe CNAE". */
|
|
@@ -88,49 +128,65 @@ export declare class RecursoAusenteError extends Error {
|
|
|
88
128
|
* derrubar o tratamento do erro.
|
|
89
129
|
*/
|
|
90
130
|
export declare function motivoUpstream(response: Response): Promise<string | undefined>;
|
|
131
|
+
/** `motivoUpstream` para um corpo já lido (o pacote lê o corpo do erro no modo JSON). */
|
|
132
|
+
export declare function motivoDoCorpo(corpo: string | undefined): string | undefined;
|
|
91
133
|
export interface RetryOptions {
|
|
92
|
-
/**
|
|
134
|
+
/** Retries beyond the first attempt (default: 4 — up to 5 attempts) */
|
|
93
135
|
maxRetries?: number;
|
|
94
|
-
/** Initial delay in milliseconds (default: 2000) */
|
|
136
|
+
/** Initial delay in milliseconds (default: 2000); doubles at every retry */
|
|
95
137
|
initialDelayMs?: number;
|
|
96
138
|
/** Maximum delay in milliseconds (default: 16000) */
|
|
97
139
|
maxDelayMs?: number;
|
|
98
|
-
/** Multiplier for exponential backoff (default: 2) */
|
|
99
|
-
backoffMultiplier?: number;
|
|
100
140
|
/** HTTP status codes that should trigger a retry */
|
|
101
141
|
retryableStatusCodes?: number[];
|
|
102
|
-
/**
|
|
103
|
-
isRetryable?: (error: Error) => boolean;
|
|
104
|
-
/** Per-request timeout in milliseconds (default: REQUEST_TIMEOUT_MS) */
|
|
142
|
+
/** Per-attempt timeout in milliseconds (default: REQUEST_TIMEOUT_MS) */
|
|
105
143
|
timeoutMs?: number;
|
|
106
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Retry configuration presets for different scenarios. `AGGRESSIVE` (6 retries
|
|
147
|
+
* up to 30 s) went away in 5.4.0: nothing used it, and it would not fit the
|
|
148
|
+
* total budget of a request (`orcamentoTotalMs`).
|
|
149
|
+
*/
|
|
150
|
+
export declare const RETRY_PRESETS: {
|
|
151
|
+
/** Standard retry for API requests */
|
|
152
|
+
readonly DEFAULT: RetryOptions;
|
|
153
|
+
/** Quick retry for best-effort enrichment requests (ibge_cidades, ibge_vizinhos) */
|
|
154
|
+
readonly QUICK: RetryOptions;
|
|
155
|
+
/** No retry */
|
|
156
|
+
readonly NONE: RetryOptions;
|
|
157
|
+
};
|
|
107
158
|
/**
|
|
108
159
|
* Check if an error is a network-related error that should be retried
|
|
109
160
|
*/
|
|
110
161
|
export declare function isNetworkError(error: Error): boolean;
|
|
111
162
|
/**
|
|
112
|
-
*
|
|
163
|
+
* Orçamento TOTAL de uma ida na política padrão: as tentativas inteiras mais as
|
|
164
|
+
* esperas entre elas — o que este servidor já gastava no pior caso (5 × 30 s +
|
|
165
|
+
* 2 + 4 + 8 + 16 s = 180 s). O pacote exige um teto explícito, e o teto honesto
|
|
166
|
+
* é o que já valia. Vale por cima de qualquer política por ida.
|
|
113
167
|
*/
|
|
114
|
-
export declare function
|
|
168
|
+
export declare function orcamentoTotalMs(o?: Required<RetryOptions>): number;
|
|
115
169
|
/**
|
|
116
|
-
*
|
|
170
|
+
* A decisão de repetir uma tentativa que falhou. O pacote diz a classe; aqui
|
|
171
|
+
* se decide, com a política daquela ida (a lista de status é o que varia
|
|
172
|
+
* entre `DEFAULT` e `RETRY_SIDRA`).
|
|
117
173
|
*/
|
|
118
|
-
export declare function
|
|
174
|
+
export declare function repetir(ctx: RetryContext, o: Required<RetryOptions>): boolean;
|
|
119
175
|
/**
|
|
120
|
-
*
|
|
176
|
+
* Abre o coletor de UMA chamada de tool e roda `fn` dentro dele — ou reusa o
|
|
177
|
+
* que já está aberto, se `fn` é um passo de uma chamada maior. `withMetrics`
|
|
178
|
+
* chama isto para toda tool; `provenienciaIbge` lê o resultado.
|
|
121
179
|
*/
|
|
122
|
-
export declare function
|
|
180
|
+
export declare function comColetorDeRede<T>(fn: () => Promise<T>): Promise<T>;
|
|
123
181
|
/**
|
|
124
|
-
*
|
|
182
|
+
* Uma ida lendo JSON — o caminho de `cachedFetch`. Erro de status vem como
|
|
183
|
+
* `UpstreamError` com o que a fonte disse; tempo esgotado, como `TimeoutError`.
|
|
125
184
|
*/
|
|
126
|
-
export declare
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/** No retry */
|
|
134
|
-
readonly NONE: RetryOptions;
|
|
135
|
-
};
|
|
185
|
+
export declare function fetchJson<T>(url: string, options?: RetryOptions): Promise<T>;
|
|
186
|
+
/**
|
|
187
|
+
* Uma ida que devolve a `Response` inteira, corpo não consumido — para quem
|
|
188
|
+
* só precisa saber se a origem respondeu (`ibge_vizinhos` e a malha). Status
|
|
189
|
+
* de erro final lança `UpstreamError`, como `cachedFetch`.
|
|
190
|
+
*/
|
|
191
|
+
export declare function fetchWithRetry(url: string, init?: RequestInit, options?: RetryOptions): Promise<Response>;
|
|
136
192
|
//# sourceMappingURL=retry.d.ts.map
|
package/dist/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAGL,KAAK,YAAY,EAIlB,MAAM,wBAAwB,CAAC;AAIhC;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;aACT,SAAS,EAAE,MAAM;IAA7C,YAA4B,SAAS,EAAE,MAAM,EAG5C;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,KAAK;aAEpB,MAAM,EAAE,MAAM;aACd,UAAU,EAAE,MAAM;IAClC,iFAAiF;aACjE,OAAO,CAAC,EAAE,MAAM;IAJlC,YACkB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM;IAClC,iFAAiF;IACjE,OAAO,CAAC,EAAE,MAAM,YAAA,EAChC,MAAM,SAAK,EAIZ;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAE1C,yFAAyF;aACzE,OAAO,EAAE,MAAM;IAC/B,uDAAuD;aACvC,EAAE,EAAE,MAAM;IAJ5B;IACE,yFAAyF;IACzE,OAAO,EAAE,MAAM;IAC/B,uDAAuD;IACvC,EAAE,EAAE,MAAM,EAI3B;CACF;AAED;;;;;;;;GAQG;A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;GAIG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,QAAQ,CAAC,CAOnB"}
|
package/dist/retry.js
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A ida à origem: retry, timeout, orçamento — e a CONTAGEM que alimenta o
|
|
3
|
+
* bloco `retrieval` do contrato de proveniência v1.1.
|
|
4
|
+
*
|
|
5
|
+
* Desde a 5.4.0 (27/09/2026) a ida é do `@sbissoli/mcp-upstream`, o fetch
|
|
6
|
+
* comum do portfólio: retry com backoff e `Retry-After`, timeout por
|
|
7
|
+
* tentativa, orçamento total por ida e a contagem de idas, tentativas e
|
|
8
|
+
* anomalias que sai na proveniência de toda resposta. O pacote CLASSIFICA;
|
|
9
|
+
* este módulo DECIDE. O que continua sendo daqui:
|
|
10
|
+
*
|
|
11
|
+
* - os números: 5 tentativas (4 retries) de 2 s → 16 s, 30 s por tentativa
|
|
12
|
+
* (`REQUEST_TIMEOUT_MS`), os presets `QUICK`/`NONE`, sem jitter;
|
|
13
|
+
* - a lista de status que repete (`retryableStatusCodes`) — é ela que deixa
|
|
14
|
+
* o 500 da API de Agregados fora da repetição (`RETRY_SIDRA`);
|
|
15
|
+
* - "o fetch lançou" só repete se for REDE (`isNetworkError` sobre o
|
|
16
|
+
* `cause`): um `Error` que outra camada lançou dentro do fetch não é rede;
|
|
17
|
+
* - corpo em 200 que não é JSON NÃO repete. Nunca foi medido nas APIs do
|
|
18
|
+
* IBGE; o pacote repetiria por padrão porque o bcb mediu HTML-em-200
|
|
19
|
+
* transitório na origem DELE. Quando for medido aqui, é uma linha em
|
|
20
|
+
* `repetir` — até lá, paridade com o que este servidor sempre fez;
|
|
21
|
+
* - os erros tipados que o resto do servidor lê: `TimeoutError`,
|
|
22
|
+
* `UpstreamError` (com o que a fonte disse) e `RecursoAusenteError` (o
|
|
23
|
+
* `[]`-em-200, classe medida — ver `cachedFetchOne`).
|
|
24
|
+
*
|
|
25
|
+
* O que MUDOU com o pacote: 429 passa a honrar `Retry-After`; um pedido não
|
|
26
|
+
* ultrapassa o orçamento total mesmo que a origem responda devagar a cada
|
|
27
|
+
* tentativa; e toda tentativa — superada ou final — fica contada e sai em
|
|
28
|
+
* `retrieval`.
|
|
29
|
+
*
|
|
30
|
+
* O coletor por chamada. `comColetorDeRede` (chamado por `withMetrics`, que
|
|
31
|
+
* envolve o corpo de TODA tool) abre UM `UpstreamCall` por chamada de tool,
|
|
32
|
+
* propagado por `AsyncLocalStorage`; tudo o que `cachedFetch` e
|
|
33
|
+
* `fetchWithRetry` fazem dentro dele conta, e `provenienciaIbge` lê
|
|
34
|
+
* `currentCall()?.retrieval()`. Chamada aninhada (`search`/`fetch` chamam as
|
|
35
|
+
* tools de verdade; `ibge_nomes` mede os sub-passos) REUSA o coletor aberto —
|
|
36
|
+
* senão a contagem da tool de fora perderia as idas de dentro. Fora de um
|
|
37
|
+
* coletor — chamada direta em teste — cada ida ganha um coletor descartável
|
|
38
|
+
* e a proveniência degrada para `retrieval: null` ("não medido"), nunca quebra.
|
|
3
39
|
*/
|
|
40
|
+
import { createUpstream, UpstreamError as ErroDaIda, } from "@sbissoli/mcp-upstream";
|
|
41
|
+
import { currentCall, withCall } from "@sbissoli/mcp-upstream/als";
|
|
4
42
|
import { REQUEST_TIMEOUT_MS } from "./config.js";
|
|
5
43
|
/**
|
|
6
44
|
* Thrown when a request exceeds its configured timeout. Carries the limit so
|
|
@@ -76,6 +114,9 @@ export class UpstreamError extends Error {
|
|
|
76
114
|
* `classifyError` lê para gravar a classe `nao_encontrado` na telemetria, no
|
|
77
115
|
* lugar do `outro` anônimo em que o `TypeError` caía. A forma também evita
|
|
78
116
|
* concordância com o gênero de `recurso` ("a Classe", "o Grupo").
|
|
117
|
+
*
|
|
118
|
+
* O pacote de rede não vê esta classe — para ele, `[]` com 200 é uma ida
|
|
119
|
+
* limpa, e É: a origem respondeu. A ausência é semântica deste servidor.
|
|
79
120
|
*/
|
|
80
121
|
export class RecursoAusenteError extends Error {
|
|
81
122
|
recurso;
|
|
@@ -102,42 +143,66 @@ export class RecursoAusenteError extends Error {
|
|
|
102
143
|
*/
|
|
103
144
|
export async function motivoUpstream(response) {
|
|
104
145
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
146
|
+
return motivoDoCorpo(await response.text());
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** `motivoUpstream` para um corpo já lido (o pacote lê o corpo do erro no modo JSON). */
|
|
153
|
+
export function motivoDoCorpo(corpo) {
|
|
154
|
+
const cru = (corpo ?? "").trim();
|
|
155
|
+
if (!cru || cru.startsWith("<"))
|
|
156
|
+
return undefined;
|
|
157
|
+
// JSON de erro das APIs do IBGE em v1/v3 traz a frase numa chave; texto
|
|
158
|
+
// cru é o caso do SIDRA. Tentar a chave antes de despejar o JSON inteiro.
|
|
159
|
+
let texto = cru;
|
|
160
|
+
try {
|
|
161
|
+
const j = JSON.parse(cru);
|
|
162
|
+
for (const chave of ["message", "mensagem", "erro", "error", "detail"]) {
|
|
163
|
+
if (typeof j[chave] === "string" && j[chave]) {
|
|
164
|
+
texto = j[chave];
|
|
165
|
+
break;
|
|
118
166
|
}
|
|
119
167
|
}
|
|
120
|
-
catch {
|
|
121
|
-
// Não era JSON — o texto cru é a mensagem, que é o caso do SIDRA.
|
|
122
|
-
}
|
|
123
|
-
const limpo = texto.replace(/\s+/g, " ").trim();
|
|
124
|
-
if (!limpo)
|
|
125
|
-
return undefined;
|
|
126
|
-
return limpo.length > 300 ? `${limpo.slice(0, 297)}...` : limpo;
|
|
127
168
|
}
|
|
128
169
|
catch {
|
|
129
|
-
|
|
170
|
+
// Não era JSON — o texto cru é a mensagem, que é o caso do SIDRA.
|
|
130
171
|
}
|
|
172
|
+
const limpo = texto.replace(/\s+/g, " ").trim();
|
|
173
|
+
if (!limpo)
|
|
174
|
+
return undefined;
|
|
175
|
+
return limpo.length > 300 ? `${limpo.slice(0, 297)}...` : limpo;
|
|
131
176
|
}
|
|
132
177
|
const DEFAULT_OPTIONS = {
|
|
133
178
|
maxRetries: 4,
|
|
134
179
|
initialDelayMs: 2000,
|
|
135
180
|
maxDelayMs: 16000,
|
|
136
|
-
backoffMultiplier: 2,
|
|
137
181
|
retryableStatusCodes: [429, 500, 502, 503, 504],
|
|
138
|
-
isRetryable: isNetworkError,
|
|
139
182
|
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
140
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* Retry configuration presets for different scenarios. `AGGRESSIVE` (6 retries
|
|
186
|
+
* up to 30 s) went away in 5.4.0: nothing used it, and it would not fit the
|
|
187
|
+
* total budget of a request (`orcamentoTotalMs`).
|
|
188
|
+
*/
|
|
189
|
+
export const RETRY_PRESETS = {
|
|
190
|
+
/** Standard retry for API requests */
|
|
191
|
+
DEFAULT: {
|
|
192
|
+
maxRetries: 4,
|
|
193
|
+
initialDelayMs: 2000,
|
|
194
|
+
},
|
|
195
|
+
/** Quick retry for best-effort enrichment requests (ibge_cidades, ibge_vizinhos) */
|
|
196
|
+
QUICK: {
|
|
197
|
+
maxRetries: 2,
|
|
198
|
+
initialDelayMs: 500,
|
|
199
|
+
maxDelayMs: 2000,
|
|
200
|
+
},
|
|
201
|
+
/** No retry */
|
|
202
|
+
NONE: {
|
|
203
|
+
maxRetries: 0,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
141
206
|
/**
|
|
142
207
|
* Check if an error is a network-related error that should be retried
|
|
143
208
|
*/
|
|
@@ -162,123 +227,153 @@ export function isNetworkError(error) {
|
|
|
162
227
|
return networkErrorPatterns.some((pattern) => message.includes(pattern.toLowerCase()) || error.name === pattern);
|
|
163
228
|
}
|
|
164
229
|
/**
|
|
165
|
-
*
|
|
230
|
+
* Orçamento TOTAL de uma ida na política padrão: as tentativas inteiras mais as
|
|
231
|
+
* esperas entre elas — o que este servidor já gastava no pior caso (5 × 30 s +
|
|
232
|
+
* 2 + 4 + 8 + 16 s = 180 s). O pacote exige um teto explícito, e o teto honesto
|
|
233
|
+
* é o que já valia. Vale por cima de qualquer política por ida.
|
|
166
234
|
*/
|
|
167
|
-
export function
|
|
168
|
-
|
|
235
|
+
export function orcamentoTotalMs(o = DEFAULT_OPTIONS) {
|
|
236
|
+
let esperas = 0;
|
|
237
|
+
for (let r = 0; r < o.maxRetries; r++) {
|
|
238
|
+
esperas += Math.min(o.initialDelayMs * 2 ** r, o.maxDelayMs);
|
|
239
|
+
}
|
|
240
|
+
return (o.maxRetries + 1) * o.timeoutMs + esperas;
|
|
169
241
|
}
|
|
170
242
|
/**
|
|
171
|
-
*
|
|
243
|
+
* A decisão de repetir uma tentativa que falhou. O pacote diz a classe; aqui
|
|
244
|
+
* se decide, com a política daquela ida (a lista de status é o que varia
|
|
245
|
+
* entre `DEFAULT` e `RETRY_SIDRA`).
|
|
172
246
|
*/
|
|
173
|
-
function
|
|
174
|
-
|
|
247
|
+
export function repetir(ctx, o) {
|
|
248
|
+
// Tempo esgotado é transitório por natureza — cabeçalhos ou corpo.
|
|
249
|
+
if (ctx.kind === "timeout")
|
|
250
|
+
return true;
|
|
251
|
+
// O fetch lançou: só é rede se a mensagem for de rede. Um `Error` de outra
|
|
252
|
+
// camada lançado dentro do fetch (é assim que os testes simulam status) não é.
|
|
253
|
+
if (ctx.kind === "network")
|
|
254
|
+
return ctx.cause instanceof Error && isNetworkError(ctx.cause);
|
|
255
|
+
// 200 que não é JSON: nunca medido nas APIs do IBGE — paridade (ver cabeçalho).
|
|
256
|
+
if (ctx.kind === "malformed_body")
|
|
257
|
+
return false;
|
|
258
|
+
// Um status chegou (4xx, 5xx, 429): a lista decide.
|
|
259
|
+
return ctx.status !== undefined && o.retryableStatusCodes.includes(ctx.status);
|
|
175
260
|
}
|
|
176
261
|
/**
|
|
177
|
-
*
|
|
262
|
+
* A política de rede do servidor: os números padrão, sem jitter (os testes
|
|
263
|
+
* contam o relógio), e a ligação TARDIA ao `fetch` global — os testes o dublam
|
|
264
|
+
* depois de o módulo carregar.
|
|
178
265
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
266
|
+
function upstreamIbge() {
|
|
267
|
+
return createUpstream({
|
|
268
|
+
timeoutMs: DEFAULT_OPTIONS.timeoutMs,
|
|
269
|
+
retries: DEFAULT_OPTIONS.maxRetries,
|
|
270
|
+
budgetMs: orcamentoTotalMs(),
|
|
271
|
+
backoff: {
|
|
272
|
+
baseMs: DEFAULT_OPTIONS.initialDelayMs,
|
|
273
|
+
maxMs: DEFAULT_OPTIONS.maxDelayMs,
|
|
274
|
+
jitterMs: 0,
|
|
275
|
+
},
|
|
276
|
+
honorRetryAfter: true,
|
|
277
|
+
retryOn: (ctx) => repetir(ctx, DEFAULT_OPTIONS),
|
|
278
|
+
fetchImpl: (input, init) => globalThis.fetch(input, init),
|
|
279
|
+
});
|
|
182
280
|
}
|
|
183
281
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* Returns a `cleanup` that must run after each attempt to clear the timer.
|
|
282
|
+
* Abre o coletor de UMA chamada de tool e roda `fn` dentro dele — ou reusa o
|
|
283
|
+
* que já está aberto, se `fn` é um passo de uma chamada maior. `withMetrics`
|
|
284
|
+
* chama isto para toda tool; `provenienciaIbge` lê o resultado.
|
|
188
285
|
*/
|
|
189
|
-
function
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
286
|
+
export function comColetorDeRede(fn) {
|
|
287
|
+
return currentCall() ? fn() : withCall(upstreamIbge(), () => fn());
|
|
288
|
+
}
|
|
289
|
+
/** O coletor da chamada corrente; fora de uma, um descartável (a ida ainda tem política). */
|
|
290
|
+
function coletor() {
|
|
291
|
+
return currentCall() ?? upstreamIbge().call();
|
|
292
|
+
}
|
|
293
|
+
/** A política de UMA ida, na forma que o pacote lê por requisição. */
|
|
294
|
+
function politicaDaIda(o, init) {
|
|
295
|
+
return {
|
|
296
|
+
...init,
|
|
297
|
+
signal: init?.signal ?? undefined,
|
|
298
|
+
timeoutMs: o.timeoutMs,
|
|
299
|
+
retries: o.maxRetries,
|
|
300
|
+
backoff: { baseMs: o.initialDelayMs, maxMs: o.maxDelayMs },
|
|
301
|
+
retryOn: (ctx) => repetir(ctx, o),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Uma ida lendo JSON — o caminho de `cachedFetch`. Erro de status vem como
|
|
306
|
+
* `UpstreamError` com o que a fonte disse; tempo esgotado, como `TimeoutError`.
|
|
307
|
+
*/
|
|
308
|
+
export async function fetchJson(url, options) {
|
|
309
|
+
const o = { ...DEFAULT_OPTIONS, ...options };
|
|
310
|
+
try {
|
|
311
|
+
return await coletor().json(url, politicaDaIda(o));
|
|
312
|
+
}
|
|
313
|
+
catch (erro) {
|
|
314
|
+
throw await traduzirErro(erro, o);
|
|
199
315
|
}
|
|
200
|
-
return { signal: controller.signal, cleanup: () => clearTimeout(timer) };
|
|
201
316
|
}
|
|
202
317
|
/**
|
|
203
|
-
*
|
|
318
|
+
* Uma ida que devolve a `Response` inteira, corpo não consumido — para quem
|
|
319
|
+
* só precisa saber se a origem respondeu (`ibge_vizinhos` e a malha). Status
|
|
320
|
+
* de erro final lança `UpstreamError`, como `cachedFetch`.
|
|
204
321
|
*/
|
|
205
322
|
export async function fetchWithRetry(url, init, options) {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
for (let attempt = 1; attempt <= opts.maxRetries + 1; attempt++) {
|
|
210
|
-
const { signal, cleanup } = createTimeoutSignal(opts.timeoutMs, init?.signal);
|
|
211
|
-
try {
|
|
212
|
-
const response = await fetch(url, { ...init, signal });
|
|
213
|
-
// Check if status code is retryable
|
|
214
|
-
if (!response.ok && isRetryableStatus(response.status, opts.retryableStatusCodes)) {
|
|
215
|
-
lastResponse = response;
|
|
216
|
-
if (attempt <= opts.maxRetries) {
|
|
217
|
-
const delay = calculateDelay(attempt, opts);
|
|
218
|
-
await sleep(delay);
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return response;
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
// A timeout aborts with a TimeoutError reason; surface that, not the
|
|
226
|
-
// generic AbortError the fetch implementation may throw.
|
|
227
|
-
const timedOut = signal.reason instanceof TimeoutError;
|
|
228
|
-
lastError = timedOut
|
|
229
|
-
? signal.reason
|
|
230
|
-
: error instanceof Error
|
|
231
|
-
? error
|
|
232
|
-
: new Error(String(error));
|
|
233
|
-
// Timeouts are transient and retryable; otherwise defer to the predicate.
|
|
234
|
-
const shouldRetry = timedOut || opts.isRetryable(lastError);
|
|
235
|
-
if (shouldRetry && attempt <= opts.maxRetries) {
|
|
236
|
-
const delay = calculateDelay(attempt, opts);
|
|
237
|
-
await sleep(delay);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
// If not retryable or no more retries, throw
|
|
241
|
-
throw lastError;
|
|
242
|
-
}
|
|
243
|
-
finally {
|
|
244
|
-
cleanup();
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
// If we exhausted retries with a response, throw an error with the status
|
|
248
|
-
if (lastResponse) {
|
|
249
|
-
throw new UpstreamError(lastResponse.status, lastResponse.statusText, await motivoUpstream(lastResponse), ` (after ${opts.maxRetries} retries)`);
|
|
323
|
+
const o = { ...DEFAULT_OPTIONS, ...options };
|
|
324
|
+
try {
|
|
325
|
+
return await coletor().response(url, politicaDaIda(o, init));
|
|
250
326
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
throw lastError;
|
|
327
|
+
catch (erro) {
|
|
328
|
+
throw await traduzirErro(erro, o);
|
|
254
329
|
}
|
|
255
|
-
// This should never happen, but TypeScript needs it
|
|
256
|
-
throw new Error("Unexpected retry loop exit");
|
|
257
330
|
}
|
|
331
|
+
/** Texto padrão dos status que as APIs do IBGE respondem (o modo JSON do pacote não guarda a `Response`). */
|
|
332
|
+
const STATUS_TEXT = {
|
|
333
|
+
400: "Bad Request",
|
|
334
|
+
401: "Unauthorized",
|
|
335
|
+
403: "Forbidden",
|
|
336
|
+
404: "Not Found",
|
|
337
|
+
405: "Method Not Allowed",
|
|
338
|
+
406: "Not Acceptable",
|
|
339
|
+
408: "Request Timeout",
|
|
340
|
+
429: "Too Many Requests",
|
|
341
|
+
500: "Internal Server Error",
|
|
342
|
+
502: "Bad Gateway",
|
|
343
|
+
503: "Service Unavailable",
|
|
344
|
+
504: "Gateway Timeout",
|
|
345
|
+
};
|
|
258
346
|
/**
|
|
259
|
-
*
|
|
347
|
+
* Do erro do pacote (classe + contagem) ao erro que o servidor sempre leu
|
|
348
|
+
* (tipo + mensagem). O sufixo "(after N retries)" continua onde estava: na
|
|
349
|
+
* mensagem de quem esgotou as tentativas.
|
|
260
350
|
*/
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
351
|
+
async function traduzirErro(erro, o) {
|
|
352
|
+
if (!(erro instanceof ErroDaIda)) {
|
|
353
|
+
return erro instanceof Error ? erro : new Error(String(erro));
|
|
354
|
+
}
|
|
355
|
+
const sufixo = erro.attempts > 1 ? ` (after ${erro.attempts - 1} retries)` : "";
|
|
356
|
+
switch (erro.kind) {
|
|
357
|
+
case "timeout":
|
|
358
|
+
return new TimeoutError(o.timeoutMs);
|
|
359
|
+
case "network":
|
|
360
|
+
case "aborted":
|
|
361
|
+
// O que o fetch lançou é o que o servidor sempre viu.
|
|
362
|
+
return erro.cause instanceof Error
|
|
363
|
+
? erro.cause
|
|
364
|
+
: new Error(erro.message, { cause: erro.cause });
|
|
365
|
+
case "malformed_body":
|
|
366
|
+
return new Error(`Resposta da API do IBGE não é JSON válido${sufixo}`, { cause: erro.cause });
|
|
367
|
+
default: {
|
|
368
|
+
// Um status chegou: http_4xx, http_5xx, rate_limited, not_found. O corpo
|
|
369
|
+
// vai junto — é nele que a fonte diz QUAL parâmetro recusou e por quê.
|
|
370
|
+
const status = erro.status ?? 0;
|
|
371
|
+
const detalhe = erro.response
|
|
372
|
+
? await motivoUpstream(erro.response)
|
|
373
|
+
: motivoDoCorpo(erro.body);
|
|
374
|
+
const statusText = erro.response?.statusText || STATUS_TEXT[status] || "";
|
|
375
|
+
return new UpstreamError(status, statusText, detalhe, sufixo);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
284
379
|
//# sourceMappingURL=retry.js.map
|
package/dist/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EACL,cAAc,EACd,aAAa,IAAI,SAAS,GAK3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;GAGG;AACH,MA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AI,CAAC,KAAK,EAAE,CAAC,CAAC;QACrD,KAAK,gBAAgB;YACnB,OAAO,IAAI,KAAK,CAAC,4CAA4C,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAChG,SAAS,CAAC;YACR,yEAAyE;YACzE,uEAAuE;YACvE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;YAChC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ;gBAC3B,CAAC,CAAC,MAAM,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;gBACrC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,UAAU,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC1E,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ibge-br-mcp",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"mcpName": "io.github.SidneyBissoli/ibge-br-mcp",
|
|
5
5
|
"description": "MCP server giving AI assistants live, sourced access to Brazilian public data — geography, census, economy and health — from the official IBGE APIs. Exact figures with provenance, not approximations.",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"format:check": "prettier --check src/",
|
|
26
26
|
"test": "vitest run",
|
|
27
27
|
"test:watch": "vitest",
|
|
28
|
-
"test:coverage": "vitest run --coverage"
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"manifest:lhm": "node scripts/gen-lhm-manifest.mjs"
|
|
29
30
|
},
|
|
30
31
|
"keywords": [
|
|
31
32
|
"mcp",
|
|
@@ -59,9 +60,10 @@
|
|
|
59
60
|
"license": "MIT",
|
|
60
61
|
"dependencies": {
|
|
61
62
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
62
|
-
"@sbissoli/mcp-provenance": "^0.
|
|
63
|
-
"@sbissoli/mcp-search": "^0.
|
|
63
|
+
"@sbissoli/mcp-provenance": "^0.2.0",
|
|
64
|
+
"@sbissoli/mcp-search": "^0.6.0",
|
|
64
65
|
"@sbissoli/mcp-stats": "^0.3.0",
|
|
66
|
+
"@sbissoli/mcp-upstream": "^0.3.0",
|
|
65
67
|
"zod": "^4.5.4"
|
|
66
68
|
},
|
|
67
69
|
"devDependencies": {
|