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