pocketsmith-mcp
Version:
MCP server for managing budgets via PocketSmith API
431 lines (430 loc) • 15.5 kB
TypeScript
/**
* @fileoverview PocketSmith API service integration
* This module provides a service wrapper around the PocketSmith TypeScript client
* for use within the MCP server environment.
*/
import { type RequestContext } from '../utils/index.js';
export declare class PocketSmithService {
private client;
private formatError;
constructor(apiKey?: string, accessToken?: string);
getCurrentUser(context: RequestContext): Promise<{
id?: number;
login?: string;
name?: string;
email?: string;
avatar_url?: string;
beta_user?: boolean;
time_zone?: string;
week_start_day?: number;
is_reviewing_transactions?: boolean;
base_currency_code?: string;
always_show_base_currency?: boolean;
using_multiple_currencies?: boolean;
available_accounts?: number;
available_budgets?: number;
forecast_last_updated_at?: string;
forecast_last_accessed_at?: string;
forecast_start_date?: string;
forecast_end_date?: string;
forecast_defer_recalculate?: boolean;
forecast_needs_recalculate?: boolean;
last_logged_in_at?: string;
last_activity_at?: string;
created_at?: string;
updated_at?: string;
}>;
getAccounts(userId: number, context: RequestContext): Promise<{
id?: number;
title?: string;
currency_code?: string;
type?: "bank" | "credits" | "cash" | "stocks" | "mortgage" | "loans" | "vehicle" | "property" | "insurance" | "other_asset" | "other_liability";
is_net_worth?: boolean;
primary_transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
primary_scenario?: import("pocketsmith-ts").components["schemas"]["Scenario"];
transaction_accounts?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"][];
scenarios?: import("pocketsmith-ts").components["schemas"]["Scenario"][];
created_at?: string;
updated_at?: string;
current_balance?: number;
current_balance_date?: string;
current_balance_in_base_currency?: number;
current_balance_exchange_rate?: number;
safe_balance?: number;
safe_balance_in_base_currency?: number;
}[]>;
getTransactions(userId: number, context: RequestContext, options?: {
startDate?: string;
endDate?: string;
search?: string;
type?: 'credit' | 'debit';
limit?: number;
}): Promise<{
cheque_number?: string;
type?: "debit" | "credit";
memo?: string;
payee?: string;
amount?: number;
amount_in_base_currency?: number;
date?: string;
is_transfer?: boolean;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
note?: string;
labels?: string[];
id?: number;
original_payee?: string;
upload_source?: string;
closing_balance?: number;
transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
status?: "pending" | "posted";
needs_review?: boolean;
created_at?: string;
updated_at?: string;
}[]>;
createTransaction(accountId: number, transaction: {
payee: string;
amount: number;
date: string;
category_id?: number;
note?: string;
}, context: RequestContext): Promise<{
cheque_number?: string;
type?: "debit" | "credit";
memo?: string;
payee?: string;
amount?: number;
amount_in_base_currency?: number;
date?: string;
is_transfer?: boolean;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
note?: string;
labels?: string[];
id?: number;
original_payee?: string;
upload_source?: string;
closing_balance?: number;
transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
status?: "pending" | "posted";
needs_review?: boolean;
created_at?: string;
updated_at?: string;
}>;
getTransaction(transactionId: number, context: RequestContext): Promise<{
cheque_number?: string;
type?: "debit" | "credit";
memo?: string;
payee?: string;
amount?: number;
amount_in_base_currency?: number;
date?: string;
is_transfer?: boolean;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
note?: string;
labels?: string[];
id?: number;
original_payee?: string;
upload_source?: string;
closing_balance?: number;
transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
status?: "pending" | "posted";
needs_review?: boolean;
created_at?: string;
updated_at?: string;
}>;
updateTransaction(transactionId: number, updates: {
payee?: string;
amount?: number;
date?: string;
category_id?: number;
note?: string;
}, context: RequestContext): Promise<{
cheque_number?: string;
type?: "debit" | "credit";
memo?: string;
payee?: string;
amount?: number;
amount_in_base_currency?: number;
date?: string;
is_transfer?: boolean;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
note?: string;
labels?: string[];
id?: number;
original_payee?: string;
upload_source?: string;
closing_balance?: number;
transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
status?: "pending" | "posted";
needs_review?: boolean;
created_at?: string;
updated_at?: string;
}>;
deleteTransaction(transactionId: number, context: RequestContext): Promise<Record<string, never>>;
createCategory(userId: number, category: {
title: string;
colour?: string;
parent_id?: number;
is_bill?: boolean;
is_transfer?: boolean;
}, context: RequestContext): Promise<{
id?: number;
title?: string;
colour?: string;
children?: import("pocketsmith-ts").components["schemas"]["Category"][];
parent_id?: number;
is_transfer?: boolean;
is_bill?: boolean;
roll_up?: boolean;
refund_behaviour?: "debits_are_deductions" | "credits_are_refunds" | null;
created_at?: string;
updated_at?: string;
}>;
updateCategory(categoryId: number, updates: {
title?: string;
colour?: string;
parent_id?: number;
is_bill?: boolean;
is_transfer?: boolean;
}, context: RequestContext): Promise<{
id?: number;
title?: string;
colour?: string;
children?: import("pocketsmith-ts").components["schemas"]["Category"][];
parent_id?: number;
is_transfer?: boolean;
is_bill?: boolean;
roll_up?: boolean;
refund_behaviour?: "debits_are_deductions" | "credits_are_refunds" | null;
created_at?: string;
updated_at?: string;
}>;
getCategories(userId: number, context: RequestContext): Promise<{
id?: number;
title?: string;
colour?: string;
children?: import("pocketsmith-ts").components["schemas"]["Category"][];
parent_id?: number;
is_transfer?: boolean;
is_bill?: boolean;
roll_up?: boolean;
refund_behaviour?: "debits_are_deductions" | "credits_are_refunds" | null;
created_at?: string;
updated_at?: string;
}[]>;
getBudgets(userId: number, context: RequestContext): Promise<{
category?: import("pocketsmith-ts").components["schemas"]["Category"];
is_transfer?: boolean;
expense?: import("pocketsmith-ts").components["schemas"]["BudgetAnalysis"];
income?: import("pocketsmith-ts").components["schemas"]["BudgetAnalysis"];
}[]>;
getBudgetSummary(userId: number, options: {
period: 'weeks' | 'months' | 'years';
interval: number;
startDate: string;
endDate: string;
}, context: RequestContext): Promise<{
category?: import("pocketsmith-ts").components["schemas"]["Category"];
is_transfer?: boolean;
expense?: import("pocketsmith-ts").components["schemas"]["BudgetAnalysis"];
income?: import("pocketsmith-ts").components["schemas"]["BudgetAnalysis"];
}[]>;
getAccountTransactions(accountId: number, context: RequestContext, options?: {
startDate?: string;
endDate?: string;
search?: string;
limit?: number;
}): Promise<{
cheque_number?: string;
type?: "debit" | "credit";
memo?: string;
payee?: string;
amount?: number;
amount_in_base_currency?: number;
date?: string;
is_transfer?: boolean;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
note?: string;
labels?: string[];
id?: number;
original_payee?: string;
upload_source?: string;
closing_balance?: number;
transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
status?: "pending" | "posted";
needs_review?: boolean;
created_at?: string;
updated_at?: string;
}[]>;
getCategoryTransactions(categoryIds: number | number[], context: RequestContext, options?: {
startDate?: string;
endDate?: string;
page?: number;
}): Promise<{
cheque_number?: string;
type?: "debit" | "credit";
memo?: string;
payee?: string;
amount?: number;
amount_in_base_currency?: number;
date?: string;
is_transfer?: boolean;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
note?: string;
labels?: string[];
id?: number;
original_payee?: string;
upload_source?: string;
closing_balance?: number;
transaction_account?: import("pocketsmith-ts").components["schemas"]["TransactionAccount"];
status?: "pending" | "posted";
needs_review?: boolean;
created_at?: string;
updated_at?: string;
}[]>;
getTransactionAttachments(transactionId: number, context: RequestContext): Promise<{
id?: number;
title?: string;
file_name?: string;
type?: string;
content_type?: string;
content_type_meta?: {
title?: string;
description?: string;
extension?: string;
};
original_url?: string;
variants?: {
large_url?: string;
thumb_url?: string;
};
created_at?: string;
updated_at?: string;
}[]>;
getUserAttachments(userId: number, context: RequestContext): Promise<{
id?: number;
title?: string;
file_name?: string;
type?: string;
content_type?: string;
content_type_meta?: {
title?: string;
description?: string;
extension?: string;
};
original_url?: string;
variants?: {
large_url?: string;
thumb_url?: string;
};
created_at?: string;
updated_at?: string;
}[]>;
createUserAttachment(userId: number, attachment: {
title?: string;
file_name?: string;
file_data?: string;
}, context: RequestContext): Promise<{
id?: number;
title?: string;
file_name?: string;
type?: string;
content_type?: string;
content_type_meta?: {
title?: string;
description?: string;
extension?: string;
};
original_url?: string;
variants?: {
large_url?: string;
thumb_url?: string;
};
created_at?: string;
updated_at?: string;
}>;
assignAttachmentToTransaction(transactionId: number, attachmentId: number, context: RequestContext): Promise<{
id?: number;
title?: string;
file_name?: string;
type?: string;
content_type?: string;
content_type_meta?: {
title?: string;
description?: string;
extension?: string;
};
original_url?: string;
variants?: {
large_url?: string;
thumb_url?: string;
};
created_at?: string;
updated_at?: string;
}>;
getRecurringEvents(userId: number, startDate: string, endDate: string, context: RequestContext): Promise<{
id?: string;
category?: import("pocketsmith-ts").components["schemas"]["Category"];
scenario?: import("pocketsmith-ts").components["schemas"]["Scenario"];
amount?: number;
amount_in_base_currency?: number;
currency_code?: string;
date?: string;
colour?: string;
note?: string;
repeat_type?: "once" | "daily" | "weekly" | "fortnightly" | "monthly" | "yearly" | "each weekday";
repeat_interval?: number;
series_id?: number;
series_start_id?: string;
infinite_series?: boolean;
}[]>;
getCategoryRules(userId: number, context: RequestContext): Promise<{
category?: import("pocketsmith-ts").components["schemas"]["Category"];
id?: number;
payee_matches?: string;
created_at?: string;
updated_at?: string;
}[]>;
createCategoryRule(categoryId: number, rule: {
payee_matches: string;
apply_to_uncategorised?: boolean;
apply_to_all?: boolean;
}, context: RequestContext): Promise<{
category?: import("pocketsmith-ts").components["schemas"]["Category"];
id?: number;
payee_matches?: string;
created_at?: string;
updated_at?: string;
}>;
getInstitutions(userId: number, context: RequestContext): Promise<{
currency_code?: string;
title?: string;
updated_at?: string;
created_at?: string;
id?: number;
}[]>;
getTransactionAccounts(userId: number, context: RequestContext): Promise<{
id?: number;
name?: string;
number?: string;
current_balance?: number;
current_balance_date?: string;
current_balance_in_base_currency?: number;
current_balance_exchange_rate?: number;
safe_balance?: number;
safe_balance_in_base_currency?: number;
starting_balance?: number;
starting_balance_date?: string;
created_at?: string;
updated_at?: string;
institution?: import("pocketsmith-ts").components["schemas"]["Institution"];
currency_code?: string;
type?: "bank" | "credits" | "cash" | "stocks" | "mortgage" | "loans" | "vehicle" | "property" | "insurance" | "other_asset" | "other_liability";
}[]>;
getCurrencies(context: RequestContext): Promise<{
id?: string;
name?: string;
minor_unit?: number;
separators?: import("pocketsmith-ts").components["schemas"]["CurrencySeparators"];
symbol?: string;
}[]>;
}