@hasna/microservices 0.0.3 → 0.0.5
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/bin/index.js +63 -0
- package/bin/mcp.js +63 -0
- package/dist/index.js +63 -0
- package/microservices/microservice-ads/package.json +27 -0
- package/microservices/microservice-ads/src/cli/index.ts +605 -0
- package/microservices/microservice-ads/src/db/campaigns.ts +797 -0
- package/microservices/microservice-ads/src/db/database.ts +93 -0
- package/microservices/microservice-ads/src/db/migrations.ts +60 -0
- package/microservices/microservice-ads/src/index.ts +39 -0
- package/microservices/microservice-ads/src/mcp/index.ts +480 -0
- package/microservices/microservice-contracts/package.json +27 -0
- package/microservices/microservice-contracts/src/cli/index.ts +770 -0
- package/microservices/microservice-contracts/src/db/contracts.ts +925 -0
- package/microservices/microservice-contracts/src/db/database.ts +93 -0
- package/microservices/microservice-contracts/src/db/migrations.ts +141 -0
- package/microservices/microservice-contracts/src/index.ts +43 -0
- package/microservices/microservice-contracts/src/mcp/index.ts +617 -0
- package/microservices/microservice-domains/package.json +27 -0
- package/microservices/microservice-domains/src/cli/index.ts +691 -0
- package/microservices/microservice-domains/src/db/database.ts +93 -0
- package/microservices/microservice-domains/src/db/domains.ts +1164 -0
- package/microservices/microservice-domains/src/db/migrations.ts +60 -0
- package/microservices/microservice-domains/src/index.ts +65 -0
- package/microservices/microservice-domains/src/mcp/index.ts +536 -0
- package/microservices/microservice-hiring/package.json +27 -0
- package/microservices/microservice-hiring/src/cli/index.ts +741 -0
- package/microservices/microservice-hiring/src/db/database.ts +93 -0
- package/microservices/microservice-hiring/src/db/hiring.ts +1085 -0
- package/microservices/microservice-hiring/src/db/migrations.ts +89 -0
- package/microservices/microservice-hiring/src/index.ts +80 -0
- package/microservices/microservice-hiring/src/lib/scoring.ts +206 -0
- package/microservices/microservice-hiring/src/mcp/index.ts +709 -0
- package/microservices/microservice-payments/package.json +27 -0
- package/microservices/microservice-payments/src/cli/index.ts +609 -0
- package/microservices/microservice-payments/src/db/database.ts +93 -0
- package/microservices/microservice-payments/src/db/migrations.ts +81 -0
- package/microservices/microservice-payments/src/db/payments.ts +1204 -0
- package/microservices/microservice-payments/src/index.ts +51 -0
- package/microservices/microservice-payments/src/mcp/index.ts +683 -0
- package/microservices/microservice-payroll/package.json +27 -0
- package/microservices/microservice-payroll/src/cli/index.ts +643 -0
- package/microservices/microservice-payroll/src/db/database.ts +93 -0
- package/microservices/microservice-payroll/src/db/migrations.ts +95 -0
- package/microservices/microservice-payroll/src/db/payroll.ts +1377 -0
- package/microservices/microservice-payroll/src/index.ts +48 -0
- package/microservices/microservice-payroll/src/mcp/index.ts +666 -0
- package/microservices/microservice-shipping/package.json +27 -0
- package/microservices/microservice-shipping/src/cli/index.ts +606 -0
- package/microservices/microservice-shipping/src/db/database.ts +93 -0
- package/microservices/microservice-shipping/src/db/migrations.ts +69 -0
- package/microservices/microservice-shipping/src/db/shipping.ts +1093 -0
- package/microservices/microservice-shipping/src/index.ts +53 -0
- package/microservices/microservice-shipping/src/mcp/index.ts +533 -0
- package/microservices/microservice-social/package.json +27 -0
- package/microservices/microservice-social/src/cli/index.ts +689 -0
- package/microservices/microservice-social/src/db/database.ts +93 -0
- package/microservices/microservice-social/src/db/migrations.ts +88 -0
- package/microservices/microservice-social/src/db/social.ts +1046 -0
- package/microservices/microservice-social/src/index.ts +46 -0
- package/microservices/microservice-social/src/mcp/index.ts +655 -0
- package/microservices/microservice-subscriptions/package.json +27 -0
- package/microservices/microservice-subscriptions/src/cli/index.ts +715 -0
- package/microservices/microservice-subscriptions/src/db/database.ts +93 -0
- package/microservices/microservice-subscriptions/src/db/migrations.ts +125 -0
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +1256 -0
- package/microservices/microservice-subscriptions/src/index.ts +41 -0
- package/microservices/microservice-subscriptions/src/mcp/index.ts +631 -0
- package/package.json +1 -1
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import {
|
|
7
|
+
createPayment,
|
|
8
|
+
getPayment,
|
|
9
|
+
listPayments,
|
|
10
|
+
updatePayment,
|
|
11
|
+
deletePayment,
|
|
12
|
+
refundPayment,
|
|
13
|
+
searchPayments,
|
|
14
|
+
getRevenueReport,
|
|
15
|
+
getRevenueByCustomer,
|
|
16
|
+
reconcileWithInvoice,
|
|
17
|
+
getPaymentStats,
|
|
18
|
+
getBalanceByProvider,
|
|
19
|
+
listByProvider,
|
|
20
|
+
autoReconcile,
|
|
21
|
+
retryPayment,
|
|
22
|
+
listRetries,
|
|
23
|
+
getRetryStats,
|
|
24
|
+
convertCurrency,
|
|
25
|
+
feeAnalysis,
|
|
26
|
+
declineReport,
|
|
27
|
+
addDisputeEvidence,
|
|
28
|
+
splitPayment,
|
|
29
|
+
revenueForecast,
|
|
30
|
+
findReconciliationGaps,
|
|
31
|
+
} from "../db/payments.js";
|
|
32
|
+
import {
|
|
33
|
+
createDispute,
|
|
34
|
+
getDispute,
|
|
35
|
+
listDisputes,
|
|
36
|
+
respondDispute,
|
|
37
|
+
deleteDispute,
|
|
38
|
+
} from "../db/payments.js";
|
|
39
|
+
import {
|
|
40
|
+
createPayout,
|
|
41
|
+
getPayout,
|
|
42
|
+
listPayouts,
|
|
43
|
+
updatePayout,
|
|
44
|
+
deletePayout,
|
|
45
|
+
} from "../db/payments.js";
|
|
46
|
+
|
|
47
|
+
const server = new McpServer({
|
|
48
|
+
name: "microservice-payments",
|
|
49
|
+
version: "0.0.1",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// --- Payments ---
|
|
53
|
+
|
|
54
|
+
server.registerTool(
|
|
55
|
+
"create_payment",
|
|
56
|
+
{
|
|
57
|
+
title: "Create Payment",
|
|
58
|
+
description: "Create a new payment record.",
|
|
59
|
+
inputSchema: {
|
|
60
|
+
type: z.enum(["charge", "refund", "transfer", "payout"]),
|
|
61
|
+
amount: z.number(),
|
|
62
|
+
currency: z.string().optional(),
|
|
63
|
+
status: z.enum(["pending", "succeeded", "failed", "disputed", "refunded"]).optional(),
|
|
64
|
+
customer_name: z.string().optional(),
|
|
65
|
+
customer_email: z.string().optional(),
|
|
66
|
+
description: z.string().optional(),
|
|
67
|
+
provider: z.enum(["stripe", "square", "mercury", "manual"]).optional(),
|
|
68
|
+
provider_id: z.string().optional(),
|
|
69
|
+
invoice_id: z.string().optional(),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
async (params) => {
|
|
73
|
+
const payment = createPayment(params);
|
|
74
|
+
return { content: [{ type: "text", text: JSON.stringify(payment, null, 2) }] };
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
server.registerTool(
|
|
79
|
+
"get_payment",
|
|
80
|
+
{
|
|
81
|
+
title: "Get Payment",
|
|
82
|
+
description: "Get a payment by ID.",
|
|
83
|
+
inputSchema: { id: z.string() },
|
|
84
|
+
},
|
|
85
|
+
async ({ id }) => {
|
|
86
|
+
const payment = getPayment(id);
|
|
87
|
+
if (!payment) {
|
|
88
|
+
return { content: [{ type: "text", text: `Payment '${id}' not found.` }], isError: true };
|
|
89
|
+
}
|
|
90
|
+
return { content: [{ type: "text", text: JSON.stringify(payment, null, 2) }] };
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
server.registerTool(
|
|
95
|
+
"list_payments",
|
|
96
|
+
{
|
|
97
|
+
title: "List Payments",
|
|
98
|
+
description: "List payments with optional filters.",
|
|
99
|
+
inputSchema: {
|
|
100
|
+
status: z.enum(["pending", "succeeded", "failed", "disputed", "refunded"]).optional(),
|
|
101
|
+
type: z.enum(["charge", "refund", "transfer", "payout"]).optional(),
|
|
102
|
+
provider: z.enum(["stripe", "square", "mercury", "manual"]).optional(),
|
|
103
|
+
customer_email: z.string().optional(),
|
|
104
|
+
limit: z.number().optional(),
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
async (params) => {
|
|
108
|
+
const payments = listPayments(params);
|
|
109
|
+
return {
|
|
110
|
+
content: [
|
|
111
|
+
{ type: "text", text: JSON.stringify({ payments, count: payments.length }, null, 2) },
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
server.registerTool(
|
|
118
|
+
"update_payment",
|
|
119
|
+
{
|
|
120
|
+
title: "Update Payment",
|
|
121
|
+
description: "Update an existing payment.",
|
|
122
|
+
inputSchema: {
|
|
123
|
+
id: z.string(),
|
|
124
|
+
status: z.enum(["pending", "succeeded", "failed", "disputed", "refunded"]).optional(),
|
|
125
|
+
customer_name: z.string().optional(),
|
|
126
|
+
customer_email: z.string().optional(),
|
|
127
|
+
description: z.string().optional(),
|
|
128
|
+
provider: z.enum(["stripe", "square", "mercury", "manual"]).optional(),
|
|
129
|
+
provider_id: z.string().optional(),
|
|
130
|
+
invoice_id: z.string().optional(),
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
async ({ id, ...input }) => {
|
|
134
|
+
const payment = updatePayment(id, input);
|
|
135
|
+
if (!payment) {
|
|
136
|
+
return { content: [{ type: "text", text: `Payment '${id}' not found.` }], isError: true };
|
|
137
|
+
}
|
|
138
|
+
return { content: [{ type: "text", text: JSON.stringify(payment, null, 2) }] };
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
server.registerTool(
|
|
143
|
+
"delete_payment",
|
|
144
|
+
{
|
|
145
|
+
title: "Delete Payment",
|
|
146
|
+
description: "Delete a payment by ID.",
|
|
147
|
+
inputSchema: { id: z.string() },
|
|
148
|
+
},
|
|
149
|
+
async ({ id }) => {
|
|
150
|
+
const deleted = deletePayment(id);
|
|
151
|
+
return { content: [{ type: "text", text: JSON.stringify({ id, deleted }) }] };
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
server.registerTool(
|
|
156
|
+
"refund_payment",
|
|
157
|
+
{
|
|
158
|
+
title: "Refund Payment",
|
|
159
|
+
description: "Refund a succeeded payment. Creates a refund record and marks the original as refunded.",
|
|
160
|
+
inputSchema: {
|
|
161
|
+
id: z.string(),
|
|
162
|
+
amount: z.number().optional(),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
async ({ id, amount }) => {
|
|
166
|
+
const refund = refundPayment(id, amount);
|
|
167
|
+
if (!refund) {
|
|
168
|
+
return {
|
|
169
|
+
content: [{ type: "text", text: `Cannot refund payment '${id}' — not found or not succeeded.` }],
|
|
170
|
+
isError: true,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return { content: [{ type: "text", text: JSON.stringify(refund, null, 2) }] };
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
server.registerTool(
|
|
178
|
+
"search_payments",
|
|
179
|
+
{
|
|
180
|
+
title: "Search Payments",
|
|
181
|
+
description: "Search payments by customer name, email, description, provider ID, or invoice ID.",
|
|
182
|
+
inputSchema: { query: z.string() },
|
|
183
|
+
},
|
|
184
|
+
async ({ query }) => {
|
|
185
|
+
const results = searchPayments(query);
|
|
186
|
+
return {
|
|
187
|
+
content: [
|
|
188
|
+
{ type: "text", text: JSON.stringify({ results, count: results.length }, null, 2) },
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
server.registerTool(
|
|
195
|
+
"revenue_report",
|
|
196
|
+
{
|
|
197
|
+
title: "Revenue Report",
|
|
198
|
+
description: "Get revenue report for a date range.",
|
|
199
|
+
inputSchema: {
|
|
200
|
+
start_date: z.string(),
|
|
201
|
+
end_date: z.string(),
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
async ({ start_date, end_date }) => {
|
|
205
|
+
const report = getRevenueReport(start_date, end_date);
|
|
206
|
+
return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] };
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
server.registerTool(
|
|
211
|
+
"revenue_by_customer",
|
|
212
|
+
{
|
|
213
|
+
title: "Revenue by Customer",
|
|
214
|
+
description: "Get revenue breakdown by customer.",
|
|
215
|
+
inputSchema: {},
|
|
216
|
+
},
|
|
217
|
+
async () => {
|
|
218
|
+
const revenue = getRevenueByCustomer();
|
|
219
|
+
return { content: [{ type: "text", text: JSON.stringify(revenue, null, 2) }] };
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
server.registerTool(
|
|
224
|
+
"reconcile_payment",
|
|
225
|
+
{
|
|
226
|
+
title: "Reconcile Payment",
|
|
227
|
+
description: "Link a payment to an invoice ID for reconciliation.",
|
|
228
|
+
inputSchema: {
|
|
229
|
+
payment_id: z.string(),
|
|
230
|
+
invoice_id: z.string(),
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
async ({ payment_id, invoice_id }) => {
|
|
234
|
+
const payment = reconcileWithInvoice(payment_id, invoice_id);
|
|
235
|
+
if (!payment) {
|
|
236
|
+
return { content: [{ type: "text", text: `Payment '${payment_id}' not found.` }], isError: true };
|
|
237
|
+
}
|
|
238
|
+
return { content: [{ type: "text", text: JSON.stringify(payment, null, 2) }] };
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
server.registerTool(
|
|
243
|
+
"payment_stats",
|
|
244
|
+
{
|
|
245
|
+
title: "Payment Statistics",
|
|
246
|
+
description: "Get overall payment statistics.",
|
|
247
|
+
inputSchema: {},
|
|
248
|
+
},
|
|
249
|
+
async () => {
|
|
250
|
+
const stats = getPaymentStats();
|
|
251
|
+
return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
server.registerTool(
|
|
256
|
+
"balance_by_provider",
|
|
257
|
+
{
|
|
258
|
+
title: "Balance by Provider",
|
|
259
|
+
description: "Get balance breakdown by payment provider.",
|
|
260
|
+
inputSchema: {},
|
|
261
|
+
},
|
|
262
|
+
async () => {
|
|
263
|
+
const balances = getBalanceByProvider();
|
|
264
|
+
return { content: [{ type: "text", text: JSON.stringify(balances, null, 2) }] };
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
server.registerTool(
|
|
269
|
+
"list_by_provider",
|
|
270
|
+
{
|
|
271
|
+
title: "List by Provider",
|
|
272
|
+
description: "List all payments for a specific provider.",
|
|
273
|
+
inputSchema: {
|
|
274
|
+
provider: z.enum(["stripe", "square", "mercury", "manual"]),
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
async ({ provider }) => {
|
|
278
|
+
const payments = listByProvider(provider);
|
|
279
|
+
return {
|
|
280
|
+
content: [
|
|
281
|
+
{ type: "text", text: JSON.stringify({ payments, count: payments.length }, null, 2) },
|
|
282
|
+
],
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
// --- Disputes ---
|
|
288
|
+
|
|
289
|
+
server.registerTool(
|
|
290
|
+
"create_dispute",
|
|
291
|
+
{
|
|
292
|
+
title: "Create Dispute",
|
|
293
|
+
description: "Create a dispute for a payment.",
|
|
294
|
+
inputSchema: {
|
|
295
|
+
payment_id: z.string(),
|
|
296
|
+
reason: z.string().optional(),
|
|
297
|
+
amount: z.number().optional(),
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
async (params) => {
|
|
301
|
+
const dispute = createDispute(params);
|
|
302
|
+
return { content: [{ type: "text", text: JSON.stringify(dispute, null, 2) }] };
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
server.registerTool(
|
|
307
|
+
"get_dispute",
|
|
308
|
+
{
|
|
309
|
+
title: "Get Dispute",
|
|
310
|
+
description: "Get a dispute by ID.",
|
|
311
|
+
inputSchema: { id: z.string() },
|
|
312
|
+
},
|
|
313
|
+
async ({ id }) => {
|
|
314
|
+
const dispute = getDispute(id);
|
|
315
|
+
if (!dispute) {
|
|
316
|
+
return { content: [{ type: "text", text: `Dispute '${id}' not found.` }], isError: true };
|
|
317
|
+
}
|
|
318
|
+
return { content: [{ type: "text", text: JSON.stringify(dispute, null, 2) }] };
|
|
319
|
+
}
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
server.registerTool(
|
|
323
|
+
"list_disputes",
|
|
324
|
+
{
|
|
325
|
+
title: "List Disputes",
|
|
326
|
+
description: "List disputes with optional status filter.",
|
|
327
|
+
inputSchema: {
|
|
328
|
+
status: z.enum(["open", "under_review", "won", "lost"]).optional(),
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
async ({ status }) => {
|
|
332
|
+
const disputes = listDisputes(status);
|
|
333
|
+
return {
|
|
334
|
+
content: [
|
|
335
|
+
{ type: "text", text: JSON.stringify({ disputes, count: disputes.length }, null, 2) },
|
|
336
|
+
],
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
server.registerTool(
|
|
342
|
+
"respond_dispute",
|
|
343
|
+
{
|
|
344
|
+
title: "Respond to Dispute",
|
|
345
|
+
description: "Respond to a dispute — update status and optionally add evidence.",
|
|
346
|
+
inputSchema: {
|
|
347
|
+
id: z.string(),
|
|
348
|
+
status: z.enum(["open", "under_review", "won", "lost"]),
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
async ({ id, status }) => {
|
|
352
|
+
const dispute = respondDispute(id, { status });
|
|
353
|
+
if (!dispute) {
|
|
354
|
+
return { content: [{ type: "text", text: `Dispute '${id}' not found.` }], isError: true };
|
|
355
|
+
}
|
|
356
|
+
return { content: [{ type: "text", text: JSON.stringify(dispute, null, 2) }] };
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
server.registerTool(
|
|
361
|
+
"delete_dispute",
|
|
362
|
+
{
|
|
363
|
+
title: "Delete Dispute",
|
|
364
|
+
description: "Delete a dispute by ID.",
|
|
365
|
+
inputSchema: { id: z.string() },
|
|
366
|
+
},
|
|
367
|
+
async ({ id }) => {
|
|
368
|
+
const deleted = deleteDispute(id);
|
|
369
|
+
return { content: [{ type: "text", text: JSON.stringify({ id, deleted }) }] };
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
// --- Payouts ---
|
|
374
|
+
|
|
375
|
+
server.registerTool(
|
|
376
|
+
"create_payout",
|
|
377
|
+
{
|
|
378
|
+
title: "Create Payout",
|
|
379
|
+
description: "Initiate a new payout.",
|
|
380
|
+
inputSchema: {
|
|
381
|
+
amount: z.number(),
|
|
382
|
+
currency: z.string().optional(),
|
|
383
|
+
destination: z.string().optional(),
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
async (params) => {
|
|
387
|
+
const payout = createPayout(params);
|
|
388
|
+
return { content: [{ type: "text", text: JSON.stringify(payout, null, 2) }] };
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
server.registerTool(
|
|
393
|
+
"get_payout",
|
|
394
|
+
{
|
|
395
|
+
title: "Get Payout",
|
|
396
|
+
description: "Get a payout by ID.",
|
|
397
|
+
inputSchema: { id: z.string() },
|
|
398
|
+
},
|
|
399
|
+
async ({ id }) => {
|
|
400
|
+
const payout = getPayout(id);
|
|
401
|
+
if (!payout) {
|
|
402
|
+
return { content: [{ type: "text", text: `Payout '${id}' not found.` }], isError: true };
|
|
403
|
+
}
|
|
404
|
+
return { content: [{ type: "text", text: JSON.stringify(payout, null, 2) }] };
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
server.registerTool(
|
|
409
|
+
"list_payouts",
|
|
410
|
+
{
|
|
411
|
+
title: "List Payouts",
|
|
412
|
+
description: "List payouts with optional status filter.",
|
|
413
|
+
inputSchema: {
|
|
414
|
+
status: z.enum(["pending", "in_transit", "paid", "failed"]).optional(),
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
async ({ status }) => {
|
|
418
|
+
const payouts = listPayouts(status);
|
|
419
|
+
return {
|
|
420
|
+
content: [
|
|
421
|
+
{ type: "text", text: JSON.stringify({ payouts, count: payouts.length }, null, 2) },
|
|
422
|
+
],
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
server.registerTool(
|
|
428
|
+
"update_payout",
|
|
429
|
+
{
|
|
430
|
+
title: "Update Payout",
|
|
431
|
+
description: "Update a payout status.",
|
|
432
|
+
inputSchema: {
|
|
433
|
+
id: z.string(),
|
|
434
|
+
status: z.enum(["pending", "in_transit", "paid", "failed"]).optional(),
|
|
435
|
+
destination: z.string().optional(),
|
|
436
|
+
arrived_at: z.string().optional(),
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
async ({ id, ...input }) => {
|
|
440
|
+
const payout = updatePayout(id, input);
|
|
441
|
+
if (!payout) {
|
|
442
|
+
return { content: [{ type: "text", text: `Payout '${id}' not found.` }], isError: true };
|
|
443
|
+
}
|
|
444
|
+
return { content: [{ type: "text", text: JSON.stringify(payout, null, 2) }] };
|
|
445
|
+
}
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
server.registerTool(
|
|
449
|
+
"delete_payout",
|
|
450
|
+
{
|
|
451
|
+
title: "Delete Payout",
|
|
452
|
+
description: "Delete a payout by ID.",
|
|
453
|
+
inputSchema: { id: z.string() },
|
|
454
|
+
},
|
|
455
|
+
async ({ id }) => {
|
|
456
|
+
const deleted = deletePayout(id);
|
|
457
|
+
return { content: [{ type: "text", text: JSON.stringify({ id, deleted }) }] };
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
// --- Auto-Reconciliation ---
|
|
462
|
+
|
|
463
|
+
server.registerTool(
|
|
464
|
+
"auto_reconcile",
|
|
465
|
+
{
|
|
466
|
+
title: "Auto Reconcile",
|
|
467
|
+
description: "Auto-reconcile payments to invoices by matching amount, customer email, and date (+-3 days tolerance).",
|
|
468
|
+
inputSchema: {
|
|
469
|
+
date_from: z.string().optional(),
|
|
470
|
+
date_to: z.string().optional(),
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
async ({ date_from, date_to }) => {
|
|
474
|
+
const result = autoReconcile(date_from, date_to);
|
|
475
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
476
|
+
}
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
// --- Retry ---
|
|
480
|
+
|
|
481
|
+
server.registerTool(
|
|
482
|
+
"retry_payment",
|
|
483
|
+
{
|
|
484
|
+
title: "Retry Payment",
|
|
485
|
+
description: "Retry a failed payment. Creates a retry attempt record and re-processes the payment.",
|
|
486
|
+
inputSchema: { id: z.string() },
|
|
487
|
+
},
|
|
488
|
+
async ({ id }) => {
|
|
489
|
+
const attempt = retryPayment(id);
|
|
490
|
+
if (!attempt) {
|
|
491
|
+
return {
|
|
492
|
+
content: [{ type: "text", text: `Cannot retry payment '${id}' — not found or not failed.` }],
|
|
493
|
+
isError: true,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
return { content: [{ type: "text", text: JSON.stringify(attempt, null, 2) }] };
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
server.registerTool(
|
|
501
|
+
"list_retries",
|
|
502
|
+
{
|
|
503
|
+
title: "List Retries",
|
|
504
|
+
description: "List all retry attempts for a payment.",
|
|
505
|
+
inputSchema: { payment_id: z.string() },
|
|
506
|
+
},
|
|
507
|
+
async ({ payment_id }) => {
|
|
508
|
+
const retries = listRetries(payment_id);
|
|
509
|
+
return {
|
|
510
|
+
content: [
|
|
511
|
+
{ type: "text", text: JSON.stringify({ retries, count: retries.length }, null, 2) },
|
|
512
|
+
],
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
server.registerTool(
|
|
518
|
+
"retry_stats",
|
|
519
|
+
{
|
|
520
|
+
title: "Retry Statistics",
|
|
521
|
+
description: "Get overall retry attempt statistics.",
|
|
522
|
+
inputSchema: {},
|
|
523
|
+
},
|
|
524
|
+
async () => {
|
|
525
|
+
const stats = getRetryStats();
|
|
526
|
+
return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
// --- Currency Conversion ---
|
|
531
|
+
|
|
532
|
+
server.registerTool(
|
|
533
|
+
"convert_currency",
|
|
534
|
+
{
|
|
535
|
+
title: "Convert Currency",
|
|
536
|
+
description: "Convert an amount between currencies using built-in rates (USD/EUR/GBP/CAD/AUD).",
|
|
537
|
+
inputSchema: {
|
|
538
|
+
amount: z.number(),
|
|
539
|
+
from: z.string(),
|
|
540
|
+
to: z.string(),
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
async ({ amount, from, to }) => {
|
|
544
|
+
const result = convertCurrency(amount, from, to);
|
|
545
|
+
if (!result) {
|
|
546
|
+
return {
|
|
547
|
+
content: [{ type: "text", text: `Unsupported currency pair: ${from} -> ${to}` }],
|
|
548
|
+
isError: true,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
552
|
+
}
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
// --- Fee Analysis ---
|
|
556
|
+
|
|
557
|
+
server.registerTool(
|
|
558
|
+
"fee_analysis",
|
|
559
|
+
{
|
|
560
|
+
title: "Fee Analysis",
|
|
561
|
+
description: "Analyze processor fees per provider for a given month. Shows gross, fees, and net per provider.",
|
|
562
|
+
inputSchema: {
|
|
563
|
+
month: z.string().describe("Month in YYYY-MM format"),
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
async ({ month }) => {
|
|
567
|
+
const result = feeAnalysis(month);
|
|
568
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
// --- Decline Analytics ---
|
|
573
|
+
|
|
574
|
+
server.registerTool(
|
|
575
|
+
"decline_analysis",
|
|
576
|
+
{
|
|
577
|
+
title: "Decline Analysis",
|
|
578
|
+
description: "Get decline analytics — groups failed payments by description/reason.",
|
|
579
|
+
inputSchema: {
|
|
580
|
+
provider: z.enum(["stripe", "square", "mercury", "manual"]).optional(),
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
async ({ provider }) => {
|
|
584
|
+
const report = declineReport(provider);
|
|
585
|
+
return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] };
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
// --- Dispute Evidence ---
|
|
590
|
+
|
|
591
|
+
server.registerTool(
|
|
592
|
+
"add_dispute_evidence",
|
|
593
|
+
{
|
|
594
|
+
title: "Add Dispute Evidence",
|
|
595
|
+
description: "Add evidence to an existing dispute. Appends to the evidence items array.",
|
|
596
|
+
inputSchema: {
|
|
597
|
+
dispute_id: z.string(),
|
|
598
|
+
description: z.string(),
|
|
599
|
+
file_ref: z.string().optional(),
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
async ({ dispute_id, description, file_ref }) => {
|
|
603
|
+
const dispute = addDisputeEvidence(dispute_id, description, file_ref);
|
|
604
|
+
if (!dispute) {
|
|
605
|
+
return {
|
|
606
|
+
content: [{ type: "text", text: `Dispute '${dispute_id}' not found.` }],
|
|
607
|
+
isError: true,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
return { content: [{ type: "text", text: JSON.stringify(dispute, null, 2) }] };
|
|
611
|
+
}
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
// --- Payment Split ---
|
|
615
|
+
|
|
616
|
+
server.registerTool(
|
|
617
|
+
"split_payment",
|
|
618
|
+
{
|
|
619
|
+
title: "Split Payment",
|
|
620
|
+
description: "Record marketplace commission splits for a payment. Stores split percentages in payment metadata.",
|
|
621
|
+
inputSchema: {
|
|
622
|
+
payment_id: z.string(),
|
|
623
|
+
splits: z.record(z.number()).describe("Map of vendor name to percentage (e.g. {vendor1: 70, vendor2: 30})"),
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
async ({ payment_id, splits }) => {
|
|
627
|
+
const payment = splitPayment(payment_id, splits);
|
|
628
|
+
if (!payment) {
|
|
629
|
+
return {
|
|
630
|
+
content: [{ type: "text", text: `Payment '${payment_id}' not found.` }],
|
|
631
|
+
isError: true,
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
return { content: [{ type: "text", text: JSON.stringify(payment, null, 2) }] };
|
|
635
|
+
}
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
// --- Revenue Forecast ---
|
|
639
|
+
|
|
640
|
+
server.registerTool(
|
|
641
|
+
"revenue_forecast",
|
|
642
|
+
{
|
|
643
|
+
title: "Revenue Forecast",
|
|
644
|
+
description: "Project revenue for upcoming months based on last 3 months trend.",
|
|
645
|
+
inputSchema: {
|
|
646
|
+
months: z.number().describe("Number of months to forecast"),
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
async ({ months }) => {
|
|
650
|
+
const result = revenueForecast(months);
|
|
651
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
652
|
+
}
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
// --- Reconciliation Gaps ---
|
|
656
|
+
|
|
657
|
+
server.registerTool(
|
|
658
|
+
"reconciliation_gaps",
|
|
659
|
+
{
|
|
660
|
+
title: "Reconciliation Gaps",
|
|
661
|
+
description: "Find payments without invoice_id and invoice IDs without a succeeded payment in a date range.",
|
|
662
|
+
inputSchema: {
|
|
663
|
+
date_from: z.string(),
|
|
664
|
+
date_to: z.string(),
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
async ({ date_from, date_to }) => {
|
|
668
|
+
const gaps = findReconciliationGaps(date_from, date_to);
|
|
669
|
+
return { content: [{ type: "text", text: JSON.stringify(gaps, null, 2) }] };
|
|
670
|
+
}
|
|
671
|
+
);
|
|
672
|
+
|
|
673
|
+
// --- Start ---
|
|
674
|
+
async function main() {
|
|
675
|
+
const transport = new StdioServerTransport();
|
|
676
|
+
await server.connect(transport);
|
|
677
|
+
console.error("microservice-payments MCP server running on stdio");
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
main().catch((error) => {
|
|
681
|
+
console.error("Fatal error:", error);
|
|
682
|
+
process.exit(1);
|
|
683
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hasna/microservice-payroll",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Payroll management microservice with SQLite — manage employees, pay periods, pay stubs, and payments",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"microservice-payroll": "./src/cli/index.ts",
|
|
8
|
+
"microservice-payroll-mcp": "./src/mcp/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "bun run ./src/cli/index.ts",
|
|
15
|
+
"test": "bun test"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
19
|
+
"commander": "^12.1.0",
|
|
20
|
+
"zod": "^3.24.0"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org",
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|