bcb_serie_ultimos
Retrieve recent time series values from the Brazilian Central Bank's economic database. Specify a series code and quantity to access current economic indicators.
Instructions
Obtém os últimos N valores de uma série temporal do BCB. Útil para consultar dados mais recentes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| codigo | Yes | Código da série no SGS/BCB | |
| quantidade | No | Quantidade de valores a retornar (1-1000, padrão: 10) |
Implementation Reference
- src/tools.ts:392-430 (handler)The `handleSerieUltimos` function fetches the latest N data points for a BCB series from the API.
export async function handleSerieUltimos( args: { codigo: number; quantidade: number }, timeoutMs?: number, maxRetries?: number ): Promise<ToolResult> { try { const url = `${BCB_API_BASE}.${args.codigo}/dados/ultimos/${args.quantidade}?formato=json`; const data = await fetchBcbApi(url, timeoutMs, maxRetries) as SerieValor[]; if (!Array.isArray(data) || data.length === 0) { return { content: [{ type: "text" as const, text: `Nenhum dado encontrado para a série ${args.codigo}.` }] }; } const serieInfo = SERIES_POPULARES.find(s => s.codigo === args.codigo); const result = { serie: { codigo: args.codigo, nome: serieInfo?.nome || `Série ${args.codigo}`, categoria: serieInfo?.categoria || "Desconhecida", periodicidade: serieInfo?.periodicidade || "Desconhecida" }, totalRegistros: data.length, dados: data.map(d => ({ data: d.data, valor: parseFloat(d.valor) })) }; return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Erro ao consultar últimos valores da série ${args.codigo}: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } export async function handleSerieMetadados( args: { codigo: number }, timeoutMs?: number, - src/tools.ts:756-767 (schema)The definition and input schema for the `bcb_serie_ultimos` tool.
{ name: "bcb_serie_ultimos", description: "Obtém os últimos N valores de uma série temporal do BCB. Útil para consultar dados mais recentes.", inputSchema: { type: "object" as const, properties: { codigo: { type: "number" as const, description: "Código da série no SGS/BCB" }, quantidade: { type: "number" as const, description: "Quantidade de valores a retornar (1-1000, padrão: 10)" } }, required: ["codigo"] } }, - src/tools.ts:848-852 (registration)The `dispatchTool` function routes the `bcb_serie_ultimos` tool to its handler function.
case "bcb_serie_ultimos": return handleSerieUltimos( { codigo: args.codigo as number, quantidade: (args.quantidade as number) || 10 }, timeoutMs, maxRetries );