@naturalpay/sdk 0.0.4 → 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 +47 -8
- 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 +47 -8
- package/dist/index.js.map +1 -1
- package/dist/mcp/cli.cjs +94 -31
- package/dist/mcp/cli.cjs.map +1 -1
- package/dist/mcp/cli.js +94 -31
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/index.cjs +93 -30
- 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 +93 -30
- 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
|
};
|
|
@@ -658,8 +693,14 @@ var WalletResource = class extends BaseResource {
|
|
|
658
693
|
*
|
|
659
694
|
* @returns AccountBalance with available, current, pending amounts
|
|
660
695
|
*/
|
|
661
|
-
async balance() {
|
|
662
|
-
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
|
+
});
|
|
663
704
|
return unwrapBalance(response);
|
|
664
705
|
}
|
|
665
706
|
/**
|
|
@@ -753,6 +794,9 @@ var TransactionsResource = class extends BaseResource {
|
|
|
753
794
|
if (params?.customerPartyId) {
|
|
754
795
|
headers["X-On-Behalf-Of"] = params.customerPartyId;
|
|
755
796
|
}
|
|
797
|
+
if (params?.instanceId) {
|
|
798
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
799
|
+
}
|
|
756
800
|
const response = await this.http.get("/transactions", {
|
|
757
801
|
params: {
|
|
758
802
|
limit: params?.limit ?? 50,
|
|
@@ -824,13 +868,18 @@ var AgentsResource = class extends BaseResource {
|
|
|
824
868
|
* @returns AgentListResponse with list of agents
|
|
825
869
|
*/
|
|
826
870
|
async list(params) {
|
|
871
|
+
const headers = {};
|
|
872
|
+
if (params?.instanceId) {
|
|
873
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
874
|
+
}
|
|
827
875
|
const response = await this.http.get("/agents", {
|
|
828
876
|
params: {
|
|
829
877
|
status: params?.status,
|
|
830
878
|
partyId: params?.partyId,
|
|
831
879
|
limit: params?.limit ?? 50,
|
|
832
880
|
cursor: params?.cursor
|
|
833
|
-
}
|
|
881
|
+
},
|
|
882
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
834
883
|
});
|
|
835
884
|
return unwrapAgentList(response);
|
|
836
885
|
}
|
|
@@ -1099,7 +1148,8 @@ var NaturalClient = class {
|
|
|
1099
1148
|
|
|
1100
1149
|
// src/mcp/server.ts
|
|
1101
1150
|
var logger2 = getLogger("mcp.server");
|
|
1102
|
-
function createServer(
|
|
1151
|
+
function createServer(apiKeyOrOptions) {
|
|
1152
|
+
const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions ?? {};
|
|
1103
1153
|
logger2.info("Creating Natural Payments MCP server");
|
|
1104
1154
|
const server = new FastMCP({
|
|
1105
1155
|
name: "Natural Payments",
|
|
@@ -1108,7 +1158,7 @@ function createServer(apiKey) {
|
|
|
1108
1158
|
let client = null;
|
|
1109
1159
|
const getClient = () => {
|
|
1110
1160
|
if (!client) {
|
|
1111
|
-
client = new NaturalClient({ apiKey });
|
|
1161
|
+
client = new NaturalClient({ apiKey: options.apiKey });
|
|
1112
1162
|
}
|
|
1113
1163
|
return client;
|
|
1114
1164
|
};
|
|
@@ -1119,11 +1169,13 @@ function createServer(apiKey) {
|
|
|
1119
1169
|
amount: z.number().positive().describe("Payment amount"),
|
|
1120
1170
|
memo: z.string().describe("Payment memo (required)"),
|
|
1121
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"),
|
|
1122
1173
|
recipientEmail: z.string().email().optional().describe("Recipient email address"),
|
|
1123
1174
|
recipientPhone: z.string().optional().describe("Recipient phone number"),
|
|
1124
|
-
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")
|
|
1125
1177
|
}),
|
|
1126
|
-
execute: async (args) => {
|
|
1178
|
+
execute: async (args) => runWithToolCall("create_payment", args, async () => {
|
|
1127
1179
|
const startTime = Date.now();
|
|
1128
1180
|
try {
|
|
1129
1181
|
const result = await getClient().payments.create({
|
|
@@ -1132,7 +1184,9 @@ function createServer(apiKey) {
|
|
|
1132
1184
|
recipientPartyId: args.recipientPartyId,
|
|
1133
1185
|
amount: args.amount,
|
|
1134
1186
|
memo: args.memo,
|
|
1135
|
-
customerPartyId: args.customerPartyId
|
|
1187
|
+
customerPartyId: args.customerPartyId,
|
|
1188
|
+
agentId: args.agentId,
|
|
1189
|
+
instanceId: args.instanceId
|
|
1136
1190
|
});
|
|
1137
1191
|
const durationMs = Date.now() - startTime;
|
|
1138
1192
|
logToolCall(logger2, "create_payment", { success: true, durationMs });
|
|
@@ -1146,18 +1200,21 @@ function createServer(apiKey) {
|
|
|
1146
1200
|
});
|
|
1147
1201
|
throw error;
|
|
1148
1202
|
}
|
|
1149
|
-
}
|
|
1203
|
+
})
|
|
1150
1204
|
});
|
|
1151
1205
|
server.addTool({
|
|
1152
1206
|
name: "get_payment_status",
|
|
1153
1207
|
description: "Check the status of a payment by transfer ID",
|
|
1154
1208
|
parameters: z.object({
|
|
1155
|
-
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")
|
|
1156
1211
|
}),
|
|
1157
|
-
execute: async (args) => {
|
|
1212
|
+
execute: async (args) => runWithToolCall("get_payment_status", args, async () => {
|
|
1158
1213
|
const startTime = Date.now();
|
|
1159
1214
|
try {
|
|
1160
|
-
const result = await getClient().payments.retrieve(args.transferId
|
|
1215
|
+
const result = await getClient().payments.retrieve(args.transferId, {
|
|
1216
|
+
instanceId: args.instanceId
|
|
1217
|
+
});
|
|
1161
1218
|
const durationMs = Date.now() - startTime;
|
|
1162
1219
|
logToolCall(logger2, "get_payment_status", { success: true, durationMs });
|
|
1163
1220
|
return JSON.stringify(result, null, 2);
|
|
@@ -1170,16 +1227,18 @@ function createServer(apiKey) {
|
|
|
1170
1227
|
});
|
|
1171
1228
|
throw error;
|
|
1172
1229
|
}
|
|
1173
|
-
}
|
|
1230
|
+
})
|
|
1174
1231
|
});
|
|
1175
1232
|
server.addTool({
|
|
1176
1233
|
name: "get_account_balance",
|
|
1177
1234
|
description: "Get the current wallet balance",
|
|
1178
|
-
parameters: z.object({
|
|
1179
|
-
|
|
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 () => {
|
|
1180
1239
|
const startTime = Date.now();
|
|
1181
1240
|
try {
|
|
1182
|
-
const result = await getClient().wallet.balance();
|
|
1241
|
+
const result = await getClient().wallet.balance({ instanceId: args.instanceId });
|
|
1183
1242
|
const balances = result.balances.map((bal) => ({
|
|
1184
1243
|
assetCode: bal.assetCode,
|
|
1185
1244
|
available: bal.available.amountDollars,
|
|
@@ -1210,7 +1269,7 @@ function createServer(apiKey) {
|
|
|
1210
1269
|
});
|
|
1211
1270
|
throw error;
|
|
1212
1271
|
}
|
|
1213
|
-
}
|
|
1272
|
+
})
|
|
1214
1273
|
});
|
|
1215
1274
|
server.addTool({
|
|
1216
1275
|
name: "list_transactions",
|
|
@@ -1219,16 +1278,18 @@ function createServer(apiKey) {
|
|
|
1219
1278
|
limit: z.number().min(1).max(100).default(50).describe("Maximum number of transactions"),
|
|
1220
1279
|
cursor: z.string().optional().describe("Pagination cursor from previous response"),
|
|
1221
1280
|
agentId: z.string().optional().describe("Agent ID for agent-context authentication"),
|
|
1222
|
-
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")
|
|
1223
1283
|
}),
|
|
1224
|
-
execute: async (args) => {
|
|
1284
|
+
execute: async (args) => runWithToolCall("list_transactions", args, async () => {
|
|
1225
1285
|
const startTime = Date.now();
|
|
1226
1286
|
try {
|
|
1227
1287
|
const result = await getClient().transactions.list({
|
|
1228
1288
|
limit: args.limit,
|
|
1229
1289
|
cursor: args.cursor,
|
|
1230
1290
|
agentId: args.agentId,
|
|
1231
|
-
customerPartyId: args.customerPartyId
|
|
1291
|
+
customerPartyId: args.customerPartyId,
|
|
1292
|
+
instanceId: args.instanceId
|
|
1232
1293
|
});
|
|
1233
1294
|
const durationMs = Date.now() - startTime;
|
|
1234
1295
|
logToolCall(logger2, "list_transactions", { success: true, durationMs });
|
|
@@ -1242,21 +1303,23 @@ function createServer(apiKey) {
|
|
|
1242
1303
|
});
|
|
1243
1304
|
throw error;
|
|
1244
1305
|
}
|
|
1245
|
-
}
|
|
1306
|
+
})
|
|
1246
1307
|
});
|
|
1247
1308
|
server.addTool({
|
|
1248
1309
|
name: "list_agents",
|
|
1249
1310
|
description: "List agents for the partner",
|
|
1250
1311
|
parameters: z.object({
|
|
1251
1312
|
status: z.enum(["ACTIVE", "REVOKED"]).optional().describe("Filter by status"),
|
|
1252
|
-
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")
|
|
1253
1315
|
}),
|
|
1254
|
-
execute: async (args) => {
|
|
1316
|
+
execute: async (args) => runWithToolCall("list_agents", args, async () => {
|
|
1255
1317
|
const startTime = Date.now();
|
|
1256
1318
|
try {
|
|
1257
1319
|
const result = await getClient().agents.list({
|
|
1258
1320
|
status: args.status,
|
|
1259
|
-
limit: args.limit
|
|
1321
|
+
limit: args.limit,
|
|
1322
|
+
instanceId: args.instanceId
|
|
1260
1323
|
});
|
|
1261
1324
|
const durationMs = Date.now() - startTime;
|
|
1262
1325
|
logToolCall(logger2, "list_agents", { success: true, durationMs });
|
|
@@ -1270,7 +1333,7 @@ function createServer(apiKey) {
|
|
|
1270
1333
|
});
|
|
1271
1334
|
throw error;
|
|
1272
1335
|
}
|
|
1273
|
-
}
|
|
1336
|
+
})
|
|
1274
1337
|
});
|
|
1275
1338
|
return server;
|
|
1276
1339
|
}
|
|
@@ -1295,7 +1358,7 @@ mcpCommand.command("serve").description("Start the MCP server").option("-t, --tr
|
|
|
1295
1358
|
if (options.serverUrl) {
|
|
1296
1359
|
process.env["NATURAL_SERVER_URL"] = options.serverUrl;
|
|
1297
1360
|
}
|
|
1298
|
-
const server = createServer(options.apiKey);
|
|
1361
|
+
const server = createServer({ apiKey: options.apiKey });
|
|
1299
1362
|
if (options.transport === "stdio") {
|
|
1300
1363
|
logger3.info("Running with stdio transport");
|
|
1301
1364
|
server.start({ transportType: "stdio" });
|