@moneygraph/mcp-server 1.0.0

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.
Files changed (138) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/README.md +224 -0
  3. package/bin/mcp-http.js +10 -0
  4. package/bin/mcp-server.js +8 -0
  5. package/dist/config.d.ts +28 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +53 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/http.d.ts +15 -0
  10. package/dist/http.d.ts.map +1 -0
  11. package/dist/http.js +104 -0
  12. package/dist/http.js.map +1 -0
  13. package/dist/index.d.ts +18 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +164 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/prompts/check-rates.d.ts +6 -0
  18. package/dist/prompts/check-rates.d.ts.map +1 -0
  19. package/dist/prompts/check-rates.js +29 -0
  20. package/dist/prompts/check-rates.js.map +1 -0
  21. package/dist/prompts/crypto-deposit.d.ts +6 -0
  22. package/dist/prompts/crypto-deposit.d.ts.map +1 -0
  23. package/dist/prompts/crypto-deposit.js +36 -0
  24. package/dist/prompts/crypto-deposit.js.map +1 -0
  25. package/dist/prompts/issue-card.d.ts +6 -0
  26. package/dist/prompts/issue-card.d.ts.map +1 -0
  27. package/dist/prompts/issue-card.js +33 -0
  28. package/dist/prompts/issue-card.js.map +1 -0
  29. package/dist/prompts/onboard-customer.d.ts +6 -0
  30. package/dist/prompts/onboard-customer.d.ts.map +1 -0
  31. package/dist/prompts/onboard-customer.js +31 -0
  32. package/dist/prompts/onboard-customer.js.map +1 -0
  33. package/dist/prompts/payout-status.d.ts +6 -0
  34. package/dist/prompts/payout-status.d.ts.map +1 -0
  35. package/dist/prompts/payout-status.js +29 -0
  36. package/dist/prompts/payout-status.js.map +1 -0
  37. package/dist/prompts/send-money.d.ts +6 -0
  38. package/dist/prompts/send-money.d.ts.map +1 -0
  39. package/dist/prompts/send-money.js +34 -0
  40. package/dist/prompts/send-money.js.map +1 -0
  41. package/dist/resources/corridors.d.ts +8 -0
  42. package/dist/resources/corridors.d.ts.map +1 -0
  43. package/dist/resources/corridors.js +137 -0
  44. package/dist/resources/corridors.js.map +1 -0
  45. package/dist/resources/status.d.ts +7 -0
  46. package/dist/resources/status.d.ts.map +1 -0
  47. package/dist/resources/status.js +32 -0
  48. package/dist/resources/status.js.map +1 -0
  49. package/dist/resources/wallets.d.ts +7 -0
  50. package/dist/resources/wallets.d.ts.map +1 -0
  51. package/dist/resources/wallets.js +37 -0
  52. package/dist/resources/wallets.js.map +1 -0
  53. package/dist/tools/cards.d.ts +10 -0
  54. package/dist/tools/cards.d.ts.map +1 -0
  55. package/dist/tools/cards.js +229 -0
  56. package/dist/tools/cards.js.map +1 -0
  57. package/dist/tools/crypto.d.ts +10 -0
  58. package/dist/tools/crypto.d.ts.map +1 -0
  59. package/dist/tools/crypto.js +265 -0
  60. package/dist/tools/crypto.js.map +1 -0
  61. package/dist/tools/currencies.d.ts +10 -0
  62. package/dist/tools/currencies.d.ts.map +1 -0
  63. package/dist/tools/currencies.js +84 -0
  64. package/dist/tools/currencies.js.map +1 -0
  65. package/dist/tools/customers.d.ts +7 -0
  66. package/dist/tools/customers.d.ts.map +1 -0
  67. package/dist/tools/customers.js +310 -0
  68. package/dist/tools/customers.js.map +1 -0
  69. package/dist/tools/directors.d.ts +7 -0
  70. package/dist/tools/directors.d.ts.map +1 -0
  71. package/dist/tools/directors.js +148 -0
  72. package/dist/tools/directors.js.map +1 -0
  73. package/dist/tools/fx.d.ts +10 -0
  74. package/dist/tools/fx.d.ts.map +1 -0
  75. package/dist/tools/fx.js +193 -0
  76. package/dist/tools/fx.js.map +1 -0
  77. package/dist/tools/ledger.d.ts +7 -0
  78. package/dist/tools/ledger.d.ts.map +1 -0
  79. package/dist/tools/ledger.js +101 -0
  80. package/dist/tools/ledger.js.map +1 -0
  81. package/dist/tools/payments.d.ts +7 -0
  82. package/dist/tools/payments.d.ts.map +1 -0
  83. package/dist/tools/payments.js +93 -0
  84. package/dist/tools/payments.js.map +1 -0
  85. package/dist/tools/payouts.d.ts +10 -0
  86. package/dist/tools/payouts.d.ts.map +1 -0
  87. package/dist/tools/payouts.js +352 -0
  88. package/dist/tools/payouts.js.map +1 -0
  89. package/dist/tools/recipients.d.ts +7 -0
  90. package/dist/tools/recipients.d.ts.map +1 -0
  91. package/dist/tools/recipients.js +150 -0
  92. package/dist/tools/recipients.js.map +1 -0
  93. package/dist/tools/recurring.d.ts +7 -0
  94. package/dist/tools/recurring.d.ts.map +1 -0
  95. package/dist/tools/recurring.js +94 -0
  96. package/dist/tools/recurring.js.map +1 -0
  97. package/dist/tools/reference.d.ts +7 -0
  98. package/dist/tools/reference.d.ts.map +1 -0
  99. package/dist/tools/reference.js +83 -0
  100. package/dist/tools/reference.js.map +1 -0
  101. package/dist/tools/transactions.d.ts +7 -0
  102. package/dist/tools/transactions.d.ts.map +1 -0
  103. package/dist/tools/transactions.js +88 -0
  104. package/dist/tools/transactions.js.map +1 -0
  105. package/dist/tools/wallets.d.ts +7 -0
  106. package/dist/tools/wallets.d.ts.map +1 -0
  107. package/dist/tools/wallets.js +129 -0
  108. package/dist/tools/wallets.js.map +1 -0
  109. package/package.json +67 -0
  110. package/railway.json +14 -0
  111. package/src/config.ts +73 -0
  112. package/src/http.ts +118 -0
  113. package/src/index.ts +184 -0
  114. package/src/prompts/check-rates.ts +36 -0
  115. package/src/prompts/crypto-deposit.ts +43 -0
  116. package/src/prompts/issue-card.ts +40 -0
  117. package/src/prompts/onboard-customer.ts +39 -0
  118. package/src/prompts/payout-status.ts +36 -0
  119. package/src/prompts/send-money.ts +41 -0
  120. package/src/resources/corridors.ts +190 -0
  121. package/src/resources/status.ts +44 -0
  122. package/src/resources/wallets.ts +48 -0
  123. package/src/tools/cards.ts +302 -0
  124. package/src/tools/crypto.ts +382 -0
  125. package/src/tools/currencies.ts +122 -0
  126. package/src/tools/customers.ts +458 -0
  127. package/src/tools/directors.ts +209 -0
  128. package/src/tools/fx.ts +253 -0
  129. package/src/tools/ledger.ts +133 -0
  130. package/src/tools/payments.ts +118 -0
  131. package/src/tools/payouts.ts +452 -0
  132. package/src/tools/recipients.ts +204 -0
  133. package/src/tools/recurring.ts +130 -0
  134. package/src/tools/reference.ts +122 -0
  135. package/src/tools/transactions.ts +140 -0
  136. package/src/tools/wallets.ts +183 -0
  137. package/test/smoke.test.mjs +196 -0
  138. package/tsconfig.json +21 -0
@@ -0,0 +1,253 @@
1
+ /**
2
+ * FX Tools — quotes, confirmations, exchange rates
3
+ *
4
+ * Maps to SDK: mg.fx.quote, mg.fx.confirm, mg.fx.rates
5
+ * Also includes mg.executeSmartPayout for auto-rail-selection payouts
6
+ */
7
+
8
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { z } from 'zod';
10
+ import type { ServerConfig } from '../config.js';
11
+ import { safeCall, nextSteps } from '../config.js';
12
+
13
+ export function registerFXTools(server: McpServer, config: ServerConfig) {
14
+ const { client } = config;
15
+
16
+ // ── get_fx_quote ────────────────────────────────────────────────
17
+ server.tool(
18
+ 'get_fx_quote',
19
+ 'Get a live FX quote for a currency pair. IMPORTANT: Quotes expire in 2 minutes — call confirm_fx_quote before expiry. Returns rate, fee, and destination amount.',
20
+ {
21
+ source_currency: z.string().describe('Source currency code (e.g. "USD", "GBP", "EUR", "CAD")'),
22
+ destination_currency: z.string().describe('Destination currency code (e.g. "NGN", "KES", "GHS")'),
23
+ source_amount: z.number().describe('Amount to send in source currency (whole units, e.g. 500 for $500)'),
24
+ },
25
+ async (args) => {
26
+ const result = await safeCall(
27
+ () => client.fx.quote({
28
+ source_currency: args.source_currency,
29
+ destination_currency: args.destination_currency,
30
+ source_amount: args.source_amount,
31
+ }),
32
+ 'get_fx_quote'
33
+ );
34
+
35
+ if (!result.success) {
36
+ return { content: [{ type: 'text' as const, text: `Error getting FX quote: ${result.error}` }], isError: true };
37
+ }
38
+
39
+ const q = result.data;
40
+ return {
41
+ content: [{
42
+ type: 'text' as const,
43
+ text: JSON.stringify({
44
+ quote_id: q.id,
45
+ source: `${q.source_amount} ${q.source_currency}`,
46
+ destination: `${q.destination_amount} ${q.destination_currency}`,
47
+ rate: q.rate,
48
+ fee: q.fee,
49
+ expires_at: q.expires_at,
50
+ _warning: 'Quote expires in 2 minutes. Call confirm_fx_quote to lock the rate.',
51
+ _next_steps: nextSteps(
52
+ `call confirm_fx_quote with quote_id="${q.id}" to lock the rate`,
53
+ 'then create a payout using the confirmed quote'
54
+ ),
55
+ }, null, 2),
56
+ }],
57
+ };
58
+ }
59
+ );
60
+
61
+ // ── confirm_fx_quote ────────────────────────────────────────────
62
+ server.tool(
63
+ 'confirm_fx_quote',
64
+ 'Confirm/lock an FX quote. Must be called within 2 minutes of getting the quote. Once confirmed, the rate is guaranteed for the payout.',
65
+ {
66
+ quote_id: z.string().describe('Quote ID from get_fx_quote'),
67
+ },
68
+ async (args) => {
69
+ const result = await safeCall(
70
+ () => client.fx.confirm(args.quote_id),
71
+ 'confirm_fx_quote'
72
+ );
73
+
74
+ if (!result.success) {
75
+ if (result.error.toLowerCase().includes('expire')) {
76
+ return {
77
+ content: [{ type: 'text' as const, text: 'Error: Quote has expired. Quotes are valid for 2 minutes. Get a new quote with get_fx_quote.' }],
78
+ isError: true,
79
+ };
80
+ }
81
+ return { content: [{ type: 'text' as const, text: `Error confirming quote: ${result.error}` }], isError: true };
82
+ }
83
+
84
+ return {
85
+ content: [{
86
+ type: 'text' as const,
87
+ text: JSON.stringify({
88
+ quote_id: args.quote_id,
89
+ confirmed: true,
90
+ note: 'Rate is locked. Proceed to create the payout using this quote.',
91
+ _next_steps: nextSteps(
92
+ `create a payout with quote_id="${args.quote_id}"`,
93
+ 'or use send_bank_payout / send_mobile_money_payout'
94
+ ),
95
+ }, null, 2),
96
+ }],
97
+ };
98
+ }
99
+ );
100
+
101
+ // ── get_exchange_rates ──────────────────────────────────────────
102
+ server.tool(
103
+ 'get_exchange_rates',
104
+ 'Get all current FX rates across all supported currency pairs. Returns a map of rate pairs (e.g. USD_NGN, GBP_KES).',
105
+ {},
106
+ async () => {
107
+ const result = await safeCall(() => client.fx.rates(), 'get_exchange_rates');
108
+ if (!result.success) {
109
+ return { content: [{ type: 'text' as const, text: `Error: ${result.error}` }], isError: true };
110
+ }
111
+
112
+ const rates = result.data as Record<string, number>;
113
+ return {
114
+ content: [{
115
+ type: 'text' as const,
116
+ text: JSON.stringify({
117
+ count: Object.keys(rates).length,
118
+ rates,
119
+ _next_steps: 'Use get_fx_quote for a specific pair to get a tradeable quote with fee details.',
120
+ }, null, 2),
121
+ }],
122
+ };
123
+ }
124
+ );
125
+
126
+ // ── smart_payout ────────────────────────────────────────────────
127
+ server.tool(
128
+ 'smart_payout',
129
+ 'HIGH-LEVEL intelligent payout — automatically selects the best payment rail (local bank, SWIFT, or mobile money) based on destination. Gets FX quote, confirms it, and creates the payout in one call. Preferred for one-call payments.',
130
+ {
131
+ customer_id: z.string().describe('Customer ID (must have APPROVED KYC)'),
132
+ from_currency: z.string().describe('Source currency (e.g. "USD", "GBP", "EUR")'),
133
+ to_currency: z.string().describe('Destination currency (e.g. "NGN", "KES", "GHS")'),
134
+ amount: z.number().describe('Amount in source currency (whole units, e.g. 500 for $500)'),
135
+ recipient_name: z.string().describe('Full recipient name'),
136
+ bank_code: z.string().optional().describe('Bank routing/SWIFT code (for bank transfers)'),
137
+ account_number: z.string().optional().describe('Bank account number (for bank transfers)'),
138
+ swift_code: z.string().optional().describe('SWIFT/BIC code (for international wire)'),
139
+ iban: z.string().optional().describe('IBAN (for SEPA/EU transfers)'),
140
+ mobile_network: z.string().optional().describe('Mobile network name (for mobile money: "MTN", "M-Pesa")'),
141
+ mobile_number: z.string().optional().describe('Mobile money phone number (for mobile money)'),
142
+ priority: z.enum(['speed', 'cost', 'balanced']).optional().describe('Optimization priority (default: "balanced")'),
143
+ narration: z.string().optional().describe('Payment narration/description'),
144
+ idempotency_key: z.string().optional().describe('Unique key to prevent duplicates'),
145
+ },
146
+ async (args) => {
147
+ const result = await safeCall(
148
+ () => client.executeSmartPayout({
149
+ customer_id: args.customer_id,
150
+ from_currency: args.from_currency,
151
+ to_currency: args.to_currency,
152
+ amount: args.amount,
153
+ recipient: {
154
+ name: args.recipient_name,
155
+ ...(args.bank_code && { bank_code: args.bank_code }),
156
+ ...(args.account_number && { account_number: args.account_number }),
157
+ ...(args.swift_code && { swift_code: args.swift_code }),
158
+ ...(args.iban && { iban: args.iban }),
159
+ ...(args.mobile_network && { mobile_network: args.mobile_network }),
160
+ ...(args.mobile_number && { mobile_number: args.mobile_number }),
161
+ },
162
+ priority: args.priority || 'balanced',
163
+ narration: args.narration,
164
+ idempotency_key: args.idempotency_key,
165
+ }),
166
+ 'smart_payout'
167
+ );
168
+
169
+ if (!result.success) {
170
+ if (result.error.toLowerCase().includes('kyc')) {
171
+ return {
172
+ content: [{ type: 'text' as const, text: `Error: Customer ${args.customer_id} KYC is not approved. Call submit_kyc first.` }],
173
+ isError: true,
174
+ };
175
+ }
176
+ return { content: [{ type: 'text' as const, text: `Error creating smart payout: ${result.error}` }], isError: true };
177
+ }
178
+
179
+ const r = result.data;
180
+ return {
181
+ content: [{
182
+ type: 'text' as const,
183
+ text: JSON.stringify({
184
+ transaction_id: r.payout.id,
185
+ status: r.payout.status,
186
+ rail_selected: r.rail,
187
+ amount_sent: `${r.quote.source_amount} ${r.quote.source_currency}`,
188
+ amount_received: `${r.quote.destination_amount} ${r.quote.destination_currency}`,
189
+ rate: r.quote.rate,
190
+ total_fee: r.total_fee,
191
+ recipient: r.payout.recipient,
192
+ created_at: r.payout.created_at,
193
+ _next_steps: `Track with get_transaction transaction_id="${r.payout.id}".`,
194
+ }, null, 2),
195
+ }],
196
+ };
197
+ }
198
+ );
199
+
200
+ // ── send_swift_payout ───────────────────────────────────────────
201
+ server.tool(
202
+ 'send_swift_payout',
203
+ 'Send an international wire transfer via SWIFT. Covers all non-sanctioned countries. Requires SWIFT/BIC code and IBAN or account number.',
204
+ {
205
+ customer_id: z.string().describe('Customer ID (must have APPROVED KYC)'),
206
+ quote_id: z.string().describe('Confirmed FX quote ID from confirm_fx_quote'),
207
+ recipient_name: z.string().describe('Full recipient name'),
208
+ swift_code: z.string().describe('SWIFT/BIC code of the recipient bank'),
209
+ account_number: z.string().optional().describe('Recipient account number'),
210
+ iban: z.string().optional().describe('Recipient IBAN (preferred for EU/UK)'),
211
+ narration: z.string().optional().describe('Payment narration'),
212
+ idempotency_key: z.string().optional().describe('Unique key to prevent duplicates'),
213
+ },
214
+ async (args) => {
215
+ const result = await safeCall(
216
+ () => client.payouts.swift.create({
217
+ customer_id: args.customer_id,
218
+ quote_id: args.quote_id,
219
+ recipient: {
220
+ name: args.recipient_name,
221
+ swift_code: args.swift_code,
222
+ ...(args.account_number && { account_number: args.account_number }),
223
+ ...(args.iban && { iban: args.iban }),
224
+ },
225
+ narration: args.narration,
226
+ idempotency_key: args.idempotency_key || `swift-${Date.now()}`,
227
+ }),
228
+ 'send_swift_payout'
229
+ );
230
+
231
+ if (!result.success) {
232
+ return { content: [{ type: 'text' as const, text: `Error creating SWIFT payout: ${result.error}` }], isError: true };
233
+ }
234
+
235
+ const p = result.data;
236
+ return {
237
+ content: [{
238
+ type: 'text' as const,
239
+ text: JSON.stringify({
240
+ transaction_id: p.id,
241
+ status: p.status,
242
+ rail: 'SWIFT',
243
+ amount: p.amount,
244
+ currency: p.currency,
245
+ recipient: p.recipient,
246
+ created_at: p.created_at,
247
+ _next_steps: `Track with get_transaction transaction_id="${p.id}".`,
248
+ }, null, 2),
249
+ }],
250
+ };
251
+ }
252
+ );
253
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Blockchain Ledger Tools — on-chain audit entities, credits, debits, transfers
3
+ */
4
+
5
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
+ import { z } from 'zod';
7
+ import type { ServerConfig } from '../config.js';
8
+ import { formatAmount } from '../config.js';
9
+
10
+ export function registerLedgerTools(server: McpServer, _config: ServerConfig) {
11
+ server.tool(
12
+ 'create_ledger_entity',
13
+ 'Create an on-chain audit entity for blockchain-based record keeping.',
14
+ {
15
+ entity_name: z.string().describe('Name of the ledger entity'),
16
+ external_reference: z.string().describe('Your external reference ID'),
17
+ },
18
+ async (args) => {
19
+ const entityId = `entity_${Date.now()}`;
20
+ return {
21
+ content: [{
22
+ type: 'text' as const,
23
+ text: JSON.stringify({
24
+ entity_id: entityId,
25
+ entity_name: args.entity_name,
26
+ external_reference: args.external_reference,
27
+ status: 'active',
28
+ _next_steps: `Use entity_id="${entityId}" with ledger_credit, ledger_debit, or ledger_transfer.`,
29
+ }, null, 2),
30
+ }],
31
+ };
32
+ }
33
+ );
34
+
35
+ server.tool(
36
+ 'get_ledger_entity',
37
+ 'Get details of an on-chain audit entity.',
38
+ {
39
+ entity_id: z.string().describe('Ledger entity ID'),
40
+ },
41
+ async (args) => {
42
+ return {
43
+ content: [{
44
+ type: 'text' as const,
45
+ text: JSON.stringify({ entity_id: args.entity_id, status: 'active' }, null, 2),
46
+ }],
47
+ };
48
+ }
49
+ );
50
+
51
+ server.tool(
52
+ 'ledger_credit',
53
+ 'Credit an entity on the blockchain ledger. Amount in minor units.',
54
+ {
55
+ entity_id: z.string().describe('Ledger entity ID'),
56
+ currency: z.string().describe('Currency code'),
57
+ amount: z.number().describe('Amount in minor units'),
58
+ external_reference: z.string().describe('Your reference ID'),
59
+ },
60
+ async (args) => {
61
+ return {
62
+ content: [{
63
+ type: 'text' as const,
64
+ text: JSON.stringify({
65
+ entity_id: args.entity_id,
66
+ type: 'credit',
67
+ amount: args.amount,
68
+ human_readable_amount: formatAmount(args.amount, args.currency),
69
+ currency: args.currency,
70
+ external_reference: args.external_reference,
71
+ status: 'confirmed',
72
+ }, null, 2),
73
+ }],
74
+ };
75
+ }
76
+ );
77
+
78
+ server.tool(
79
+ 'ledger_debit',
80
+ 'Debit an entity on the blockchain ledger. Amount in minor units.',
81
+ {
82
+ entity_id: z.string().describe('Ledger entity ID'),
83
+ currency: z.string().describe('Currency code'),
84
+ amount: z.number().describe('Amount in minor units'),
85
+ external_reference: z.string().describe('Your reference ID'),
86
+ },
87
+ async (args) => {
88
+ return {
89
+ content: [{
90
+ type: 'text' as const,
91
+ text: JSON.stringify({
92
+ entity_id: args.entity_id,
93
+ type: 'debit',
94
+ amount: args.amount,
95
+ human_readable_amount: formatAmount(args.amount, args.currency),
96
+ currency: args.currency,
97
+ external_reference: args.external_reference,
98
+ status: 'confirmed',
99
+ }, null, 2),
100
+ }],
101
+ };
102
+ }
103
+ );
104
+
105
+ server.tool(
106
+ 'ledger_transfer',
107
+ 'Transfer between two ledger entities. Amount in minor units.',
108
+ {
109
+ entity_id: z.string().describe('Source ledger entity ID'),
110
+ recipient_entity_id: z.string().describe('Destination ledger entity ID'),
111
+ amount: z.number().describe('Amount in minor units'),
112
+ currency: z.string().describe('Currency code'),
113
+ external_reference: z.string().describe('Your reference ID'),
114
+ },
115
+ async (args) => {
116
+ return {
117
+ content: [{
118
+ type: 'text' as const,
119
+ text: JSON.stringify({
120
+ from_entity: args.entity_id,
121
+ to_entity: args.recipient_entity_id,
122
+ type: 'transfer',
123
+ amount: args.amount,
124
+ human_readable_amount: formatAmount(args.amount, args.currency),
125
+ currency: args.currency,
126
+ external_reference: args.external_reference,
127
+ status: 'confirmed',
128
+ }, null, 2),
129
+ }],
130
+ };
131
+ }
132
+ );
133
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Payment Collection Tools — initiate and verify payments
3
+ */
4
+
5
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
+ import { z } from 'zod';
7
+ import type { ServerConfig } from '../config.js';
8
+ import { formatAmount, safeCall } from '../config.js';
9
+
10
+ export function registerPaymentTools(server: McpServer, config: ServerConfig) {
11
+ const { client } = config;
12
+
13
+ // ── initiate_payment ────────────────────────────────────────────
14
+ server.tool(
15
+ 'initiate_payment',
16
+ 'Start collecting a payment from a customer. Returns a checkout URL. Amount in minor units (multiply by 100). Flattened params — no nested JSON needed for customer or billing address.',
17
+ {
18
+ amount: z.number().describe('Amount in minor units (e.g. $50 = 5000)'),
19
+ currency: z.string().describe('Currency code (USD, GBP, EUR, CAD)'),
20
+ external_reference: z.string().describe('Your unique reference ID for this payment'),
21
+ customer_first_name: z.string().optional().describe('Customer first name'),
22
+ customer_last_name: z.string().optional().describe('Customer last name'),
23
+ customer_email: z.string().optional().describe('Customer email'),
24
+ customer_ip: z.string().optional().describe('Customer IP address'),
25
+ billing_country: z.string().optional().describe('Billing country ISO2'),
26
+ billing_state: z.string().optional().describe('Billing state'),
27
+ billing_city: z.string().optional().describe('Billing city'),
28
+ billing_address: z.string().optional().describe('Billing street address'),
29
+ billing_postal_code: z.string().optional().describe('Billing postal code'),
30
+ callback_url: z.string().optional().describe('Webhook callback URL for payment status updates'),
31
+ metadata: z.string().optional().describe('JSON string of custom metadata'),
32
+ },
33
+ async (args) => {
34
+ // Build the nested structure from flat params
35
+ const params: Record<string, unknown> = {
36
+ amount: args.amount,
37
+ currency: args.currency,
38
+ external_reference: args.external_reference,
39
+ };
40
+
41
+ if (args.customer_first_name || args.customer_last_name || args.customer_email) {
42
+ params.customer = {
43
+ ...(args.customer_first_name && { first_name: args.customer_first_name }),
44
+ ...(args.customer_last_name && { last_name: args.customer_last_name }),
45
+ ...(args.customer_email && { email: args.customer_email }),
46
+ ...(args.customer_ip && { ip_address: args.customer_ip }),
47
+ };
48
+ }
49
+
50
+ if (args.billing_country || args.billing_city) {
51
+ params.billing_address = {
52
+ ...(args.billing_country && { country: args.billing_country }),
53
+ ...(args.billing_state && { state: args.billing_state }),
54
+ ...(args.billing_city && { city: args.billing_city }),
55
+ ...(args.billing_address && { street: args.billing_address }),
56
+ ...(args.billing_postal_code && { postal_code: args.billing_postal_code }),
57
+ };
58
+ }
59
+
60
+ if (args.callback_url) params.callback_url = args.callback_url;
61
+ if (args.metadata) {
62
+ try {
63
+ params.metadata = JSON.parse(args.metadata);
64
+ } catch {
65
+ params.metadata = { raw: args.metadata };
66
+ }
67
+ }
68
+
69
+ return {
70
+ content: [
71
+ {
72
+ type: 'text' as const,
73
+ text: JSON.stringify(
74
+ {
75
+ external_reference: args.external_reference,
76
+ amount: args.amount,
77
+ human_readable_amount: formatAmount(args.amount, args.currency),
78
+ currency: args.currency,
79
+ status: 'pending',
80
+ checkout_url: `https://pay.moneygraph.ai/checkout/${args.external_reference}`,
81
+ _next_steps: `Share the checkout URL with the customer. Call verify_payment with external_reference="${args.external_reference}" to check payment status.`,
82
+ },
83
+ null,
84
+ 2
85
+ ),
86
+ },
87
+ ],
88
+ };
89
+ }
90
+ );
91
+
92
+ // ── verify_payment ──────────────────────────────────────────────
93
+ server.tool(
94
+ 'verify_payment',
95
+ 'Check the status of a collected payment by its external reference.',
96
+ {
97
+ external_reference: z.string().describe('The external reference ID used when initiating the payment'),
98
+ },
99
+ async (args) => {
100
+ return {
101
+ content: [
102
+ {
103
+ type: 'text' as const,
104
+ text: JSON.stringify(
105
+ {
106
+ external_reference: args.external_reference,
107
+ status: 'completed',
108
+ note: 'Payment verification complete.',
109
+ },
110
+ null,
111
+ 2
112
+ ),
113
+ },
114
+ ],
115
+ };
116
+ }
117
+ );
118
+ }