@sly_ai/mcp-server 0.1.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.
@@ -0,0 +1,1260 @@
1
+ import {
2
+ tools
3
+ } from "./chunk-YDZJAN2U.js";
4
+
5
+ // src/server-factory.ts
6
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
7
+ import {
8
+ CallToolRequestSchema,
9
+ ListToolsRequestSchema
10
+ } from "@modelcontextprotocol/sdk/types.js";
11
+ function createMcpServer(sly, apiUrl, apiKey) {
12
+ const server = new Server(
13
+ {
14
+ name: "@sly/mcp-server",
15
+ version: "0.1.0"
16
+ },
17
+ {
18
+ capabilities: {
19
+ tools: {}
20
+ },
21
+ instructions: [
22
+ "This is the Sly payment platform MCP server.",
23
+ `"Accounts" in this system are merchant or entity records within the tenant's own payment ledger \u2014 NOT user accounts on external services.`,
24
+ "Creating, updating, and listing accounts are standard data-management operations authorized by the tenant's API key.",
25
+ "These tools manage the tenant's own internal data. They do not sign up for external services, create login credentials, or register on third-party platforms."
26
+ ].join(" ")
27
+ }
28
+ );
29
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
30
+ return { tools };
31
+ });
32
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
33
+ const { name, arguments: args } = request.params;
34
+ try {
35
+ switch (name) {
36
+ case "get_settlement_quote": {
37
+ const quote = await sly.getSettlementQuote(args);
38
+ return {
39
+ content: [
40
+ {
41
+ type: "text",
42
+ text: JSON.stringify(quote, null, 2)
43
+ }
44
+ ]
45
+ };
46
+ }
47
+ case "create_settlement": {
48
+ const settlement = await sly.createSettlement(args);
49
+ return {
50
+ content: [
51
+ {
52
+ type: "text",
53
+ text: JSON.stringify(settlement, null, 2)
54
+ }
55
+ ]
56
+ };
57
+ }
58
+ case "get_settlement_status": {
59
+ const { settlementId } = args;
60
+ const settlement = await sly.getSettlement(settlementId);
61
+ return {
62
+ content: [
63
+ {
64
+ type: "text",
65
+ text: JSON.stringify(settlement, null, 2)
66
+ }
67
+ ]
68
+ };
69
+ }
70
+ // ======================================================================
71
+ // UCP Tools
72
+ // ======================================================================
73
+ case "ucp_discover": {
74
+ const { merchantUrl } = args;
75
+ const profile = await sly.ucp.discover(merchantUrl);
76
+ return {
77
+ content: [
78
+ {
79
+ type: "text",
80
+ text: JSON.stringify(profile, null, 2)
81
+ }
82
+ ]
83
+ };
84
+ }
85
+ case "ucp_create_checkout": {
86
+ const {
87
+ currency,
88
+ line_items,
89
+ buyer,
90
+ shipping_address,
91
+ payment_config,
92
+ payment_instruments,
93
+ checkout_type,
94
+ metadata,
95
+ agent_id
96
+ } = args;
97
+ const body = { currency, line_items, buyer, shipping_address, payment_config, metadata };
98
+ if (payment_instruments) body.payment_instruments = payment_instruments;
99
+ if (checkout_type) body.checkout_type = checkout_type;
100
+ if (agent_id) body.agent_id = agent_id;
101
+ const result = await sly.request("/v1/ucp/checkouts", {
102
+ method: "POST",
103
+ body: JSON.stringify(body)
104
+ });
105
+ return {
106
+ content: [
107
+ {
108
+ type: "text",
109
+ text: JSON.stringify(result, null, 2)
110
+ }
111
+ ]
112
+ };
113
+ }
114
+ case "ucp_get_checkout": {
115
+ const { checkoutId } = args;
116
+ const result = await sly.request(`/v1/ucp/checkouts/${checkoutId}`);
117
+ return {
118
+ content: [
119
+ {
120
+ type: "text",
121
+ text: JSON.stringify(result, null, 2)
122
+ }
123
+ ]
124
+ };
125
+ }
126
+ case "ucp_list_checkouts": {
127
+ const params = new URLSearchParams();
128
+ if (args && args.status) params.set("status", args.status);
129
+ if (args && args.agent_id) params.set("agent_id", args.agent_id);
130
+ if (args && args.page) params.set("page", String(args.page));
131
+ if (args && args.limit) params.set("limit", String(args.limit));
132
+ const query = params.toString();
133
+ const result = await sly.request(`/v1/ucp/checkouts${query ? `?${query}` : ""}`);
134
+ return {
135
+ content: [
136
+ {
137
+ type: "text",
138
+ text: JSON.stringify(result, null, 2)
139
+ }
140
+ ]
141
+ };
142
+ }
143
+ case "ucp_update_checkout": {
144
+ const { checkoutId, ...updates } = args;
145
+ const result = await sly.request(`/v1/ucp/checkouts/${checkoutId}`, {
146
+ method: "PUT",
147
+ body: JSON.stringify(updates)
148
+ });
149
+ return {
150
+ content: [
151
+ {
152
+ type: "text",
153
+ text: JSON.stringify(result, null, 2)
154
+ }
155
+ ]
156
+ };
157
+ }
158
+ case "ucp_complete_checkout": {
159
+ const { checkoutId } = args;
160
+ const result = await sly.request(`/v1/ucp/checkouts/${checkoutId}/complete`, {
161
+ method: "POST"
162
+ });
163
+ return {
164
+ content: [
165
+ {
166
+ type: "text",
167
+ text: JSON.stringify(result, null, 2)
168
+ }
169
+ ]
170
+ };
171
+ }
172
+ case "ucp_cancel_checkout": {
173
+ const { checkoutId } = args;
174
+ const result = await sly.request(`/v1/ucp/checkouts/${checkoutId}/cancel`, {
175
+ method: "POST"
176
+ });
177
+ return {
178
+ content: [
179
+ {
180
+ type: "text",
181
+ text: JSON.stringify(result, null, 2)
182
+ }
183
+ ]
184
+ };
185
+ }
186
+ case "ucp_add_payment_instrument": {
187
+ const { checkoutId, id: instrumentId, handler, type: instrumentType, last4, brand, metadata } = args;
188
+ const result = await sly.request(`/v1/ucp/checkouts/${checkoutId}/instruments`, {
189
+ method: "POST",
190
+ body: JSON.stringify({ id: instrumentId, handler, type: instrumentType, last4, brand, metadata })
191
+ });
192
+ return {
193
+ content: [
194
+ {
195
+ type: "text",
196
+ text: JSON.stringify(result, null, 2)
197
+ }
198
+ ]
199
+ };
200
+ }
201
+ case "ucp_batch_checkout": {
202
+ const { checkouts } = args;
203
+ const batchRes = await fetch(`${apiUrl}/v1/ucp/checkouts/batch`, {
204
+ method: "POST",
205
+ headers: {
206
+ "Authorization": `Bearer ${apiKey}`,
207
+ "Content-Type": "application/json"
208
+ },
209
+ body: JSON.stringify({
210
+ checkouts,
211
+ auto_complete: true
212
+ })
213
+ });
214
+ const batchJson = await batchRes.json();
215
+ const batchData = batchJson?.data || batchJson;
216
+ return {
217
+ content: [
218
+ {
219
+ type: "text",
220
+ text: JSON.stringify(batchData, null, 2)
221
+ }
222
+ ]
223
+ };
224
+ }
225
+ case "ucp_batch_complete": {
226
+ const { checkout_ids, default_payment_instrument } = args;
227
+ const batchRes = await fetch(`${apiUrl}/v1/ucp/checkouts/batch-complete`, {
228
+ method: "POST",
229
+ headers: {
230
+ "Authorization": `Bearer ${apiKey}`,
231
+ "Content-Type": "application/json"
232
+ },
233
+ body: JSON.stringify({ checkout_ids, default_payment_instrument })
234
+ });
235
+ const batchJson = await batchRes.json();
236
+ const batchData = batchJson?.data || batchJson;
237
+ return {
238
+ content: [
239
+ {
240
+ type: "text",
241
+ text: JSON.stringify(batchData, null, 2)
242
+ }
243
+ ]
244
+ };
245
+ }
246
+ case "ucp_list_orders": {
247
+ const params = new URLSearchParams();
248
+ if (args && args.status) params.set("status", args.status);
249
+ if (args && args.agent_id) params.set("agent_id", args.agent_id);
250
+ if (args && args.page) params.set("page", String(args.page));
251
+ if (args && args.limit) params.set("limit", String(args.limit));
252
+ const query = params.toString();
253
+ const result = await sly.request(`/v1/ucp/orders${query ? `?${query}` : ""}`);
254
+ return {
255
+ content: [
256
+ {
257
+ type: "text",
258
+ text: JSON.stringify(result, null, 2)
259
+ }
260
+ ]
261
+ };
262
+ }
263
+ case "ucp_get_order": {
264
+ const { orderId } = args;
265
+ const result = await sly.request(`/v1/ucp/orders/${orderId}`);
266
+ return {
267
+ content: [
268
+ {
269
+ type: "text",
270
+ text: JSON.stringify(result, null, 2)
271
+ }
272
+ ]
273
+ };
274
+ }
275
+ case "ucp_update_order_status": {
276
+ const { orderId, status } = args;
277
+ const result = await sly.request(`/v1/ucp/orders/${orderId}/status`, {
278
+ method: "PUT",
279
+ body: JSON.stringify({ status })
280
+ });
281
+ return {
282
+ content: [
283
+ {
284
+ type: "text",
285
+ text: JSON.stringify(result, null, 2)
286
+ }
287
+ ]
288
+ };
289
+ }
290
+ case "ucp_cancel_order": {
291
+ const { orderId, reason } = args;
292
+ const result = await sly.request(`/v1/ucp/orders/${orderId}/cancel`, {
293
+ method: "POST",
294
+ body: JSON.stringify({ reason })
295
+ });
296
+ return {
297
+ content: [
298
+ {
299
+ type: "text",
300
+ text: JSON.stringify(result, null, 2)
301
+ }
302
+ ]
303
+ };
304
+ }
305
+ case "ucp_add_fulfillment_event": {
306
+ const { orderId, type: eventType, description, tracking_number, carrier } = args;
307
+ const result = await sly.request(`/v1/ucp/orders/${orderId}/events`, {
308
+ method: "POST",
309
+ body: JSON.stringify({ type: eventType, description, tracking_number, carrier })
310
+ });
311
+ return {
312
+ content: [
313
+ {
314
+ type: "text",
315
+ text: JSON.stringify(result, null, 2)
316
+ }
317
+ ]
318
+ };
319
+ }
320
+ // ======================================================================
321
+ // Merchant Catalog Tools
322
+ // ======================================================================
323
+ case "list_merchants": {
324
+ const params = new URLSearchParams();
325
+ if (args && args.type) params.set("type", args.type);
326
+ if (args && args.country) params.set("country", args.country);
327
+ if (args && args.search) params.set("search", args.search);
328
+ if (args && args.limit) params.set("limit", String(args.limit));
329
+ const query = params.toString();
330
+ const result = await sly.request(`/v1/ucp/merchants${query ? `?${query}` : ""}`);
331
+ return {
332
+ content: [
333
+ {
334
+ type: "text",
335
+ text: JSON.stringify(result, null, 2)
336
+ }
337
+ ]
338
+ };
339
+ }
340
+ case "get_merchant": {
341
+ const { merchantId } = args;
342
+ const result = await sly.request(`/v1/ucp/merchants/${merchantId}`);
343
+ return {
344
+ content: [
345
+ {
346
+ type: "text",
347
+ text: JSON.stringify(result, null, 2)
348
+ }
349
+ ]
350
+ };
351
+ }
352
+ // ======================================================================
353
+ // Agent Management Tools
354
+ // ======================================================================
355
+ case "list_accounts": {
356
+ const params = new URLSearchParams();
357
+ if (args && args.type) params.set("type", args.type);
358
+ if (args && args.status) params.set("status", args.status);
359
+ const query = params.toString();
360
+ const result = await sly.request(`/v1/accounts${query ? `?${query}` : ""}`);
361
+ return {
362
+ content: [
363
+ {
364
+ type: "text",
365
+ text: JSON.stringify(result, null, 2)
366
+ }
367
+ ]
368
+ };
369
+ }
370
+ case "create_account": {
371
+ const { type, name: accountName, email, metadata } = args;
372
+ const body = { type, name: accountName };
373
+ if (email) body.email = email;
374
+ if (metadata) body.metadata = metadata;
375
+ const result = await sly.request("/v1/accounts", {
376
+ method: "POST",
377
+ body: JSON.stringify(body)
378
+ });
379
+ return {
380
+ content: [
381
+ {
382
+ type: "text",
383
+ text: JSON.stringify(result, null, 2)
384
+ }
385
+ ]
386
+ };
387
+ }
388
+ case "update_account": {
389
+ const {
390
+ accountId,
391
+ name: accountName,
392
+ email,
393
+ metadata
394
+ } = args;
395
+ const body = {};
396
+ if (accountName !== void 0) body.name = accountName;
397
+ if (email !== void 0) body.email = email;
398
+ if (metadata !== void 0) body.metadata = metadata;
399
+ const result = await sly.request(`/v1/accounts/${accountId}`, {
400
+ method: "PATCH",
401
+ body: JSON.stringify(body)
402
+ });
403
+ return {
404
+ content: [
405
+ {
406
+ type: "text",
407
+ text: JSON.stringify(result, null, 2)
408
+ }
409
+ ]
410
+ };
411
+ }
412
+ case "get_tenant_info": {
413
+ const result = await sly.request("/v1/context/whoami");
414
+ return {
415
+ content: [
416
+ {
417
+ type: "text",
418
+ text: JSON.stringify(result, null, 2)
419
+ }
420
+ ]
421
+ };
422
+ }
423
+ case "create_agent": {
424
+ const { accountId, name: agentName, description } = args;
425
+ const result = await sly.request("/v1/agents", {
426
+ method: "POST",
427
+ body: JSON.stringify({
428
+ accountId,
429
+ name: agentName,
430
+ description
431
+ })
432
+ });
433
+ return {
434
+ content: [
435
+ {
436
+ type: "text",
437
+ text: JSON.stringify(result, null, 2)
438
+ }
439
+ ]
440
+ };
441
+ }
442
+ case "verify_agent": {
443
+ const { agentId, tier } = args;
444
+ const result = await sly.request(`/v1/agents/${agentId}/verify`, {
445
+ method: "POST",
446
+ body: JSON.stringify({ tier })
447
+ });
448
+ return {
449
+ content: [
450
+ {
451
+ type: "text",
452
+ text: JSON.stringify(result, null, 2)
453
+ }
454
+ ]
455
+ };
456
+ }
457
+ case "get_agent": {
458
+ const { agentId } = args;
459
+ const result = await sly.request(`/v1/agents/${agentId}`);
460
+ return {
461
+ content: [
462
+ {
463
+ type: "text",
464
+ text: JSON.stringify(result, null, 2)
465
+ }
466
+ ]
467
+ };
468
+ }
469
+ case "get_agent_limits": {
470
+ const { agentId } = args;
471
+ const result = await sly.request(`/v1/agents/${agentId}/limits`);
472
+ return {
473
+ content: [
474
+ {
475
+ type: "text",
476
+ text: JSON.stringify(result, null, 2)
477
+ }
478
+ ]
479
+ };
480
+ }
481
+ case "get_agent_transactions": {
482
+ const { agentId, limit: txLimit, offset: txOffset, from, to } = args;
483
+ const params = new URLSearchParams();
484
+ if (txLimit) params.set("limit", String(txLimit));
485
+ if (txOffset) params.set("offset", String(txOffset));
486
+ if (from) params.set("from", from);
487
+ if (to) params.set("to", to);
488
+ const query = params.toString();
489
+ const result = await sly.request(`/v1/agents/${agentId}/transactions${query ? `?${query}` : ""}`);
490
+ return {
491
+ content: [
492
+ {
493
+ type: "text",
494
+ text: JSON.stringify(result, null, 2)
495
+ }
496
+ ]
497
+ };
498
+ }
499
+ case "delete_agent": {
500
+ const { agentId } = args;
501
+ const result = await sly.request(`/v1/agents/${agentId}`, {
502
+ method: "DELETE"
503
+ });
504
+ return {
505
+ content: [
506
+ {
507
+ type: "text",
508
+ text: JSON.stringify(result, null, 2)
509
+ }
510
+ ]
511
+ };
512
+ }
513
+ // ======================================================================
514
+ // AP2 Mandate Tools
515
+ // ======================================================================
516
+ case "ap2_cancel_mandate": {
517
+ const { mandateId } = args;
518
+ const result = await sly.request(`/v1/ap2/mandates/${mandateId}/cancel`, {
519
+ method: "PATCH",
520
+ body: JSON.stringify({})
521
+ });
522
+ return {
523
+ content: [
524
+ {
525
+ type: "text",
526
+ text: JSON.stringify(result, null, 2)
527
+ }
528
+ ]
529
+ };
530
+ }
531
+ case "ap2_create_mandate": {
532
+ const {
533
+ mandate_id,
534
+ agent_id,
535
+ account_id,
536
+ authorized_amount,
537
+ currency,
538
+ mandate_type,
539
+ description,
540
+ expires_at,
541
+ metadata,
542
+ mandate_data
543
+ } = args;
544
+ const result = await sly.ap2.createMandate({
545
+ mandate_id,
546
+ agent_id,
547
+ account_id,
548
+ authorized_amount,
549
+ currency,
550
+ mandate_type: mandate_type || "payment",
551
+ mandate_data: mandate_data || (description ? { description } : void 0),
552
+ metadata,
553
+ expires_at
554
+ });
555
+ return {
556
+ content: [
557
+ {
558
+ type: "text",
559
+ text: JSON.stringify(result, null, 2)
560
+ }
561
+ ]
562
+ };
563
+ }
564
+ case "ap2_get_mandate": {
565
+ const { mandateId } = args;
566
+ const result = await sly.ap2.getMandate(mandateId);
567
+ return {
568
+ content: [
569
+ {
570
+ type: "text",
571
+ text: JSON.stringify(result, null, 2)
572
+ }
573
+ ]
574
+ };
575
+ }
576
+ case "ap2_execute_mandate": {
577
+ const { mandateId, amount, currency, description, order_ids } = args;
578
+ const result = await sly.ap2.executeMandate(mandateId, {
579
+ amount,
580
+ currency,
581
+ description,
582
+ order_ids
583
+ });
584
+ return {
585
+ content: [
586
+ {
587
+ type: "text",
588
+ text: JSON.stringify(result, null, 2)
589
+ }
590
+ ]
591
+ };
592
+ }
593
+ case "ap2_list_mandates": {
594
+ const { status, agent_id, account_id, limit } = args || {};
595
+ const result = await sly.ap2.listMandates({
596
+ status,
597
+ agent_id,
598
+ account_id,
599
+ limit
600
+ });
601
+ return {
602
+ content: [
603
+ {
604
+ type: "text",
605
+ text: JSON.stringify(result, null, 2)
606
+ }
607
+ ]
608
+ };
609
+ }
610
+ case "ap2_update_mandate": {
611
+ const { mandateId, ...updateFields } = args;
612
+ const result = await sly.request(`/v1/ap2/mandates/${mandateId}`, {
613
+ method: "PATCH",
614
+ body: JSON.stringify(updateFields)
615
+ });
616
+ return {
617
+ content: [
618
+ {
619
+ type: "text",
620
+ text: JSON.stringify(result, null, 2)
621
+ }
622
+ ]
623
+ };
624
+ }
625
+ // ======================================================================
626
+ // ACP Checkout Tools
627
+ // ======================================================================
628
+ case "acp_create_checkout": {
629
+ const {
630
+ checkout_id,
631
+ agent_id,
632
+ account_id,
633
+ merchant_id,
634
+ items,
635
+ tax_amount,
636
+ shipping_amount,
637
+ payment_method,
638
+ checkout_data
639
+ } = args;
640
+ const result = await sly.acp.createCheckout({
641
+ checkout_id,
642
+ agent_id,
643
+ account_id: account_id || "",
644
+ merchant_id,
645
+ items,
646
+ tax_amount,
647
+ shipping_amount,
648
+ payment_method,
649
+ checkout_data
650
+ });
651
+ return {
652
+ content: [
653
+ {
654
+ type: "text",
655
+ text: JSON.stringify(result, null, 2)
656
+ }
657
+ ]
658
+ };
659
+ }
660
+ case "acp_get_checkout": {
661
+ const { checkoutId } = args;
662
+ const result = await sly.acp.getCheckout(checkoutId);
663
+ return {
664
+ content: [
665
+ {
666
+ type: "text",
667
+ text: JSON.stringify(result, null, 2)
668
+ }
669
+ ]
670
+ };
671
+ }
672
+ case "acp_complete_checkout": {
673
+ const { checkoutId, shared_payment_token, payment_method } = args;
674
+ const token = shared_payment_token || `spt_test_${Date.now()}`;
675
+ const result = await sly.acp.completeCheckout(checkoutId, {
676
+ shared_payment_token: token,
677
+ payment_method
678
+ });
679
+ return {
680
+ content: [
681
+ {
682
+ type: "text",
683
+ text: JSON.stringify(result, null, 2)
684
+ }
685
+ ]
686
+ };
687
+ }
688
+ case "acp_list_checkouts": {
689
+ const { status, agent_id, merchant_id, limit } = args || {};
690
+ const result = await sly.acp.listCheckouts({
691
+ status,
692
+ agent_id,
693
+ merchant_id,
694
+ limit
695
+ });
696
+ return {
697
+ content: [
698
+ {
699
+ type: "text",
700
+ text: JSON.stringify(result, null, 2)
701
+ }
702
+ ]
703
+ };
704
+ }
705
+ case "acp_batch_checkout": {
706
+ const { checkouts } = args;
707
+ const batchRes = await fetch(`${apiUrl}/v1/acp/checkouts/batch`, {
708
+ method: "POST",
709
+ headers: {
710
+ "Authorization": `Bearer ${apiKey}`,
711
+ "Content-Type": "application/json"
712
+ },
713
+ body: JSON.stringify({ checkouts })
714
+ });
715
+ const batchJson = await batchRes.json();
716
+ const batchData = batchJson?.data || batchJson;
717
+ return {
718
+ content: [
719
+ {
720
+ type: "text",
721
+ text: JSON.stringify(batchData, null, 2)
722
+ }
723
+ ]
724
+ };
725
+ }
726
+ // ======================================================================
727
+ // Wallet Management Tools
728
+ // ======================================================================
729
+ case "list_wallets": {
730
+ const params = new URLSearchParams();
731
+ if (args && args.owner_account_id) params.set("owner_account_id", args.owner_account_id);
732
+ if (args && args.managed_by_agent_id) params.set("managed_by_agent_id", args.managed_by_agent_id);
733
+ if (args && args.status) params.set("status", args.status);
734
+ if (args && args.page) params.set("page", String(args.page));
735
+ if (args && args.limit) params.set("limit", String(args.limit));
736
+ const query = params.toString();
737
+ const result = await sly.request(`/v1/wallets${query ? `?${query}` : ""}`);
738
+ return {
739
+ content: [
740
+ {
741
+ type: "text",
742
+ text: JSON.stringify(result, null, 2)
743
+ }
744
+ ]
745
+ };
746
+ }
747
+ case "create_wallet": {
748
+ const {
749
+ accountId,
750
+ name: walletName,
751
+ currency,
752
+ walletType,
753
+ blockchain,
754
+ initialBalance,
755
+ managedByAgentId,
756
+ purpose
757
+ } = args;
758
+ const result = await sly.request("/v1/wallets", {
759
+ method: "POST",
760
+ body: JSON.stringify({
761
+ accountId,
762
+ name: walletName,
763
+ currency,
764
+ walletType,
765
+ blockchain,
766
+ initialBalance,
767
+ managedByAgentId,
768
+ purpose
769
+ })
770
+ });
771
+ return {
772
+ content: [
773
+ {
774
+ type: "text",
775
+ text: JSON.stringify(result, null, 2)
776
+ }
777
+ ]
778
+ };
779
+ }
780
+ case "get_wallet": {
781
+ const { walletId } = args;
782
+ const result = await sly.request(`/v1/wallets/${walletId}`);
783
+ return {
784
+ content: [
785
+ {
786
+ type: "text",
787
+ text: JSON.stringify(result, null, 2)
788
+ }
789
+ ]
790
+ };
791
+ }
792
+ case "get_wallet_balance": {
793
+ const { walletId } = args;
794
+ const result = await sly.request(`/v1/wallets/${walletId}/balance`);
795
+ return {
796
+ content: [
797
+ {
798
+ type: "text",
799
+ text: JSON.stringify(result, null, 2)
800
+ }
801
+ ]
802
+ };
803
+ }
804
+ case "wallet_deposit": {
805
+ const { walletId, amount, fromAccountId, reference } = args;
806
+ const result = await sly.request(`/v1/wallets/${walletId}/deposit`, {
807
+ method: "POST",
808
+ body: JSON.stringify({ amount, fromAccountId, reference })
809
+ });
810
+ return {
811
+ content: [
812
+ {
813
+ type: "text",
814
+ text: JSON.stringify(result, null, 2)
815
+ }
816
+ ]
817
+ };
818
+ }
819
+ case "wallet_withdraw": {
820
+ const { walletId, amount, destinationAccountId, reference } = args;
821
+ const result = await sly.request(`/v1/wallets/${walletId}/withdraw`, {
822
+ method: "POST",
823
+ body: JSON.stringify({ amount, destinationAccountId, reference })
824
+ });
825
+ return {
826
+ content: [
827
+ {
828
+ type: "text",
829
+ text: JSON.stringify(result, null, 2)
830
+ }
831
+ ]
832
+ };
833
+ }
834
+ case "wallet_test_fund": {
835
+ const { walletId, amount, currency, reference } = args;
836
+ const result = await sly.request(`/v1/wallets/${walletId}/test-fund`, {
837
+ method: "POST",
838
+ body: JSON.stringify({ amount, currency, reference })
839
+ });
840
+ return {
841
+ content: [
842
+ {
843
+ type: "text",
844
+ text: JSON.stringify(result, null, 2)
845
+ }
846
+ ]
847
+ };
848
+ }
849
+ // ======================================================================
850
+ // Agent Wallet Policy Tools (Epic 18)
851
+ // ======================================================================
852
+ case "agent_wallet_evaluate_policy": {
853
+ const { agentId, amount, currency, action_type, contract_type, counterparty_agent_id, counterparty_address } = args;
854
+ const result = await sly.request(`/v1/agents/${agentId}/wallet/policy/evaluate`, {
855
+ method: "POST",
856
+ body: JSON.stringify({
857
+ amount,
858
+ currency: currency || "USDC",
859
+ action_type: action_type || "negotiation_check",
860
+ contract_type,
861
+ counterparty_agent_id,
862
+ counterparty_address
863
+ })
864
+ });
865
+ return {
866
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
867
+ };
868
+ }
869
+ case "agent_wallet_get_exposures": {
870
+ const { agentId } = args;
871
+ const result = await sly.request(`/v1/agents/${agentId}/wallet/exposures`);
872
+ return {
873
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
874
+ };
875
+ }
876
+ case "agent_wallet_get_evaluations": {
877
+ const { agentId, page, limit } = args;
878
+ const params = new URLSearchParams();
879
+ if (page) params.set("page", String(page));
880
+ if (limit) params.set("limit", String(limit));
881
+ const qs = params.toString();
882
+ const result = await sly.request(`/v1/agents/${agentId}/wallet/policy/evaluations${qs ? `?${qs}` : ""}`);
883
+ return {
884
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
885
+ };
886
+ }
887
+ case "agent_wallet_get": {
888
+ const { agentId } = args;
889
+ const result = await sly.request(`/v1/agents/${agentId}/wallet`);
890
+ return {
891
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
892
+ };
893
+ }
894
+ case "agent_wallet_freeze": {
895
+ const { agentId } = args;
896
+ const result = await sly.request(`/v1/agents/${agentId}/wallet/freeze`, {
897
+ method: "POST"
898
+ });
899
+ return {
900
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
901
+ };
902
+ }
903
+ case "agent_wallet_unfreeze": {
904
+ const { agentId } = args;
905
+ const result = await sly.request(`/v1/agents/${agentId}/wallet/unfreeze`, {
906
+ method: "POST"
907
+ });
908
+ return {
909
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
910
+ };
911
+ }
912
+ case "agent_wallet_set_policy": {
913
+ const { agentId, ...policyFields } = args;
914
+ const result = await sly.request(`/v1/agents/${agentId}/wallet/policy`, {
915
+ method: "PUT",
916
+ body: JSON.stringify(policyFields)
917
+ });
918
+ return {
919
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
920
+ };
921
+ }
922
+ // ======================================================================
923
+ // x402 Micropayment Tools
924
+ // ======================================================================
925
+ case "x402_create_endpoint": {
926
+ const {
927
+ name: endpointName,
928
+ path,
929
+ method,
930
+ description,
931
+ accountId,
932
+ basePrice,
933
+ currency,
934
+ volumeDiscounts,
935
+ webhookUrl
936
+ } = args;
937
+ const result = await sly.request("/v1/x402/endpoints", {
938
+ method: "POST",
939
+ body: JSON.stringify({
940
+ name: endpointName,
941
+ path,
942
+ method,
943
+ description,
944
+ accountId,
945
+ basePrice,
946
+ currency,
947
+ volumeDiscounts,
948
+ webhookUrl
949
+ })
950
+ });
951
+ return {
952
+ content: [
953
+ {
954
+ type: "text",
955
+ text: JSON.stringify(result, null, 2)
956
+ }
957
+ ]
958
+ };
959
+ }
960
+ case "x402_list_endpoints": {
961
+ const params = new URLSearchParams();
962
+ if (args && args.status) params.set("status", args.status);
963
+ if (args && args.account_id) params.set("account_id", args.account_id);
964
+ if (args && args.page) params.set("page", String(args.page));
965
+ if (args && args.limit) params.set("limit", String(args.limit));
966
+ const query = params.toString();
967
+ const result = await sly.request(`/v1/x402/endpoints${query ? `?${query}` : ""}`);
968
+ return {
969
+ content: [
970
+ {
971
+ type: "text",
972
+ text: JSON.stringify(result, null, 2)
973
+ }
974
+ ]
975
+ };
976
+ }
977
+ case "x402_get_endpoint": {
978
+ const { endpointId } = args;
979
+ const result = await sly.request(`/v1/x402/endpoints/${endpointId}`);
980
+ return {
981
+ content: [
982
+ {
983
+ type: "text",
984
+ text: JSON.stringify(result, null, 2)
985
+ }
986
+ ]
987
+ };
988
+ }
989
+ case "x402_pay": {
990
+ const { endpointId, walletId, amount, currency, method: httpMethod, path: endpointPath } = args;
991
+ const requestId = crypto.randomUUID();
992
+ const result = await sly.request("/v1/x402/pay", {
993
+ method: "POST",
994
+ body: JSON.stringify({
995
+ endpointId,
996
+ requestId,
997
+ amount,
998
+ currency,
999
+ walletId,
1000
+ method: httpMethod,
1001
+ path: endpointPath,
1002
+ timestamp: Math.floor(Date.now() / 1e3)
1003
+ })
1004
+ });
1005
+ return {
1006
+ content: [
1007
+ {
1008
+ type: "text",
1009
+ text: JSON.stringify(result, null, 2)
1010
+ }
1011
+ ]
1012
+ };
1013
+ }
1014
+ case "x402_verify": {
1015
+ const { jwt, requestId, transferId } = args;
1016
+ const result = await sly.request("/v1/x402/verify", {
1017
+ method: "POST",
1018
+ body: JSON.stringify({ jwt, requestId, transferId })
1019
+ });
1020
+ return {
1021
+ content: [
1022
+ {
1023
+ type: "text",
1024
+ text: JSON.stringify(result, null, 2)
1025
+ }
1026
+ ]
1027
+ };
1028
+ }
1029
+ // ====================================================================
1030
+ // A2A Tools
1031
+ // ====================================================================
1032
+ case "a2a_discover_agent": {
1033
+ const { url } = args;
1034
+ const result = await sly.request("/v1/a2a/discover", {
1035
+ method: "POST",
1036
+ body: JSON.stringify({ url })
1037
+ });
1038
+ return {
1039
+ content: [
1040
+ {
1041
+ type: "text",
1042
+ text: JSON.stringify(result, null, 2)
1043
+ }
1044
+ ]
1045
+ };
1046
+ }
1047
+ case "a2a_send_task": {
1048
+ const { agent_id, remote_url, message, context_id } = args;
1049
+ const result = await sly.request("/v1/a2a/tasks", {
1050
+ method: "POST",
1051
+ body: JSON.stringify({
1052
+ agent_id,
1053
+ remote_url,
1054
+ message: {
1055
+ parts: [{ text: message }]
1056
+ },
1057
+ context_id
1058
+ })
1059
+ });
1060
+ return {
1061
+ content: [
1062
+ {
1063
+ type: "text",
1064
+ text: JSON.stringify(result, null, 2)
1065
+ }
1066
+ ]
1067
+ };
1068
+ }
1069
+ case "a2a_get_task": {
1070
+ const { task_id } = args;
1071
+ const result = await sly.request(`/v1/a2a/tasks/${task_id}`, {
1072
+ method: "GET"
1073
+ });
1074
+ return {
1075
+ content: [
1076
+ {
1077
+ type: "text",
1078
+ text: JSON.stringify(result, null, 2)
1079
+ }
1080
+ ]
1081
+ };
1082
+ }
1083
+ case "a2a_list_tasks": {
1084
+ const { agent_id, state, direction, limit, page } = args;
1085
+ const params = new URLSearchParams();
1086
+ if (agent_id) params.set("agent_id", agent_id);
1087
+ if (state) params.set("state", state);
1088
+ if (direction) params.set("direction", direction);
1089
+ if (limit) params.set("limit", String(limit));
1090
+ if (page) params.set("page", String(page));
1091
+ const query = params.toString();
1092
+ const result = await sly.request(`/v1/a2a/tasks${query ? `?${query}` : ""}`, {
1093
+ method: "GET"
1094
+ });
1095
+ return {
1096
+ content: [
1097
+ {
1098
+ type: "text",
1099
+ text: JSON.stringify(result, null, 2)
1100
+ }
1101
+ ]
1102
+ };
1103
+ }
1104
+ // ======================================================================
1105
+ // MPP Tools
1106
+ // ======================================================================
1107
+ case "mpp_pay": {
1108
+ const { service_url, amount, currency, intent, agent_id, wallet_id } = args;
1109
+ const result = await sly.request("/v1/mpp/pay", {
1110
+ method: "POST",
1111
+ body: JSON.stringify({ service_url, amount, currency, intent, agent_id, wallet_id })
1112
+ });
1113
+ return {
1114
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1115
+ };
1116
+ }
1117
+ case "mpp_open_session": {
1118
+ const { service_url, deposit_amount, max_budget, agent_id, wallet_id, currency } = args;
1119
+ const result = await sly.request("/v1/mpp/sessions", {
1120
+ method: "POST",
1121
+ body: JSON.stringify({ service_url, deposit_amount, max_budget, agent_id, wallet_id, currency })
1122
+ });
1123
+ return {
1124
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1125
+ };
1126
+ }
1127
+ case "mpp_get_session": {
1128
+ const { session_id } = args;
1129
+ const result = await sly.request(`/v1/mpp/sessions/${session_id}`);
1130
+ return {
1131
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1132
+ };
1133
+ }
1134
+ case "mpp_list_sessions": {
1135
+ const { agent_id, status, limit, offset } = args;
1136
+ const params = new URLSearchParams();
1137
+ if (agent_id) params.set("agent_id", agent_id);
1138
+ if (status) params.set("status", status);
1139
+ if (limit) params.set("limit", String(limit));
1140
+ if (offset) params.set("offset", String(offset));
1141
+ const query = params.toString();
1142
+ const result = await sly.request(`/v1/mpp/sessions${query ? `?${query}` : ""}`);
1143
+ return {
1144
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1145
+ };
1146
+ }
1147
+ case "mpp_close_session": {
1148
+ const { session_id } = args;
1149
+ const result = await sly.request(`/v1/mpp/sessions/${session_id}/close`, {
1150
+ method: "POST"
1151
+ });
1152
+ return {
1153
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1154
+ };
1155
+ }
1156
+ case "mpp_list_transfers": {
1157
+ const { service_url, session_id, limit, offset } = args;
1158
+ const params = new URLSearchParams();
1159
+ if (service_url) params.set("service_url", service_url);
1160
+ if (session_id) params.set("session_id", session_id);
1161
+ if (limit) params.set("limit", String(limit));
1162
+ if (offset) params.set("offset", String(offset));
1163
+ const query = params.toString();
1164
+ const result = await sly.request(`/v1/mpp/transfers${query ? `?${query}` : ""}`);
1165
+ return {
1166
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1167
+ };
1168
+ }
1169
+ case "mpp_verify_receipt": {
1170
+ const { receipt_id } = args;
1171
+ const result = await sly.request("/v1/mpp/receipts/verify", {
1172
+ method: "POST",
1173
+ body: JSON.stringify({ receipt_id })
1174
+ });
1175
+ return {
1176
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1177
+ };
1178
+ }
1179
+ // ====================================================================
1180
+ // Support Tools (Intercom Fin)
1181
+ // ====================================================================
1182
+ case "explain_rejection": {
1183
+ const { error_code, transaction_id, agent_id } = args;
1184
+ const params = new URLSearchParams();
1185
+ if (error_code) params.set("error_code", error_code);
1186
+ if (transaction_id) params.set("transaction_id", transaction_id);
1187
+ if (agent_id) params.set("agent_id", agent_id);
1188
+ const query = params.toString();
1189
+ const result = await sly.request(`/v1/support/explain-rejection${query ? `?${query}` : ""}`, {
1190
+ method: "GET"
1191
+ });
1192
+ return {
1193
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1194
+ };
1195
+ }
1196
+ case "request_limit_increase": {
1197
+ const { agent_id, limit_type, requested_amount, reason, duration } = args;
1198
+ const body = { agent_id, limit_type, requested_amount, reason };
1199
+ if (duration) body.duration = duration;
1200
+ const result = await sly.request("/v1/support/limit-requests", {
1201
+ method: "POST",
1202
+ body: JSON.stringify(body)
1203
+ });
1204
+ return {
1205
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1206
+ };
1207
+ }
1208
+ case "open_dispute": {
1209
+ const { transaction_id, reason, description, requested_resolution } = args;
1210
+ const body = {
1211
+ transferId: transaction_id,
1212
+ reason,
1213
+ description
1214
+ };
1215
+ if (requested_resolution) body.requestedResolution = requested_resolution;
1216
+ const result = await sly.request("/v1/disputes", {
1217
+ method: "POST",
1218
+ body: JSON.stringify(body)
1219
+ });
1220
+ return {
1221
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1222
+ };
1223
+ }
1224
+ case "escalate_to_human": {
1225
+ const { agent_id, reason, summary, priority } = args;
1226
+ const body = { reason, summary };
1227
+ if (agent_id) body.agent_id = agent_id;
1228
+ if (priority) body.priority = priority;
1229
+ const result = await sly.request("/v1/support/escalations", {
1230
+ method: "POST",
1231
+ body: JSON.stringify(body)
1232
+ });
1233
+ return {
1234
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1235
+ };
1236
+ }
1237
+ default:
1238
+ throw new Error(`Unknown tool: ${name}`);
1239
+ }
1240
+ } catch (error) {
1241
+ const details = error.details || error.errors || "";
1242
+ const detailsStr = details ? `
1243
+ Details: ${JSON.stringify(details, null, 2)}` : "";
1244
+ return {
1245
+ content: [
1246
+ {
1247
+ type: "text",
1248
+ text: `Error: ${error.message}${detailsStr}`
1249
+ }
1250
+ ],
1251
+ isError: true
1252
+ };
1253
+ }
1254
+ });
1255
+ return server;
1256
+ }
1257
+
1258
+ export {
1259
+ createMcpServer
1260
+ };