Skip to main content
Glama
index.ts2.27 kB
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { zodToJsonSchema } from 'zod-to-json-schema'; import { MonthlySummaryInputParser } from './input-parser.js'; import { MonthlySummaryDataFetcher } from './data-fetcher.js'; import { MonthlySummaryCategoryClassifier } from './category-classifier.js'; import { MonthlySummaryTransactionAggregator } from './transaction-aggregator.js'; import { MonthlySummaryCalculator } from './summary-calculator.js'; import { MonthlySummaryReportDataBuilder } from './report-data-builder.js'; import { MonthlySummaryReportGenerator } from './report-generator.js'; import { successWithContent, errorFromCatch } from '../../utils/response.js'; import { getDateRangeForMonths } from '../../utils.js'; import { MonthlySummaryArgsSchema, type MonthlySummaryArgs, ToolInput } from '../../types.js'; export const schema = { name: 'monthly-summary', description: 'Get monthly income, expenses, and savings', inputSchema: zodToJsonSchema(MonthlySummaryArgsSchema) as ToolInput, }; export async function handler(args: MonthlySummaryArgs): Promise<CallToolResult> { try { const input = new MonthlySummaryInputParser().parse(args); const { start, end } = getDateRangeForMonths(input.months); const { accounts, categories, transactions } = await new MonthlySummaryDataFetcher().fetchAll( input.accountId, start, end ); const { incomeCategories, investmentSavingsCategories } = new MonthlySummaryCategoryClassifier().classify( categories ); const sortedMonths = new MonthlySummaryTransactionAggregator().aggregate( transactions, incomeCategories, investmentSavingsCategories ); const averages = new MonthlySummaryCalculator().calculateAverages(sortedMonths); const reportData = new MonthlySummaryReportDataBuilder().build( start, end, input.accountId, accounts, sortedMonths, averages ); const markdown = new MonthlySummaryReportGenerator().generate(reportData); return successWithContent({ type: 'text', text: markdown }); } catch (err) { // Use the standardized error response // errorFromCatch is imported from ../../utils/response.js return errorFromCatch(err); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/s-stefanov/actual-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server