quantix-mcp 0.3.9 → 0.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quantix-mcp",
3
- "version": "0.3.9",
3
+ "version": "0.4.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "quantix-mcp": "./dist/index.js"
package/src/index.ts CHANGED
@@ -13,15 +13,24 @@ import { registerSummaryTools } from './tools/summary.js';
13
13
  import { registerAccountTools } from './tools/accounts.js';
14
14
  import { registerSettingsTools } from './tools/settings.js';
15
15
  import { registerTransferTools } from './tools/transfers.js';
16
+ import { registerDataTools } from './tools/data.js';
17
+ import { registerSubscriptionTools } from './tools/subscriptions.js';
18
+ import { readFileSync } from 'fs';
19
+ import { fileURLToPath } from 'url';
20
+ import { dirname, join } from 'path';
21
+
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
24
+ const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
16
25
 
17
26
  export function getServer() {
18
27
  const mcpServer = new McpServer({
19
28
  name: 'quantix_mcp_server',
20
- version: '0.3.6',
29
+ version: pkg.version,
21
30
  description: 'MCP server for Quantix personal finance management',
22
31
  });
23
32
 
24
- console.log('Quantix MCP server started');
33
+ console.error('Quantix MCP server started');
25
34
 
26
35
  // Register Tools here
27
36
  registerCategoryTools(mcpServer);
@@ -32,6 +41,8 @@ export function getServer() {
32
41
  registerSettingsTools(mcpServer);
33
42
 
34
43
  registerTransferTools(mcpServer);
44
+ registerDataTools(mcpServer);
45
+ registerSubscriptionTools(mcpServer);
35
46
 
36
47
  return mcpServer;
37
48
  }
@@ -119,22 +119,4 @@ export function registerAccountTools(server: McpServer) {
119
119
  }
120
120
  );
121
121
 
122
- server.registerTool(
123
- 'get_account_transactions',
124
- {
125
- title: 'Get Account Transactions',
126
- description: 'Get all transactions linked to an account',
127
- inputSchema: z.object({ id: z.string() })
128
- },
129
- async ({ id }) => {
130
- try {
131
- const transactions = await apiClient.get(`/accounts/${id}/transactions`);
132
- return {
133
- content: [{ type: 'text', text: `Account transactions: ${JSON.stringify(transactions, null, 2)}` }]
134
- };
135
- } catch (error) {
136
- return handleToolError(error);
137
- }
138
- }
139
- );
140
122
  }
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
- import { CreateCreditCardInput, UpdateCreditCardInput, PayStatementInput, ReopenStatementInput } from '../types/schemas.js';
3
+ import { CreateCreditCardInput, UpdateCreditCardInput, PayStatementInput, ReopenStatementInput, CreateAnticipationInput } from '../types/schemas.js';
4
4
  import { apiClient } from '../services/apiClient.js';
5
5
  import { handleToolError } from '../utils/toolHelpers.js';
6
6
 
@@ -181,4 +181,23 @@ export function registerCreditCardTools(server: McpServer) {
181
181
  }
182
182
  }
183
183
  );
184
+
185
+ server.registerTool(
186
+ 'create_anticipation',
187
+ {
188
+ title: 'Create Credit Card Anticipation',
189
+ description: 'Create a credit card anticipation (advance payment toward a statement). Creates a linked pair: INCOME on the credit card side and EXPENSE on the account side.',
190
+ inputSchema: CreateAnticipationInput
191
+ },
192
+ async ({ cardId, ...body }) => {
193
+ try {
194
+ const result = await apiClient.post(`/credit-cards/${cardId}/anticipations`, body);
195
+ return {
196
+ content: [{ type: 'text', text: `Anticipation created: ${JSON.stringify(result, null, 2)}` }]
197
+ };
198
+ } catch (error) {
199
+ return handleToolError(error);
200
+ }
201
+ }
202
+ );
184
203
  }
@@ -0,0 +1,159 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { CreateSubscriptionInput, UpdateSubscriptionInput } from '../types/schemas.js';
4
+ import { apiClient } from '../services/apiClient.js';
5
+ import { handleToolError } from '../utils/toolHelpers.js';
6
+
7
+ export function registerSubscriptionTools(server: McpServer) {
8
+ server.registerTool(
9
+ 'create_subscription',
10
+ {
11
+ title: 'Create Subscription',
12
+ description: 'Create a new subscription (recurring payment on a credit card)',
13
+ inputSchema: CreateSubscriptionInput
14
+ },
15
+ async (args) => {
16
+ try {
17
+ const subscription = await apiClient.post('/subscriptions', args);
18
+ return {
19
+ content: [{ type: 'text', text: `Subscription created: ${JSON.stringify(subscription, null, 2)}` }]
20
+ };
21
+ } catch (error) {
22
+ return handleToolError(error);
23
+ }
24
+ }
25
+ );
26
+
27
+ server.registerTool(
28
+ 'get_subscriptions',
29
+ {
30
+ title: 'Get Subscriptions',
31
+ description: 'List all subscriptions',
32
+ inputSchema: z.object({})
33
+ },
34
+ async () => {
35
+ try {
36
+ const subscriptions = await apiClient.get('/subscriptions');
37
+ return {
38
+ content: [{ type: 'text', text: `Subscriptions: ${JSON.stringify(subscriptions, null, 2)}` }]
39
+ };
40
+ } catch (error) {
41
+ return handleToolError(error);
42
+ }
43
+ }
44
+ );
45
+
46
+ server.registerTool(
47
+ 'get_active_subscriptions',
48
+ {
49
+ title: 'Get Active Subscriptions',
50
+ description: 'List all active subscriptions',
51
+ inputSchema: z.object({})
52
+ },
53
+ async () => {
54
+ try {
55
+ const subscriptions = await apiClient.get('/subscriptions/active');
56
+ return {
57
+ content: [{ type: 'text', text: `Active subscriptions: ${JSON.stringify(subscriptions, null, 2)}` }]
58
+ };
59
+ } catch (error) {
60
+ return handleToolError(error);
61
+ }
62
+ }
63
+ );
64
+
65
+ server.registerTool(
66
+ 'get_subscription',
67
+ {
68
+ title: 'Get Subscription',
69
+ description: 'Get a subscription by ID',
70
+ inputSchema: z.object({ id: z.string() })
71
+ },
72
+ async ({ id }) => {
73
+ try {
74
+ const subscription = await apiClient.get(`/subscriptions/${id}`);
75
+ return {
76
+ content: [{ type: 'text', text: `Subscription: ${JSON.stringify(subscription, null, 2)}` }]
77
+ };
78
+ } catch (error) {
79
+ return handleToolError(error);
80
+ }
81
+ }
82
+ );
83
+
84
+ server.registerTool(
85
+ 'update_subscription',
86
+ {
87
+ title: 'Update Subscription',
88
+ description: 'Update a subscription',
89
+ inputSchema: UpdateSubscriptionInput
90
+ },
91
+ async ({ id, ...data }) => {
92
+ try {
93
+ const subscription = await apiClient.patch(`/subscriptions/${id}`, data);
94
+ return {
95
+ content: [{ type: 'text', text: `Subscription updated: ${JSON.stringify(subscription, null, 2)}` }]
96
+ };
97
+ } catch (error) {
98
+ return handleToolError(error);
99
+ }
100
+ }
101
+ );
102
+
103
+ server.registerTool(
104
+ 'deactivate_subscription',
105
+ {
106
+ title: 'Deactivate Subscription',
107
+ description: 'Deactivate a subscription (soft delete)',
108
+ inputSchema: z.object({ id: z.string() })
109
+ },
110
+ async ({ id }) => {
111
+ try {
112
+ const result = await apiClient.delete(`/subscriptions/${id}`);
113
+ return {
114
+ content: [{ type: 'text', text: `Subscription deactivated: ${JSON.stringify(result, null, 2)}` }]
115
+ };
116
+ } catch (error) {
117
+ return handleToolError(error);
118
+ }
119
+ }
120
+ );
121
+
122
+ server.registerTool(
123
+ 'delete_subscription_permanent',
124
+ {
125
+ title: 'Delete Subscription Permanently',
126
+ description: 'Permanently delete a subscription',
127
+ inputSchema: z.object({ id: z.string() })
128
+ },
129
+ async ({ id }) => {
130
+ try {
131
+ const result = await apiClient.delete(`/subscriptions/${id}/permanent`);
132
+ return {
133
+ content: [{ type: 'text', text: `Subscription permanently deleted: ${JSON.stringify(result, null, 2)}` }]
134
+ };
135
+ } catch (error) {
136
+ return handleToolError(error);
137
+ }
138
+ }
139
+ );
140
+
141
+ server.registerTool(
142
+ 'reactivate_subscription',
143
+ {
144
+ title: 'Reactivate Subscription',
145
+ description: 'Reactivate a deactivated subscription',
146
+ inputSchema: z.object({ id: z.string() })
147
+ },
148
+ async ({ id }) => {
149
+ try {
150
+ const subscription = await apiClient.patch(`/subscriptions/${id}/reactivate`, {});
151
+ return {
152
+ content: [{ type: 'text', text: `Subscription reactivated: ${JSON.stringify(subscription, null, 2)}` }]
153
+ };
154
+ } catch (error) {
155
+ return handleToolError(error);
156
+ }
157
+ }
158
+ );
159
+ }
@@ -102,10 +102,9 @@ export function registerTransactionTools(server: McpServer) {
102
102
  },
103
103
  async ({ id }) => {
104
104
  try {
105
- // PATCH /transactions/{id}/pay
106
- await apiClient.patch(`/transactions/${id}/pay`);
105
+ const transaction = await apiClient.patch(`/transactions/${id}/pay`);
107
106
  return {
108
- content: [{ type: 'text', text: `Transaction ${id} marked as paid.` }]
107
+ content: [{ type: 'text', text: `Transaction marked as paid: ${JSON.stringify(transaction, null, 2)}` }]
109
108
  };
110
109
  } catch (error) {
111
110
  return handleToolError(error);
@@ -122,9 +121,9 @@ export function registerTransactionTools(server: McpServer) {
122
121
  },
123
122
  async ({ id }) => {
124
123
  try {
125
- await apiClient.patch(`/transactions/${id}/unpay`);
124
+ const transaction = await apiClient.patch(`/transactions/${id}/unpay`);
126
125
  return {
127
- content: [{ type: 'text', text: `Transaction ${id} marked as unpaid.` }]
126
+ content: [{ type: 'text', text: `Transaction marked as unpaid: ${JSON.stringify(transaction, null, 2)}` }]
128
127
  };
129
128
  } catch (error) {
130
129
  return handleToolError(error);
@@ -184,7 +184,10 @@ export const UpdateTransactionInput = z.object({
184
184
  paymentMethod: z.enum(["CASH", "PIX", "DEBIT", "CREDIT"]).optional(),
185
185
  creditCardId: z.string().optional(),
186
186
  accountId: z.string().optional(),
187
+ installments: z.number().int().min(1).optional(),
187
188
  targetDueMonth: z.string().regex(/^\d{4}-\d{2}$/).optional(),
189
+ isPaid: z.boolean().optional(),
190
+ purchaseDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).describe("Actual purchase date (credit card only), YYYY-MM-DD").optional(),
188
191
  recurrence: z.object({
189
192
  frequency: z.enum(["MONTHLY", "WEEKLY", "YEARLY"]).optional(),
190
193
  interval: z.number().int().min(1).optional(),
@@ -202,7 +205,8 @@ export const CreateAccountInput = z.object({
202
205
  export const UpdateAccountInput = z.object({
203
206
  id: z.string(),
204
207
  name: z.string().optional(),
205
- type: z.enum(["BANK_ACCOUNT", "WALLET", "SAVINGS_ACCOUNT", "INVESTMENT_ACCOUNT", "OTHER"]).optional()
208
+ type: z.enum(["BANK_ACCOUNT", "WALLET", "SAVINGS_ACCOUNT", "INVESTMENT_ACCOUNT", "OTHER"]).optional(),
209
+ initialBalance: z.number().optional()
206
210
  });
207
211
 
208
212
  export const GetTransactionsInput = z.object({
@@ -245,6 +249,16 @@ export const UpdateSettingsInput = z.object({
245
249
  currency: z.enum(["BRL", "USD", "EUR", "GBP", "JPY", "CAD", "AUD", "CHF"]).optional()
246
250
  });
247
251
 
252
+ export const CreateAnticipationInput = z.object({
253
+ cardId: z.string().describe('Credit card ID'),
254
+ name: z.string().describe('Name/description of the anticipation'),
255
+ amount: z.number().min(0.01).describe('Amount to anticipate'),
256
+ purchaseDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).describe('Date the money leaves the account (YYYY-MM-DD)'),
257
+ targetDueMonth: z.string().regex(/^\d{4}-\d{2}$/).describe('Target statement due month (YYYY-MM)'),
258
+ accountId: z.string().describe('Account ID from which money will be debited'),
259
+ categoryId: z.string().optional().describe('Category ID for both transactions')
260
+ });
261
+
248
262
  export const ImportDataInput = z.object({
249
263
  mode: z.enum(["reset", "increment"]).describe("reset: clears all data before import; increment: adds new records, skipping existing IDs"),
250
264
  version: z.string().describe('Export format version, must be "1.0"'),
@@ -258,3 +272,33 @@ export const ImportDataInput = z.object({
258
272
  transactions: z.array(z.any()).optional()
259
273
  })
260
274
  });
275
+
276
+ export const SubscriptionSchema = z.object({
277
+ id: z.string(),
278
+ name: z.string(),
279
+ amount: z.number().min(0.01),
280
+ billingDay: z.number().int().min(1).max(31),
281
+ creditCardId: z.string(),
282
+ categoryId: z.string().optional(),
283
+ active: z.boolean(),
284
+ createdAt: z.string().datetime().optional(),
285
+ updatedAt: z.string().datetime().optional()
286
+ });
287
+
288
+ export const CreateSubscriptionInput = z.object({
289
+ name: z.string().describe("Name of the subscription (e.g., Netflix, Spotify)"),
290
+ amount: z.number().min(0.01).describe("Monthly amount charged"),
291
+ billingDay: z.number().int().min(1).max(31).describe("Day of the month when the subscription is charged (1-31)"),
292
+ creditCardId: z.string().describe("ID of the credit card used for this subscription"),
293
+ categoryId: z.string().describe("ID of the expense category").optional()
294
+ });
295
+
296
+ export const UpdateSubscriptionInput = z.object({
297
+ id: z.string(),
298
+ name: z.string().optional(),
299
+ amount: z.number().min(0.01).optional(),
300
+ billingDay: z.number().int().min(1).max(31).optional(),
301
+ creditCardId: z.string().optional(),
302
+ categoryId: z.string().optional(),
303
+ active: z.boolean().optional()
304
+ });
@@ -0,0 +1,173 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { registerSubscriptionTools } from '../../src/tools/subscriptions.js';
3
+ import { apiClient } from '../../src/services/apiClient.js';
4
+ import { ApiClientError } from '../../src/services/apiClient.js';
5
+
6
+ vi.mock('../../src/services/apiClient.js', () => ({
7
+ apiClient: {
8
+ get: vi.fn(),
9
+ post: vi.fn(),
10
+ patch: vi.fn(),
11
+ delete: vi.fn(),
12
+ },
13
+ ApiClientError: class ApiClientError extends Error {
14
+ status: number;
15
+ statusText: string;
16
+ constructor(message: string, status: number, statusText: string) {
17
+ super(message);
18
+ this.name = 'ApiClientError';
19
+ this.status = status;
20
+ this.statusText = statusText;
21
+ }
22
+ }
23
+ }));
24
+
25
+ describe('Subscription Tools', () => {
26
+ let mockServer: any;
27
+ let registeredTools: Record<string, Function> = {};
28
+
29
+ beforeEach(() => {
30
+ registeredTools = {};
31
+ mockServer = {
32
+ registerTool: vi.fn((name, def, handler) => {
33
+ registeredTools[name] = handler;
34
+ })
35
+ };
36
+ vi.clearAllMocks();
37
+ });
38
+
39
+ it('should register all subscription tools', () => {
40
+ registerSubscriptionTools(mockServer);
41
+ expect(mockServer.registerTool).toHaveBeenCalledTimes(8);
42
+ expect(registeredTools['create_subscription']).toBeDefined();
43
+ expect(registeredTools['get_subscriptions']).toBeDefined();
44
+ expect(registeredTools['get_active_subscriptions']).toBeDefined();
45
+ expect(registeredTools['get_subscription']).toBeDefined();
46
+ expect(registeredTools['update_subscription']).toBeDefined();
47
+ expect(registeredTools['deactivate_subscription']).toBeDefined();
48
+ expect(registeredTools['delete_subscription_permanent']).toBeDefined();
49
+ expect(registeredTools['reactivate_subscription']).toBeDefined();
50
+ });
51
+
52
+ describe('create_subscription', () => {
53
+ it('should call api.post with correct data', async () => {
54
+ registerSubscriptionTools(mockServer);
55
+ const handler = registeredTools['create_subscription'];
56
+
57
+ (apiClient.post as any).mockResolvedValue({ id: 'sub_1', name: 'Netflix' });
58
+
59
+ const result = await handler({ name: 'Netflix', amount: 55.9, billingDay: 15, creditCardId: 'cc_1' });
60
+
61
+ expect(apiClient.post).toHaveBeenCalledWith('/subscriptions', { name: 'Netflix', amount: 55.9, billingDay: 15, creditCardId: 'cc_1' });
62
+ expect(result.content[0].text).toContain('Subscription created');
63
+ });
64
+
65
+ it('should return API error on failure', async () => {
66
+ registerSubscriptionTools(mockServer);
67
+ const handler = registeredTools['create_subscription'];
68
+ (apiClient.post as any).mockRejectedValue(new ApiClientError('fail', 400, 'Bad Request'));
69
+
70
+ const result = await handler({ name: 'Netflix', amount: 55.9, billingDay: 15, creditCardId: 'cc_1' });
71
+
72
+ expect(result.content[0].text).toMatch(/^API error 400/);
73
+ });
74
+ });
75
+
76
+ describe('get_subscriptions', () => {
77
+ it('should call api.get', async () => {
78
+ registerSubscriptionTools(mockServer);
79
+ const handler = registeredTools['get_subscriptions'];
80
+
81
+ (apiClient.get as any).mockResolvedValue([{ id: 'sub_1', name: 'Netflix' }]);
82
+
83
+ const result = await handler({});
84
+
85
+ expect(apiClient.get).toHaveBeenCalledWith('/subscriptions');
86
+ expect(result.content[0].text).toContain('Netflix');
87
+ });
88
+ });
89
+
90
+ describe('get_active_subscriptions', () => {
91
+ it('should call api.get with correct endpoint', async () => {
92
+ registerSubscriptionTools(mockServer);
93
+ const handler = registeredTools['get_active_subscriptions'];
94
+
95
+ (apiClient.get as any).mockResolvedValue([{ id: 'sub_1', name: 'Netflix', active: true }]);
96
+
97
+ const result = await handler({});
98
+
99
+ expect(apiClient.get).toHaveBeenCalledWith('/subscriptions/active');
100
+ expect(result.content[0].text).toContain('Active subscriptions');
101
+ });
102
+ });
103
+
104
+ describe('get_subscription', () => {
105
+ it('should call api.get with correct id', async () => {
106
+ registerSubscriptionTools(mockServer);
107
+ const handler = registeredTools['get_subscription'];
108
+
109
+ (apiClient.get as any).mockResolvedValue({ id: 'sub_1', name: 'Netflix' });
110
+
111
+ const result = await handler({ id: 'sub_1' });
112
+
113
+ expect(apiClient.get).toHaveBeenCalledWith('/subscriptions/sub_1');
114
+ expect(result.content[0].text).toContain('Netflix');
115
+ });
116
+ });
117
+
118
+ describe('update_subscription', () => {
119
+ it('should call api.patch with correct data', async () => {
120
+ registerSubscriptionTools(mockServer);
121
+ const handler = registeredTools['update_subscription'];
122
+
123
+ (apiClient.patch as any).mockResolvedValue({ id: 'sub_1', name: 'Netflix Premium' });
124
+
125
+ const result = await handler({ id: 'sub_1', name: 'Netflix Premium' });
126
+
127
+ expect(apiClient.patch).toHaveBeenCalledWith('/subscriptions/sub_1', { name: 'Netflix Premium' });
128
+ expect(result.content[0].text).toContain('Subscription updated');
129
+ });
130
+ });
131
+
132
+ describe('deactivate_subscription', () => {
133
+ it('should call api.delete', async () => {
134
+ registerSubscriptionTools(mockServer);
135
+ const handler = registeredTools['deactivate_subscription'];
136
+
137
+ (apiClient.delete as any).mockResolvedValue({ id: 'sub_1', active: false });
138
+
139
+ const result = await handler({ id: 'sub_1' });
140
+
141
+ expect(apiClient.delete).toHaveBeenCalledWith('/subscriptions/sub_1');
142
+ expect(result.content[0].text).toContain('Subscription deactivated');
143
+ });
144
+ });
145
+
146
+ describe('delete_subscription_permanent', () => {
147
+ it('should call api.delete with permanent endpoint', async () => {
148
+ registerSubscriptionTools(mockServer);
149
+ const handler = registeredTools['delete_subscription_permanent'];
150
+
151
+ (apiClient.delete as any).mockResolvedValue({});
152
+
153
+ const result = await handler({ id: 'sub_1' });
154
+
155
+ expect(apiClient.delete).toHaveBeenCalledWith('/subscriptions/sub_1/permanent');
156
+ expect(result.content[0].text).toContain('permanently deleted');
157
+ });
158
+ });
159
+
160
+ describe('reactivate_subscription', () => {
161
+ it('should call api.patch with reactivate endpoint', async () => {
162
+ registerSubscriptionTools(mockServer);
163
+ const handler = registeredTools['reactivate_subscription'];
164
+
165
+ (apiClient.patch as any).mockResolvedValue({ id: 'sub_1', active: true });
166
+
167
+ const result = await handler({ id: 'sub_1' });
168
+
169
+ expect(apiClient.patch).toHaveBeenCalledWith('/subscriptions/sub_1/reactivate', {});
170
+ expect(result.content[0].text).toContain('Subscription reactivated');
171
+ });
172
+ });
173
+ });