@naturalpay/sdk 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.
Potentially problematic release.
This version of @naturalpay/sdk might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/index.cjs +205 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +205 -27
- package/dist/index.js.map +1 -1
- package/dist/mcp/cli.cjs +252 -50
- package/dist/mcp/cli.cjs.map +1 -1
- package/dist/mcp/cli.js +252 -50
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/index.cjs +251 -49
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.cts +7 -3
- package/dist/mcp/index.d.ts +7 -3
- package/dist/mcp/index.js +251 -49
- package/dist/mcp/index.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/cli.js
CHANGED
|
@@ -211,6 +211,22 @@ function logToolCall(logger4, toolName, options) {
|
|
|
211
211
|
logger4.info(`Tool call: ${toolName}`, extra);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
+
var toolCallStorage = new AsyncLocalStorage();
|
|
215
|
+
function getToolCallHeader() {
|
|
216
|
+
const data = toolCallStorage.getStore();
|
|
217
|
+
if (!data) return void 0;
|
|
218
|
+
return btoa(JSON.stringify(data));
|
|
219
|
+
}
|
|
220
|
+
function runWithToolCall(name, args, fn) {
|
|
221
|
+
return toolCallStorage.run(
|
|
222
|
+
{
|
|
223
|
+
tool: name,
|
|
224
|
+
arguments: args,
|
|
225
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
226
|
+
},
|
|
227
|
+
fn
|
|
228
|
+
);
|
|
229
|
+
}
|
|
214
230
|
|
|
215
231
|
// src/http.ts
|
|
216
232
|
var logger = getLogger("http");
|
|
@@ -444,9 +460,15 @@ var HTTPClient = class {
|
|
|
444
460
|
const headers = {
|
|
445
461
|
Authorization: `Bearer ${jwt}`,
|
|
446
462
|
"Content-Type": "application/json",
|
|
447
|
-
"User-Agent": `naturalpay-ts/${SDK_VERSION2}
|
|
448
|
-
...options?.headers
|
|
463
|
+
"User-Agent": `naturalpay-ts/${SDK_VERSION2}`
|
|
449
464
|
};
|
|
465
|
+
const toolCallHeader = getToolCallHeader();
|
|
466
|
+
if (toolCallHeader) {
|
|
467
|
+
headers["X-Tool-Call"] = toolCallHeader;
|
|
468
|
+
}
|
|
469
|
+
if (options?.headers) {
|
|
470
|
+
Object.assign(headers, options.headers);
|
|
471
|
+
}
|
|
450
472
|
const response = await fetch(url, {
|
|
451
473
|
method,
|
|
452
474
|
headers,
|
|
@@ -562,9 +584,16 @@ var PaymentsResource = class extends BaseResource {
|
|
|
562
584
|
};
|
|
563
585
|
if (params.memo) attributes["description"] = params.memo;
|
|
564
586
|
const body = { data: { attributes } };
|
|
587
|
+
const headers = { "Idempotency-Key": idempotencyKey };
|
|
588
|
+
if (params.agentId) {
|
|
589
|
+
headers["X-Agent-ID"] = params.agentId;
|
|
590
|
+
}
|
|
591
|
+
if (params.instanceId) {
|
|
592
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
593
|
+
}
|
|
565
594
|
const response = await this.http.post("/payments", {
|
|
566
595
|
body,
|
|
567
|
-
headers
|
|
596
|
+
headers
|
|
568
597
|
});
|
|
569
598
|
return unwrapPayment(response);
|
|
570
599
|
}
|
|
@@ -574,8 +603,14 @@ var PaymentsResource = class extends BaseResource {
|
|
|
574
603
|
* @param transferId - The transfer ID to look up
|
|
575
604
|
* @returns Payment object with current status
|
|
576
605
|
*/
|
|
577
|
-
async retrieve(transferId) {
|
|
578
|
-
const
|
|
606
|
+
async retrieve(transferId, options) {
|
|
607
|
+
const headers = {};
|
|
608
|
+
if (options?.instanceId) {
|
|
609
|
+
headers["X-Instance-ID"] = options.instanceId;
|
|
610
|
+
}
|
|
611
|
+
const response = await this.http.get(`/payments/${transferId}`, {
|
|
612
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
613
|
+
});
|
|
579
614
|
return unwrapPayment(response);
|
|
580
615
|
}
|
|
581
616
|
};
|
|
@@ -601,14 +636,71 @@ function unwrapBalance(response) {
|
|
|
601
636
|
pendingClaimCount: attributes.pendingClaimCount != null ? Number(attributes.pendingClaimCount) : void 0
|
|
602
637
|
};
|
|
603
638
|
}
|
|
639
|
+
function unwrapDeposit(response) {
|
|
640
|
+
if (!response?.data) {
|
|
641
|
+
throw new NaturalError('Unexpected response format: missing "data" field in deposit response');
|
|
642
|
+
}
|
|
643
|
+
const { data } = response;
|
|
644
|
+
if (data.type !== "deposit" || !data.attributes) {
|
|
645
|
+
throw new NaturalError(
|
|
646
|
+
`Unexpected resource format: expected type "deposit", got "${data.type}"`
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
const { id, attributes } = data;
|
|
650
|
+
return {
|
|
651
|
+
transferId: id ?? void 0,
|
|
652
|
+
status: String(attributes.status),
|
|
653
|
+
amount: attributes.amount != null ? String(attributes.amount) : "",
|
|
654
|
+
currency: String(attributes.currency),
|
|
655
|
+
estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
|
|
656
|
+
error: attributes.error != null ? String(attributes.error) : void 0,
|
|
657
|
+
errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function unwrapWithdrawal(response) {
|
|
661
|
+
if (!response?.data) {
|
|
662
|
+
throw new NaturalError(
|
|
663
|
+
'Unexpected response format: missing "data" field in withdrawal response'
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
const { data } = response;
|
|
667
|
+
if (data.type !== "withdrawal" || !data.attributes) {
|
|
668
|
+
throw new NaturalError(
|
|
669
|
+
`Unexpected resource format: expected type "withdrawal", got "${data.type}"`
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
const { id, attributes } = data;
|
|
673
|
+
return {
|
|
674
|
+
transferId: id ?? void 0,
|
|
675
|
+
instructionId: attributes.instructionId != null ? String(attributes.instructionId) : void 0,
|
|
676
|
+
status: String(attributes.status),
|
|
677
|
+
amount: attributes.amount != null ? String(attributes.amount) : "",
|
|
678
|
+
currency: String(attributes.currency),
|
|
679
|
+
estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
|
|
680
|
+
kycRequired: Boolean(attributes.kycRequired),
|
|
681
|
+
kycStatus: attributes.kycStatus != null ? String(attributes.kycStatus) : void 0,
|
|
682
|
+
kycSessionUrl: attributes.kycSessionUrl != null ? String(attributes.kycSessionUrl) : void 0,
|
|
683
|
+
mfaRequired: Boolean(attributes.mfaRequired),
|
|
684
|
+
mfaChallengeId: attributes.mfaChallengeId != null ? String(attributes.mfaChallengeId) : void 0,
|
|
685
|
+
mfaExpiresAt: attributes.mfaExpiresAt != null ? String(attributes.mfaExpiresAt) : void 0,
|
|
686
|
+
error: attributes.error != null ? String(attributes.error) : void 0,
|
|
687
|
+
errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
|
|
688
|
+
};
|
|
689
|
+
}
|
|
604
690
|
var WalletResource = class extends BaseResource {
|
|
605
691
|
/**
|
|
606
692
|
* Get current wallet balance.
|
|
607
693
|
*
|
|
608
694
|
* @returns AccountBalance with available, current, pending amounts
|
|
609
695
|
*/
|
|
610
|
-
async balance() {
|
|
611
|
-
const
|
|
696
|
+
async balance(options) {
|
|
697
|
+
const headers = {};
|
|
698
|
+
if (options?.instanceId) {
|
|
699
|
+
headers["X-Instance-ID"] = options.instanceId;
|
|
700
|
+
}
|
|
701
|
+
const response = await this.http.get("/wallet/balance", {
|
|
702
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
703
|
+
});
|
|
612
704
|
return unwrapBalance(response);
|
|
613
705
|
}
|
|
614
706
|
/**
|
|
@@ -618,18 +710,20 @@ var WalletResource = class extends BaseResource {
|
|
|
618
710
|
* @returns DepositResponse with transfer status
|
|
619
711
|
*/
|
|
620
712
|
async deposit(params) {
|
|
621
|
-
const
|
|
713
|
+
const attributes = {
|
|
622
714
|
amount: params.amount,
|
|
623
715
|
currency: params.currency ?? "USD",
|
|
624
716
|
paymentInstrumentId: params.paymentInstrumentId
|
|
625
717
|
};
|
|
626
718
|
if (params.description) {
|
|
627
|
-
|
|
719
|
+
attributes["description"] = params.description;
|
|
628
720
|
}
|
|
629
|
-
|
|
721
|
+
const body = { data: { attributes } };
|
|
722
|
+
const response = await this.http.post("/wallet/deposit", {
|
|
630
723
|
body,
|
|
631
724
|
headers: { "Idempotency-Key": params.idempotencyKey }
|
|
632
725
|
});
|
|
726
|
+
return unwrapDeposit(response);
|
|
633
727
|
}
|
|
634
728
|
/**
|
|
635
729
|
* Initiate a withdrawal to a linked bank account.
|
|
@@ -638,21 +732,19 @@ var WalletResource = class extends BaseResource {
|
|
|
638
732
|
* @returns WithdrawResponse with transfer status (may require KYC/MFA)
|
|
639
733
|
*/
|
|
640
734
|
async withdraw(params) {
|
|
641
|
-
const
|
|
735
|
+
const attributes = {
|
|
642
736
|
amount: params.amount,
|
|
643
737
|
currency: params.currency ?? "USD",
|
|
644
738
|
paymentInstrumentId: params.paymentInstrumentId
|
|
645
739
|
};
|
|
646
|
-
if (params.description)
|
|
647
|
-
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
body["walletId"] = params.walletId;
|
|
651
|
-
}
|
|
652
|
-
return this.http.post("/wallet/withdraw", {
|
|
740
|
+
if (params.description) attributes["description"] = params.description;
|
|
741
|
+
if (params.walletId) attributes["walletId"] = params.walletId;
|
|
742
|
+
const body = { data: { attributes } };
|
|
743
|
+
const response = await this.http.post("/wallet/withdraw", {
|
|
653
744
|
body,
|
|
654
745
|
headers: { "Idempotency-Key": params.idempotencyKey }
|
|
655
746
|
});
|
|
747
|
+
return unwrapWithdrawal(response);
|
|
656
748
|
}
|
|
657
749
|
};
|
|
658
750
|
|
|
@@ -702,6 +794,9 @@ var TransactionsResource = class extends BaseResource {
|
|
|
702
794
|
if (params?.customerPartyId) {
|
|
703
795
|
headers["X-On-Behalf-Of"] = params.customerPartyId;
|
|
704
796
|
}
|
|
797
|
+
if (params?.instanceId) {
|
|
798
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
799
|
+
}
|
|
705
800
|
const response = await this.http.get("/transactions", {
|
|
706
801
|
params: {
|
|
707
802
|
limit: params?.limit ?? 50,
|
|
@@ -773,13 +868,18 @@ var AgentsResource = class extends BaseResource {
|
|
|
773
868
|
* @returns AgentListResponse with list of agents
|
|
774
869
|
*/
|
|
775
870
|
async list(params) {
|
|
871
|
+
const headers = {};
|
|
872
|
+
if (params?.instanceId) {
|
|
873
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
874
|
+
}
|
|
776
875
|
const response = await this.http.get("/agents", {
|
|
777
876
|
params: {
|
|
778
877
|
status: params?.status,
|
|
779
878
|
partyId: params?.partyId,
|
|
780
879
|
limit: params?.limit ?? 50,
|
|
781
880
|
cursor: params?.cursor
|
|
782
|
-
}
|
|
881
|
+
},
|
|
882
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
783
883
|
});
|
|
784
884
|
return unwrapAgentList(response);
|
|
785
885
|
}
|
|
@@ -854,6 +954,52 @@ var AgentsResource = class extends BaseResource {
|
|
|
854
954
|
};
|
|
855
955
|
|
|
856
956
|
// src/resources/delegations.ts
|
|
957
|
+
function unwrapDelegationResource(resource) {
|
|
958
|
+
if (resource.type !== "delegation" || !resource.attributes) {
|
|
959
|
+
throw new NaturalError(
|
|
960
|
+
`Unexpected resource format: expected type "delegation", got "${resource.type}"`
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
const { id, attributes, relationships } = resource;
|
|
964
|
+
return {
|
|
965
|
+
id,
|
|
966
|
+
delegatingPartyId: relationships?.delegatingParty?.data?.id ?? "",
|
|
967
|
+
delegatedPartyId: relationships?.delegatedParty?.data?.id ?? "",
|
|
968
|
+
delegatingPartyName: attributes.delegatingPartyName != null ? String(attributes.delegatingPartyName) : void 0,
|
|
969
|
+
delegatedPartyName: attributes.delegatedPartyName != null ? String(attributes.delegatedPartyName) : void 0,
|
|
970
|
+
delegatingPartyEmail: attributes.delegatingPartyEmail != null ? String(attributes.delegatingPartyEmail) : void 0,
|
|
971
|
+
delegatedPartyEmail: attributes.delegatedPartyEmail != null ? String(attributes.delegatedPartyEmail) : void 0,
|
|
972
|
+
permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
|
|
973
|
+
sourceType: attributes.sourceType != null ? String(attributes.sourceType) : void 0,
|
|
974
|
+
sourceId: attributes.sourceId != null ? String(attributes.sourceId) : void 0,
|
|
975
|
+
expiresAt: attributes.expiresAt != null ? String(attributes.expiresAt) : void 0,
|
|
976
|
+
status: String(attributes.status),
|
|
977
|
+
createdAt: String(attributes.createdAt),
|
|
978
|
+
createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
function unwrapDelegation(response) {
|
|
982
|
+
if (!response?.data) {
|
|
983
|
+
throw new NaturalError(
|
|
984
|
+
'Unexpected response format: missing "data" field in delegation response'
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
return unwrapDelegationResource(response.data);
|
|
988
|
+
}
|
|
989
|
+
function unwrapDelegationList(response) {
|
|
990
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
991
|
+
throw new NaturalError(
|
|
992
|
+
'Unexpected response format: missing "data" array in delegation list response'
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
const delegations = response.data.map(unwrapDelegationResource);
|
|
996
|
+
const pagination = response.meta?.pagination ?? {};
|
|
997
|
+
return {
|
|
998
|
+
delegations,
|
|
999
|
+
hasMore: pagination.hasMore ?? false,
|
|
1000
|
+
nextCursor: pagination.nextCursor ?? null
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
857
1003
|
var DelegationsResource = class extends BaseResource {
|
|
858
1004
|
/**
|
|
859
1005
|
* List delegations with optional filters.
|
|
@@ -862,7 +1008,7 @@ var DelegationsResource = class extends BaseResource {
|
|
|
862
1008
|
* @returns DelegationListResponse with list of delegations
|
|
863
1009
|
*/
|
|
864
1010
|
async list(params) {
|
|
865
|
-
|
|
1011
|
+
const response = await this.http.get("/delegations", {
|
|
866
1012
|
params: {
|
|
867
1013
|
status: params?.status,
|
|
868
1014
|
delegatingPartyId: params?.delegatingPartyId,
|
|
@@ -871,6 +1017,7 @@ var DelegationsResource = class extends BaseResource {
|
|
|
871
1017
|
cursor: params?.cursor
|
|
872
1018
|
}
|
|
873
1019
|
});
|
|
1020
|
+
return unwrapDelegationList(response);
|
|
874
1021
|
}
|
|
875
1022
|
/**
|
|
876
1023
|
* Get delegation by ID.
|
|
@@ -879,7 +1026,8 @@ var DelegationsResource = class extends BaseResource {
|
|
|
879
1026
|
* @returns Delegation details
|
|
880
1027
|
*/
|
|
881
1028
|
async get(delegationId) {
|
|
882
|
-
|
|
1029
|
+
const response = await this.http.get(`/delegations/${delegationId}`);
|
|
1030
|
+
return unwrapDelegation(response);
|
|
883
1031
|
}
|
|
884
1032
|
/**
|
|
885
1033
|
* Update an existing delegation.
|
|
@@ -889,11 +1037,15 @@ var DelegationsResource = class extends BaseResource {
|
|
|
889
1037
|
* @returns Updated Delegation
|
|
890
1038
|
*/
|
|
891
1039
|
async update(delegationId, params) {
|
|
892
|
-
const
|
|
893
|
-
if (params.status !== void 0)
|
|
894
|
-
if (params.permissions !== void 0)
|
|
895
|
-
if (params.expiresAt !== void 0)
|
|
896
|
-
|
|
1040
|
+
const attributes = {};
|
|
1041
|
+
if (params.status !== void 0) attributes["status"] = params.status;
|
|
1042
|
+
if (params.permissions !== void 0) attributes["permissions"] = params.permissions;
|
|
1043
|
+
if (params.expiresAt !== void 0) attributes["expiresAt"] = params.expiresAt;
|
|
1044
|
+
const body = { data: { attributes } };
|
|
1045
|
+
const response = await this.http.put(`/delegations/${delegationId}`, {
|
|
1046
|
+
body
|
|
1047
|
+
});
|
|
1048
|
+
return unwrapDelegation(response);
|
|
897
1049
|
}
|
|
898
1050
|
/**
|
|
899
1051
|
* Revoke a delegation (soft delete by setting status to REVOKED).
|
|
@@ -907,6 +1059,41 @@ var DelegationsResource = class extends BaseResource {
|
|
|
907
1059
|
};
|
|
908
1060
|
|
|
909
1061
|
// src/resources/customers.ts
|
|
1062
|
+
function unwrapCustomerResource(resource) {
|
|
1063
|
+
if (resource.type !== "customer" || !resource.attributes) {
|
|
1064
|
+
throw new NaturalError(
|
|
1065
|
+
`Unexpected resource format: expected type "customer", got "${resource.type}"`
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
const { id, attributes, relationships } = resource;
|
|
1069
|
+
return {
|
|
1070
|
+
party: {
|
|
1071
|
+
id,
|
|
1072
|
+
type: String(attributes.partyType),
|
|
1073
|
+
legalName: attributes.legalName != null ? String(attributes.legalName) : void 0,
|
|
1074
|
+
displayName: attributes.displayName != null ? String(attributes.displayName) : void 0,
|
|
1075
|
+
status: attributes.partyStatus != null ? String(attributes.partyStatus) : void 0
|
|
1076
|
+
},
|
|
1077
|
+
delegationId: relationships?.delegation?.data?.id ?? "",
|
|
1078
|
+
permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
|
|
1079
|
+
delegationStatus: String(attributes.delegationStatus),
|
|
1080
|
+
createdAt: String(attributes.createdAt)
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
function unwrapCustomerList(response) {
|
|
1084
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
1085
|
+
throw new NaturalError(
|
|
1086
|
+
'Unexpected response format: missing "data" array in customer list response'
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
const items = response.data.map(unwrapCustomerResource);
|
|
1090
|
+
const pagination = response.meta?.pagination ?? {};
|
|
1091
|
+
return {
|
|
1092
|
+
items,
|
|
1093
|
+
hasMore: pagination.hasMore ?? false,
|
|
1094
|
+
nextCursor: pagination.nextCursor ?? null
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
910
1097
|
var CustomersResource = class extends BaseResource {
|
|
911
1098
|
/**
|
|
912
1099
|
* List customers onboarded by the partner via delegation.
|
|
@@ -915,12 +1102,13 @@ var CustomersResource = class extends BaseResource {
|
|
|
915
1102
|
* @returns CustomerListResponse with items, hasMore, nextCursor
|
|
916
1103
|
*/
|
|
917
1104
|
async list(params) {
|
|
918
|
-
|
|
1105
|
+
const response = await this.http.get("/customers", {
|
|
919
1106
|
params: {
|
|
920
1107
|
limit: params?.limit,
|
|
921
1108
|
cursor: params?.cursor
|
|
922
1109
|
}
|
|
923
1110
|
});
|
|
1111
|
+
return unwrapCustomerList(response);
|
|
924
1112
|
}
|
|
925
1113
|
};
|
|
926
1114
|
|
|
@@ -960,7 +1148,8 @@ var NaturalClient = class {
|
|
|
960
1148
|
|
|
961
1149
|
// src/mcp/server.ts
|
|
962
1150
|
var logger2 = getLogger("mcp.server");
|
|
963
|
-
function createServer(
|
|
1151
|
+
function createServer(apiKeyOrOptions) {
|
|
1152
|
+
const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions ?? {};
|
|
964
1153
|
logger2.info("Creating Natural Payments MCP server");
|
|
965
1154
|
const server = new FastMCP({
|
|
966
1155
|
name: "Natural Payments",
|
|
@@ -969,7 +1158,7 @@ function createServer(apiKey) {
|
|
|
969
1158
|
let client = null;
|
|
970
1159
|
const getClient = () => {
|
|
971
1160
|
if (!client) {
|
|
972
|
-
client = new NaturalClient({ apiKey });
|
|
1161
|
+
client = new NaturalClient({ apiKey: options.apiKey });
|
|
973
1162
|
}
|
|
974
1163
|
return client;
|
|
975
1164
|
};
|
|
@@ -980,11 +1169,13 @@ function createServer(apiKey) {
|
|
|
980
1169
|
amount: z.number().positive().describe("Payment amount"),
|
|
981
1170
|
memo: z.string().describe("Payment memo (required)"),
|
|
982
1171
|
customerPartyId: z.string().describe("Customer party ID on whose behalf (pty_xxx)"),
|
|
1172
|
+
agentId: z.string().optional().describe("Agent ID (agt_xxx) for agent-initiated payments"),
|
|
983
1173
|
recipientEmail: z.string().email().optional().describe("Recipient email address"),
|
|
984
1174
|
recipientPhone: z.string().optional().describe("Recipient phone number"),
|
|
985
|
-
recipientPartyId: z.string().optional().describe("Recipient party ID (pty_xxx)")
|
|
1175
|
+
recipientPartyId: z.string().optional().describe("Recipient party ID (pty_xxx)"),
|
|
1176
|
+
instanceId: z.string().optional().describe("Developer's session/conversation ID for observability grouping")
|
|
986
1177
|
}),
|
|
987
|
-
execute: async (args) => {
|
|
1178
|
+
execute: async (args) => runWithToolCall("create_payment", args, async () => {
|
|
988
1179
|
const startTime = Date.now();
|
|
989
1180
|
try {
|
|
990
1181
|
const result = await getClient().payments.create({
|
|
@@ -993,7 +1184,9 @@ function createServer(apiKey) {
|
|
|
993
1184
|
recipientPartyId: args.recipientPartyId,
|
|
994
1185
|
amount: args.amount,
|
|
995
1186
|
memo: args.memo,
|
|
996
|
-
customerPartyId: args.customerPartyId
|
|
1187
|
+
customerPartyId: args.customerPartyId,
|
|
1188
|
+
agentId: args.agentId,
|
|
1189
|
+
instanceId: args.instanceId
|
|
997
1190
|
});
|
|
998
1191
|
const durationMs = Date.now() - startTime;
|
|
999
1192
|
logToolCall(logger2, "create_payment", { success: true, durationMs });
|
|
@@ -1007,18 +1200,21 @@ function createServer(apiKey) {
|
|
|
1007
1200
|
});
|
|
1008
1201
|
throw error;
|
|
1009
1202
|
}
|
|
1010
|
-
}
|
|
1203
|
+
})
|
|
1011
1204
|
});
|
|
1012
1205
|
server.addTool({
|
|
1013
1206
|
name: "get_payment_status",
|
|
1014
1207
|
description: "Check the status of a payment by transfer ID",
|
|
1015
1208
|
parameters: z.object({
|
|
1016
|
-
transferId: z.string().describe("The transfer ID returned from create_payment")
|
|
1209
|
+
transferId: z.string().describe("The transfer ID returned from create_payment"),
|
|
1210
|
+
instanceId: z.string().optional().describe("Developer's session/conversation ID for observability grouping")
|
|
1017
1211
|
}),
|
|
1018
|
-
execute: async (args) => {
|
|
1212
|
+
execute: async (args) => runWithToolCall("get_payment_status", args, async () => {
|
|
1019
1213
|
const startTime = Date.now();
|
|
1020
1214
|
try {
|
|
1021
|
-
const result = await getClient().payments.retrieve(args.transferId
|
|
1215
|
+
const result = await getClient().payments.retrieve(args.transferId, {
|
|
1216
|
+
instanceId: args.instanceId
|
|
1217
|
+
});
|
|
1022
1218
|
const durationMs = Date.now() - startTime;
|
|
1023
1219
|
logToolCall(logger2, "get_payment_status", { success: true, durationMs });
|
|
1024
1220
|
return JSON.stringify(result, null, 2);
|
|
@@ -1031,16 +1227,18 @@ function createServer(apiKey) {
|
|
|
1031
1227
|
});
|
|
1032
1228
|
throw error;
|
|
1033
1229
|
}
|
|
1034
|
-
}
|
|
1230
|
+
})
|
|
1035
1231
|
});
|
|
1036
1232
|
server.addTool({
|
|
1037
1233
|
name: "get_account_balance",
|
|
1038
1234
|
description: "Get the current wallet balance",
|
|
1039
|
-
parameters: z.object({
|
|
1040
|
-
|
|
1235
|
+
parameters: z.object({
|
|
1236
|
+
instanceId: z.string().optional().describe("Developer's session/conversation ID for observability grouping")
|
|
1237
|
+
}),
|
|
1238
|
+
execute: async (args) => runWithToolCall("get_account_balance", args, async () => {
|
|
1041
1239
|
const startTime = Date.now();
|
|
1042
1240
|
try {
|
|
1043
|
-
const result = await getClient().wallet.balance();
|
|
1241
|
+
const result = await getClient().wallet.balance({ instanceId: args.instanceId });
|
|
1044
1242
|
const balances = result.balances.map((bal) => ({
|
|
1045
1243
|
assetCode: bal.assetCode,
|
|
1046
1244
|
available: bal.available.amountDollars,
|
|
@@ -1071,7 +1269,7 @@ function createServer(apiKey) {
|
|
|
1071
1269
|
});
|
|
1072
1270
|
throw error;
|
|
1073
1271
|
}
|
|
1074
|
-
}
|
|
1272
|
+
})
|
|
1075
1273
|
});
|
|
1076
1274
|
server.addTool({
|
|
1077
1275
|
name: "list_transactions",
|
|
@@ -1080,16 +1278,18 @@ function createServer(apiKey) {
|
|
|
1080
1278
|
limit: z.number().min(1).max(100).default(50).describe("Maximum number of transactions"),
|
|
1081
1279
|
cursor: z.string().optional().describe("Pagination cursor from previous response"),
|
|
1082
1280
|
agentId: z.string().optional().describe("Agent ID for agent-context authentication"),
|
|
1083
|
-
customerPartyId: z.string().optional().describe("Customer party ID when acting on behalf of customer")
|
|
1281
|
+
customerPartyId: z.string().optional().describe("Customer party ID when acting on behalf of customer"),
|
|
1282
|
+
instanceId: z.string().optional().describe("Developer's session/conversation ID for observability grouping")
|
|
1084
1283
|
}),
|
|
1085
|
-
execute: async (args) => {
|
|
1284
|
+
execute: async (args) => runWithToolCall("list_transactions", args, async () => {
|
|
1086
1285
|
const startTime = Date.now();
|
|
1087
1286
|
try {
|
|
1088
1287
|
const result = await getClient().transactions.list({
|
|
1089
1288
|
limit: args.limit,
|
|
1090
1289
|
cursor: args.cursor,
|
|
1091
1290
|
agentId: args.agentId,
|
|
1092
|
-
customerPartyId: args.customerPartyId
|
|
1291
|
+
customerPartyId: args.customerPartyId,
|
|
1292
|
+
instanceId: args.instanceId
|
|
1093
1293
|
});
|
|
1094
1294
|
const durationMs = Date.now() - startTime;
|
|
1095
1295
|
logToolCall(logger2, "list_transactions", { success: true, durationMs });
|
|
@@ -1103,21 +1303,23 @@ function createServer(apiKey) {
|
|
|
1103
1303
|
});
|
|
1104
1304
|
throw error;
|
|
1105
1305
|
}
|
|
1106
|
-
}
|
|
1306
|
+
})
|
|
1107
1307
|
});
|
|
1108
1308
|
server.addTool({
|
|
1109
1309
|
name: "list_agents",
|
|
1110
1310
|
description: "List agents for the partner",
|
|
1111
1311
|
parameters: z.object({
|
|
1112
1312
|
status: z.enum(["ACTIVE", "REVOKED"]).optional().describe("Filter by status"),
|
|
1113
|
-
limit: z.number().min(1).max(100).default(50).describe("Maximum number of agents")
|
|
1313
|
+
limit: z.number().min(1).max(100).default(50).describe("Maximum number of agents"),
|
|
1314
|
+
instanceId: z.string().optional().describe("Developer's session/conversation ID for observability grouping")
|
|
1114
1315
|
}),
|
|
1115
|
-
execute: async (args) => {
|
|
1316
|
+
execute: async (args) => runWithToolCall("list_agents", args, async () => {
|
|
1116
1317
|
const startTime = Date.now();
|
|
1117
1318
|
try {
|
|
1118
1319
|
const result = await getClient().agents.list({
|
|
1119
1320
|
status: args.status,
|
|
1120
|
-
limit: args.limit
|
|
1321
|
+
limit: args.limit,
|
|
1322
|
+
instanceId: args.instanceId
|
|
1121
1323
|
});
|
|
1122
1324
|
const durationMs = Date.now() - startTime;
|
|
1123
1325
|
logToolCall(logger2, "list_agents", { success: true, durationMs });
|
|
@@ -1131,7 +1333,7 @@ function createServer(apiKey) {
|
|
|
1131
1333
|
});
|
|
1132
1334
|
throw error;
|
|
1133
1335
|
}
|
|
1134
|
-
}
|
|
1336
|
+
})
|
|
1135
1337
|
});
|
|
1136
1338
|
return server;
|
|
1137
1339
|
}
|
|
@@ -1156,7 +1358,7 @@ mcpCommand.command("serve").description("Start the MCP server").option("-t, --tr
|
|
|
1156
1358
|
if (options.serverUrl) {
|
|
1157
1359
|
process.env["NATURAL_SERVER_URL"] = options.serverUrl;
|
|
1158
1360
|
}
|
|
1159
|
-
const server = createServer(options.apiKey);
|
|
1361
|
+
const server = createServer({ apiKey: options.apiKey });
|
|
1160
1362
|
if (options.transport === "stdio") {
|
|
1161
1363
|
logger3.info("Running with stdio transport");
|
|
1162
1364
|
server.start({ transportType: "stdio" });
|