get_statement
Retrieve formatted bank account statements for specified time periods, converting transaction data to readable currency units and ISO datetime formats.
Instructions
Get account statement for a given period. Rate limit: 1 request per 60 seconds. Max period: 31 days + 1 hour. Rules: 1. Fetch from default account (account_id = '0') unless another account is specified. 2. Amounts are converted from the smallest currency unit (e.g., kopiyka, cent) to the main unit and returned as decimals. 3. Transaction timestamps ('time') are converted from Unix timestamps to ISO 8601 datetime strings (UTC). 4. Fields 'id', 'invoiceId', 'counterEdrpou', and 'counterIban' are omitted from the returned results.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | Account identifier from the list of accounts, or '0' for default | |
| from_timestamp | Yes | Start of the statement period (Unix timestamp) | |
| to_timestamp | Yes | End of the statement period (Unix timestamp) |
Implementation Reference
- src/index.ts:127-201 (handler)The main handler function for the 'get_statement' tool. It validates input using Zod schema, fetches the statement data from the Monobank API, processes the transactions by converting timestamps to ISO strings and amounts to decimals, and returns the result as a formatted JSON string.async function getStatement(args: unknown) { /** * Get account statement for a given period. * Rate limit: 1 request per 60 seconds. * Max period: 31 days + 1 hour. * * Rules: * 1. Fetch from default account (account_id = "0") unless another account is specified. * 2. Amounts are converted from the smallest currency unit (e.g., kopiyka, cent) * to the main unit and returned as decimals. * 3. Transaction timestamps ("time") are converted from Unix timestamps to * ISO 8601 datetime strings (UTC). * 4. Fields "id", "invoiceId", "counterEdrpou", and "counterIban" are omitted * from the returned results. */ const parsed = GetStatementArgsSchema.parse(args); const { account_id, from_timestamp, to_timestamp } = parsed; const finalToTimestamp = to_timestamp || Math.floor(Date.now() / 1000); try { const response = await fetch( `https://api.monobank.ua/personal/statement/${account_id}/${from_timestamp}/${finalToTimestamp}`, { headers: { "X-Token": process.env.MONOBANK_API_TOKEN || "X_TOKEN_PLACEHOLDER", }, } ); if (!response.ok) { const errorText = await response.text(); throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`); } const data: StatementItem[] = await response.json() as StatementItem[]; const processedItems: ProcessedStatementItem[] = data.map((item) => { const time = new Date(item.time * 1000).toISOString(); const processedItem: ProcessedStatementItem = { time, description: item.description, mcc: item.mcc, originalMcc: item.originalMcc, hold: item.hold, amount: item.amount / 100, operationAmount: item.operationAmount / 100, currencyCode: item.currencyCode, commissionRate: item.commissionRate / 100, cashbackAmount: item.cashbackAmount / 100, balance: item.balance / 100, comment: item.comment, receiptId: item.receiptId, counterName: item.counterName, }; return processedItem; }); return { content: [ { type: "text", text: JSON.stringify(processedItems, null, 2), }, ], }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to connect to Monobank API: ${error.message}`); } throw new Error(`Failed to connect to Monobank API: ${String(error)}`); } }
- src/index.ts:83-87 (schema)Zod schema defining the input parameters for the get_statement tool, used for validation in the handler.const GetStatementArgsSchema = z.object({ account_id: z.string().describe("Account identifier from the list of accounts, or '0' for default"), from_timestamp: z.number().describe("Start of the statement period (Unix timestamp)"), to_timestamp: z.number().describe("End of the statement period (Unix timestamp)"), });
- src/index.ts:227-248 (registration)Registration of the 'get_statement' tool in the ListTools response, providing name, description, and input schema definition.{ name: "get_statement", description: "Get account statement for a given period. Rate limit: 1 request per 60 seconds. Max period: 31 days + 1 hour. Rules: 1. Fetch from default account (account_id = '0') unless another account is specified. 2. Amounts are converted from the smallest currency unit (e.g., kopiyka, cent) to the main unit and returned as decimals. 3. Transaction timestamps ('time') are converted from Unix timestamps to ISO 8601 datetime strings (UTC). 4. Fields 'id', 'invoiceId', 'counterEdrpou', and 'counterIban' are omitted from the returned results.", inputSchema: { type: "object", properties: { account_id: { type: "string", description: "Account identifier from the list of accounts, or '0' for default", }, from_timestamp: { type: "number", description: "Start of the statement period (Unix timestamp)", }, to_timestamp: { type: "number", description: "End of the statement period (Unix timestamp)", }, }, required: ["account_id", "from_timestamp", "to_timestamp"], }, },
- src/index.ts:256-257 (handler)Dispatch logic in the CallToolRequest handler that routes calls to the 'get_statement' tool to its implementation function.case "get_statement": return await getStatement(request.params.arguments);