milypay 0.1.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -85,6 +85,55 @@ var SERVICES = [
85
85
  path: "/au-bsb/search?q={query}",
86
86
  price: "0.004",
87
87
  description: "Search BSBs by bank/branch/suburb"
88
+ },
89
+ {
90
+ id: "abs-dataflows",
91
+ path: "/au-abs/dataflows?q={query}",
92
+ price: "0.002",
93
+ description: "Search ABS dataflow catalogue"
94
+ },
95
+ {
96
+ id: "abs-dataflow",
97
+ path: "/au-abs/dataflow/{id}",
98
+ price: "0.002",
99
+ description: "ABS dataflow metadata"
100
+ },
101
+ {
102
+ id: "abs-data",
103
+ path: "/au-abs/data/{dataflow}?key={key}&startPeriod={period}",
104
+ price: "0.005",
105
+ description: "ABS series data (normalised)"
106
+ },
107
+ {
108
+ id: "abs-cpi",
109
+ path: "/au-abs/cpi",
110
+ price: "0.003",
111
+ description: "Headline CPI index + QoQ/YoY"
112
+ },
113
+ { id: "transit-regions", path: "/au-transit/regions", price: "0.001", description: "AU transit regions" },
114
+ { id: "transit-vehicles", path: "/au-transit/{region}/vehicles", price: "0.003", description: "Live vehicles (GTFS-RT)" },
115
+ { id: "transit-trips", path: "/au-transit/{region}/trip-updates", price: "0.003", description: "Trip updates / delays" },
116
+ { id: "transit-alerts", path: "/au-transit/{region}/alerts", price: "0.002", description: "Service alerts" },
117
+ { id: "transit-summary", path: "/au-transit/{region}/summary", price: "0.002", description: "Region feed summary" },
118
+ { id: "energy", path: "/au-energy", price: "0.001", description: "AU energy catalogue" },
119
+ { id: "energy-nem", path: "/au-energy/nem", price: "0.002", description: "NEM live all regions" },
120
+ { id: "energy-nem-region", path: "/au-energy/nem/{region}", price: "0.002", description: "NEM live one region" },
121
+ { id: "energy-notices", path: "/au-energy/notices", price: "0.002", description: "AEMO market notices" },
122
+ { id: "domains-check", path: "/domains/check", price: "0.01", description: "Domain availability" },
123
+ { id: "domains-quote", path: "/domains/quote", price: "0.01", description: "Domain register quote" },
124
+ { id: "rides-quote", path: "/au-rides/quote", price: "0.01", description: "Uber price estimate quote-only" },
125
+ { id: "phone", path: "/au-phone?number={e164}", price: "0.05", description: "Phone line intel (valid/type/carrier)" },
126
+ {
127
+ id: "ramp-moneygram",
128
+ path: "/ramp/moneygram",
129
+ price: "0",
130
+ description: "MoneyGram funding status (pre-x402 wallet top-up)"
131
+ },
132
+ {
133
+ id: "ramp-moneygram-session",
134
+ path: "POST /ramp/moneygram/session",
135
+ price: "0",
136
+ description: "Create MoneyGram sandbox session (on-ramp / off-ramp widget)"
88
137
  }
89
138
  ];
90
139
  var DEMO_BASE = "https://milypay.xyz";
@@ -160,54 +209,83 @@ function withHostPath(base, path) {
160
209
  function log(quiet, msg) {
161
210
  if (!quiet) process.stderr.write(msg + "\n");
162
211
  }
163
- async function milypayFetch(path, opts = { host: "auto" }) {
212
+ function fundingHintFromBody(body) {
213
+ if (!body || typeof body !== "object") return "";
214
+ const b = body;
215
+ const funding = b.funding;
216
+ const mg = funding?.moneygram;
217
+ if (!mg) return "";
218
+ return [
219
+ "",
220
+ "Underfunded? MoneyGram sandbox can top up USDC (does not settle x402):",
221
+ mg.demoUi ? ` UI: ${mg.demoUi}` : " UI: https://milypay.xyz/fund",
222
+ mg.session ? ` API: POST ${mg.session} {"mode":"on-ramp"}` : " API: POST /ramp/moneygram/session",
223
+ " CLI: milypay fund session"
224
+ ].join("\n");
225
+ }
226
+ async function milypayFetch(path, opts2 = { host: "auto" }, init = {}) {
164
227
  const wallet = loadWallet();
165
- let base = resolveBase(opts.host, wallet, opts.baseUrl);
228
+ let base = resolveBase(opts2.host, wallet, opts2.baseUrl);
166
229
  let url = path.startsWith("http") ? path : withHostPath(base, path);
167
- if (wallet && (base.includes("api.milypay.xyz") || opts.host === "api" || Boolean(opts.baseUrl))) {
168
- log(opts.quiet, `\u2192 ${url} (paying as ${wallet.address.slice(0, 4)}\u2026${wallet.address.slice(-4)})`);
230
+ const method = (init.method || "GET").toUpperCase();
231
+ const headers = {
232
+ accept: "application/json",
233
+ "user-agent": "milypay-cli/0.2.5",
234
+ ...init.headers || {}
235
+ };
236
+ let body;
237
+ if (init.body !== void 0 && method !== "GET" && method !== "HEAD") {
238
+ body = typeof init.body === "string" ? init.body : JSON.stringify(init.body);
239
+ if (!headers["content-type"] && !headers["Content-Type"]) {
240
+ headers["content-type"] = "application/json";
241
+ }
242
+ }
243
+ if (wallet && (base.includes("api.milypay.xyz") || opts2.host === "api" || Boolean(opts2.baseUrl))) {
244
+ log(
245
+ opts2.quiet,
246
+ `\u2192 ${method} ${url} (paying as ${wallet.address.slice(0, 4)}\u2026${wallet.address.slice(-4)})`
247
+ );
169
248
  const client = createX402Client({
170
249
  wallet: {
171
250
  address: wallet.address,
172
251
  signTransaction: wallet.signTransaction
173
252
  },
174
253
  network: "solana",
175
- rpcUrl: opts.rpcUrl || process.env.SOLANA_RPC_URL || process.env.HELIUS_RPC_URL || "https://solana-rpc.publicnode.com",
176
- amount: opts.maxAmount ?? BigInt(5e7)
177
- });
178
- const res2 = await client.fetch(url, {
179
- headers: { accept: "application/json", "user-agent": "milypay-cli/0.1.0" }
254
+ rpcUrl: opts2.rpcUrl || process.env.SOLANA_RPC_URL || process.env.HELIUS_RPC_URL || "https://solana-rpc.publicnode.com",
255
+ amount: opts2.maxAmount ?? BigInt(5e7)
180
256
  });
257
+ const res2 = await client.fetch(url, { method, headers, body });
181
258
  return { res: res2, base, paid: true };
182
259
  }
183
- log(opts.quiet, `\u2192 ${url}${wallet ? "" : " (demo / free host)"}`);
184
- let res = await fetch(url, {
185
- headers: { accept: "application/json", "user-agent": "milypay-cli/0.1.0" }
186
- });
187
- if (res.status === 402 && !wallet && opts.host === "auto" && base === API_BASE) {
260
+ log(opts2.quiet, `\u2192 ${method} ${url}${wallet ? "" : " (demo / free host)"}`);
261
+ let res = await fetch(url, { method, headers, body });
262
+ if (res.status === 402 && !wallet && opts2.host === "auto" && base === API_BASE) {
188
263
  base = DEMO_BASE;
189
264
  url = withHostPath(base, path);
190
- log(opts.quiet, `402 Payment Required \u2014 retrying free demo host`);
191
- res = await fetch(url, {
192
- headers: { accept: "application/json", "user-agent": "milypay-cli/0.1.0" }
193
- });
265
+ log(opts2.quiet, `402 Payment Required \u2014 retrying free demo host`);
266
+ res = await fetch(url, { method, headers, body });
194
267
  }
195
268
  if (res.status === 402 && !wallet) {
196
- const body = await res.text();
269
+ const text = await res.text();
270
+ let parsed = text;
271
+ try {
272
+ parsed = text ? JSON.parse(text) : null;
273
+ } catch {
274
+ }
197
275
  const err = new Error(
198
276
  [
199
277
  "Payment required and no wallet configured.",
200
278
  "Set MILYPAY_PRIVATE_KEY (base58 secret) to pay on api.milypay.xyz,",
201
279
  "or pass --demo to use the free rate-limited host.",
202
- body ? `Server: ${body.slice(0, 300)}` : ""
280
+ fundingHintFromBody(parsed),
281
+ text ? `Server: ${text.slice(0, 300)}` : ""
203
282
  ].filter(Boolean).join("\n")
204
283
  );
205
284
  throw err;
206
285
  }
207
286
  return { res, base, paid: false };
208
287
  }
209
- async function getJson(path, opts) {
210
- const { res } = await milypayFetch(path, opts);
288
+ async function parseJsonResponse(res) {
211
289
  const text = await res.text();
212
290
  let data = text;
213
291
  try {
@@ -216,13 +294,649 @@ async function getJson(path, opts) {
216
294
  }
217
295
  if (!res.ok) {
218
296
  const msg = typeof data === "object" && data && "error" in data ? String(data.error) : text.slice(0, 400);
219
- throw new Error(`HTTP ${res.status}: ${msg}`);
297
+ const hint = fundingHintFromBody(data);
298
+ throw new Error(`HTTP ${res.status}: ${msg}${hint}`);
220
299
  }
221
300
  return data;
222
301
  }
302
+ async function getJson(path, opts2) {
303
+ const { res } = await milypayFetch(path, opts2);
304
+ return parseJsonResponse(res);
305
+ }
306
+ async function postJson(path, body, opts2) {
307
+ const { res } = await milypayFetch(path, opts2, { method: "POST", body: body ?? {} });
308
+ return parseJsonResponse(res);
309
+ }
310
+
311
+ // src/mcp.ts
312
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
313
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
314
+ import { z } from "zod";
315
+
316
+ // src/version.ts
317
+ var VERSION = "0.2.5";
318
+
319
+ // src/mcp.ts
320
+ function hostFromEnv() {
321
+ const h = (process.env.MILYPAY_HOST || "auto").toLowerCase();
322
+ if (h === "demo" || h === "api" || h === "auto") return h;
323
+ return "auto";
324
+ }
325
+ function opts() {
326
+ return {
327
+ host: hostFromEnv(),
328
+ baseUrl: process.env.MILYPAY_BASE_URL,
329
+ rpcUrl: process.env.SOLANA_RPC_URL || process.env.HELIUS_RPC_URL,
330
+ quiet: true
331
+ };
332
+ }
333
+ function digits(s) {
334
+ return s.replace(/\D/g, "");
335
+ }
336
+ function ok(data) {
337
+ return {
338
+ content: [
339
+ {
340
+ type: "text",
341
+ text: typeof data === "string" ? data : JSON.stringify(data, null, 2)
342
+ }
343
+ ]
344
+ };
345
+ }
346
+ function fail(err) {
347
+ const msg = err instanceof Error ? err.message : String(err);
348
+ return {
349
+ isError: true,
350
+ content: [{ type: "text", text: msg }]
351
+ };
352
+ }
353
+ async function runJson(path) {
354
+ try {
355
+ return ok(await getJson(path, opts()));
356
+ } catch (e) {
357
+ return fail(e);
358
+ }
359
+ }
360
+ async function startMcpServer() {
361
+ const server = new McpServer({
362
+ name: "milypay",
363
+ version: VERSION
364
+ });
365
+ server.registerTool(
366
+ "list_services",
367
+ {
368
+ title: "List Milypay services",
369
+ description: "List Australian data endpoints available on Milypay with AUD prices. Docs: " + DOCS,
370
+ inputSchema: {}
371
+ },
372
+ async () => ok({
373
+ docs: DOCS,
374
+ host: hostFromEnv(),
375
+ services: SERVICES.map((s) => ({
376
+ id: s.id,
377
+ path: s.path,
378
+ priceAUD: s.price,
379
+ description: s.description
380
+ }))
381
+ })
382
+ );
383
+ server.registerTool(
384
+ "whoami",
385
+ {
386
+ title: "Wallet / host status",
387
+ description: "Show configured Solana wallet (if any) and active host mode.",
388
+ inputSchema: {}
389
+ },
390
+ async () => {
391
+ const w = loadWallet();
392
+ return ok({
393
+ host: hostFromEnv(),
394
+ wallet: w ? { address: w.address, source: w.source } : null,
395
+ hint: w ? "Wallet set \u2014 auto mode uses paid api.milypay.xyz" : "No wallet \u2014 auto mode uses free demo host milypay.xyz"
396
+ });
397
+ }
398
+ );
399
+ server.registerTool(
400
+ "lookup_abn",
401
+ {
402
+ title: "Lookup ABN",
403
+ description: "Australian Business Register lookup by 11-digit ABN. Returns entity name, status, type, ACN, GST, location.",
404
+ inputSchema: {
405
+ abn: z.string().describe("11-digit Australian Business Number")
406
+ }
407
+ },
408
+ async ({ abn }) => {
409
+ const a = digits(abn);
410
+ if (a.length !== 11) return fail("ABN must be 11 digits");
411
+ return runJson(`/au-business/abn/${a}`);
412
+ }
413
+ );
414
+ server.registerTool(
415
+ "lookup_acn",
416
+ {
417
+ title: "Lookup business by ACN",
418
+ description: "ABR business identity resolved from a 9-digit ACN.",
419
+ inputSchema: {
420
+ acn: z.string().describe("9-digit Australian Company Number")
421
+ }
422
+ },
423
+ async ({ acn }) => {
424
+ const a = digits(acn);
425
+ if (a.length !== 9) return fail("ACN must be 9 digits");
426
+ return runJson(`/au-business/acn/${a}`);
427
+ }
428
+ );
429
+ server.registerTool(
430
+ "search_business",
431
+ {
432
+ title: "Search businesses by name",
433
+ description: "ABN name search by business or entity name (ABR).",
434
+ inputSchema: {
435
+ name: z.string().describe("Business or entity name to search"),
436
+ maxResults: z.number().int().min(1).max(50).optional()
437
+ }
438
+ },
439
+ async ({ name, maxResults }) => {
440
+ const q = new URLSearchParams({ name });
441
+ if (maxResults) q.set("maxResults", String(maxResults));
442
+ return runJson(`/au-business/search?${q}`);
443
+ }
444
+ );
445
+ server.registerTool(
446
+ "lookup_company",
447
+ {
448
+ title: "Lookup ASIC company by ACN",
449
+ description: "ASIC company register (open data): status, type, class, registration dates, former names.",
450
+ inputSchema: {
451
+ acn: z.string().describe("9-digit ACN")
452
+ }
453
+ },
454
+ async ({ acn }) => {
455
+ const a = digits(acn);
456
+ if (a.length !== 9) return fail("ACN must be 9 digits");
457
+ return runJson(`/au-company/acn/${a}`);
458
+ }
459
+ );
460
+ server.registerTool(
461
+ "search_company",
462
+ {
463
+ title: "Search ASIC companies",
464
+ description: "ASIC company name search across current and former names (open data).",
465
+ inputSchema: {
466
+ name: z.string().describe("Company name"),
467
+ limit: z.number().int().min(1).max(50).optional()
468
+ }
469
+ },
470
+ async ({ name, limit }) => {
471
+ const q = new URLSearchParams({ name });
472
+ if (limit) q.set("limit", String(limit));
473
+ return runJson(`/au-company/search?${q}`);
474
+ }
475
+ );
476
+ server.registerTool(
477
+ "company_report",
478
+ {
479
+ title: "Official ASIC company extract",
480
+ description: "Paid DSP ASIC extract (directors, office, share capital). ~$12 AUD on paid API. Demo host may return sandbox.",
481
+ inputSchema: {
482
+ acn: z.string().describe("9-digit ACN")
483
+ },
484
+ annotations: { openWorldHint: true }
485
+ },
486
+ async ({ acn }) => {
487
+ const a = digits(acn);
488
+ if (a.length !== 9) return fail("ACN must be 9 digits");
489
+ return runJson(`/au-company-report?acn=${a}`);
490
+ }
491
+ );
492
+ server.registerTool(
493
+ "address_validate",
494
+ {
495
+ title: "Validate Australian address",
496
+ description: "Validate address against G-NAF. Returns canonical form, GNAF PID, geocode.",
497
+ inputSchema: {
498
+ q: z.string().describe("Address query, e.g. '1 bligh st sydney'")
499
+ }
500
+ },
501
+ async ({ q }) => runJson(`/au-address/validate?${new URLSearchParams({ q })}`)
502
+ );
503
+ server.registerTool(
504
+ "address_search",
505
+ {
506
+ title: "Search / autocomplete address",
507
+ description: "Ranked Australian address matches from G-NAF.",
508
+ inputSchema: {
509
+ q: z.string().describe("Partial address"),
510
+ limit: z.number().int().min(1).max(20).optional()
511
+ }
512
+ },
513
+ async ({ q, limit }) => {
514
+ const qs = new URLSearchParams({ q });
515
+ if (limit) qs.set("limit", String(limit));
516
+ return runJson(`/au-address/search?${qs}`);
517
+ }
518
+ );
519
+ server.registerTool(
520
+ "address_geocode",
521
+ {
522
+ title: "Geocode Australian address",
523
+ description: "Latitude/longitude for an Australian address (G-NAF).",
524
+ inputSchema: {
525
+ q: z.string().describe("Address to geocode")
526
+ }
527
+ },
528
+ async ({ q }) => runJson(`/au-address/geocode?${new URLSearchParams({ q })}`)
529
+ );
530
+ server.registerTool(
531
+ "lookup_super",
532
+ {
533
+ title: "Lookup super fund",
534
+ description: "ATO Super Fund Lookup by ABN: fund name, status, type, USIs.",
535
+ inputSchema: {
536
+ abn: z.string().describe("11-digit fund ABN")
537
+ }
538
+ },
539
+ async ({ abn }) => {
540
+ const a = digits(abn);
541
+ if (a.length !== 11) return fail("ABN must be 11 digits");
542
+ return runJson(`/au-super/abn/${a}`);
543
+ }
544
+ );
545
+ server.registerTool(
546
+ "weather",
547
+ {
548
+ title: "Australian weather",
549
+ description: "Current conditions + multi-day forecast. Pass address q= or lat+lng. BOM ACCESS-G via Open-Meteo.",
550
+ inputSchema: {
551
+ q: z.string().optional().describe("Australian address"),
552
+ lat: z.number().optional(),
553
+ lng: z.number().optional(),
554
+ days: z.number().int().min(1).max(14).optional()
555
+ }
556
+ },
557
+ async ({ q, lat, lng, days }) => {
558
+ const qs = new URLSearchParams();
559
+ if (q) qs.set("q", q);
560
+ if (lat != null) qs.set("lat", String(lat));
561
+ if (lng != null) qs.set("lng", String(lng));
562
+ if (days != null) qs.set("days", String(days));
563
+ if (!qs.has("q") && !(qs.has("lat") && qs.has("lng"))) {
564
+ return fail("Provide q (address) or lat+lng");
565
+ }
566
+ return runJson(`/au-weather?${qs}`);
567
+ }
568
+ );
569
+ server.registerTool(
570
+ "lookup_bsb",
571
+ {
572
+ title: "Lookup BSB",
573
+ description: "AusPayNet BSB directory: bank, branch, address, payment methods. Accept 012-002 or 012002.",
574
+ inputSchema: {
575
+ bsb: z.string().describe("BSB with or without hyphen")
576
+ }
577
+ },
578
+ async ({ bsb }) => {
579
+ const d = digits(bsb);
580
+ if (d.length !== 6) return fail("BSB must be 6 digits");
581
+ const formatted = `${d.slice(0, 3)}-${d.slice(3)}`;
582
+ return runJson(`/au-bsb/${encodeURIComponent(formatted)}`);
583
+ }
584
+ );
585
+ server.registerTool(
586
+ "search_bsb",
587
+ {
588
+ title: "Search BSBs",
589
+ description: "Search BSBs by bank name, branch, or suburb.",
590
+ inputSchema: {
591
+ q: z.string().describe("Search query"),
592
+ limit: z.number().int().min(1).max(20).optional()
593
+ }
594
+ },
595
+ async ({ q, limit }) => {
596
+ const qs = new URLSearchParams({ q });
597
+ if (limit) qs.set("limit", String(limit));
598
+ return runJson(`/au-bsb/search?${qs}`);
599
+ }
600
+ );
601
+ server.registerTool(
602
+ "postage",
603
+ {
604
+ title: "Australia Post rates",
605
+ description: "Domestic parcel rates (--from/--to/--weight + dimensions) or international (--country/--weight).",
606
+ inputSchema: {
607
+ from: z.string().optional().describe("From postcode (domestic)"),
608
+ to: z.string().optional().describe("To postcode (domestic)"),
609
+ country: z.string().optional().describe("ISO country code (international)"),
610
+ weight: z.number().positive().describe("Weight in kg"),
611
+ length: z.number().positive().optional().describe("cm (domestic)"),
612
+ width: z.number().positive().optional().describe("cm (domestic)"),
613
+ height: z.number().positive().optional().describe("cm (domestic)")
614
+ }
615
+ },
616
+ async (args) => {
617
+ const qs = new URLSearchParams();
618
+ qs.set("weight", String(args.weight));
619
+ if (args.country) qs.set("country", args.country);
620
+ if (args.from) qs.set("from", args.from);
621
+ if (args.to) qs.set("to", args.to);
622
+ if (args.length != null) qs.set("length", String(args.length));
623
+ if (args.width != null) qs.set("width", String(args.width));
624
+ if (args.height != null) qs.set("height", String(args.height));
625
+ if (!args.country && !(args.from && args.to)) {
626
+ return fail("Need from+to (domestic) or country (international)");
627
+ }
628
+ return runJson(`/au-postage?${qs}`);
629
+ }
630
+ );
631
+ server.registerTool(
632
+ "call",
633
+ {
634
+ title: "Raw API call",
635
+ description: "GET an arbitrary Milypay path, e.g. /au-business/abn/51824753556. Prefer typed tools when possible.",
636
+ inputSchema: {
637
+ path: z.string().describe("API path starting with /, e.g. /au-bsb/012-002")
638
+ }
639
+ },
640
+ async ({ path }) => {
641
+ const p = path.startsWith("/") ? path : `/${path}`;
642
+ return runJson(p);
643
+ }
644
+ );
645
+ server.registerResource(
646
+ "agents-guide",
647
+ "milypay://agents.md",
648
+ {
649
+ title: "Milypay agents guide",
650
+ description: "Agent-facing documentation URL and service summary",
651
+ mimeType: "text/markdown"
652
+ },
653
+ async () => ({
654
+ contents: [
655
+ {
656
+ uri: "milypay://agents.md",
657
+ mimeType: "text/markdown",
658
+ text: [
659
+ `# Milypay MCP`,
660
+ ``,
661
+ `Full guide: ${DOCS}`,
662
+ `Host mode: ${hostFromEnv()} (env MILYPAY_HOST)`,
663
+ ``,
664
+ `## Services`,
665
+ ...SERVICES.map((s) => `- ${s.id} \u2014 ${s.path} \u2014 $${s.price} AUD \u2014 ${s.description}`)
666
+ ].join("\n")
667
+ }
668
+ ]
669
+ })
670
+ );
671
+ server.registerTool(
672
+ "abs_dataflows",
673
+ {
674
+ description: "Search or list ABS (Australian Bureau of Statistics) SDMX dataflows \u2014 CPI, wages, population, census, retail, etc.",
675
+ inputSchema: {
676
+ q: z.string().optional().describe("Search query e.g. CPI, wage, population"),
677
+ limit: z.number().int().min(1).max(200).optional()
678
+ }
679
+ },
680
+ async ({ q, limit }) => {
681
+ const qs = new URLSearchParams();
682
+ if (q) qs.set("q", q);
683
+ if (limit) qs.set("limit", String(limit));
684
+ const path = `/au-abs/dataflows${qs.toString() ? `?${qs}` : ""}`;
685
+ return runJson(path);
686
+ }
687
+ );
688
+ server.registerTool(
689
+ "abs_dataflow",
690
+ {
691
+ description: "ABS dataflow structure/metadata by id (e.g. CPI, WPI, RT).",
692
+ inputSchema: { id: z.string().describe("Dataflow id e.g. CPI") }
693
+ },
694
+ async ({ id }) => runJson(`/au-abs/dataflow/${encodeURIComponent(id)}`)
695
+ );
696
+ server.registerTool(
697
+ "abs_data",
698
+ {
699
+ description: "Fetch ABS statistical series (normalised observations). Prefer a series key + startPeriod.",
700
+ inputSchema: {
701
+ dataflow: z.string().describe("e.g. CPI"),
702
+ key: z.string().optional().describe("SDMX key e.g. 1.10001.10.50.Q"),
703
+ startPeriod: z.string().optional().describe("e.g. 2020 or 2020-Q1"),
704
+ endPeriod: z.string().optional()
705
+ }
706
+ },
707
+ async ({ dataflow, key, startPeriod, endPeriod }) => {
708
+ const qs = new URLSearchParams();
709
+ if (key) qs.set("key", key);
710
+ if (startPeriod) qs.set("startPeriod", startPeriod);
711
+ if (endPeriod) qs.set("endPeriod", endPeriod);
712
+ if (!key && !startPeriod) qs.set("startPeriod", "2020");
713
+ const q = qs.toString();
714
+ return runJson(`/au-abs/data/${encodeURIComponent(dataflow)}${q ? `?${q}` : ""}`);
715
+ }
716
+ );
717
+ server.registerTool(
718
+ "abs_cpi",
719
+ {
720
+ description: "Headline Australian CPI (All groups, quarterly index) with latest value, QoQ and YoY % change. ABS cat. 6401.0.",
721
+ inputSchema: {
722
+ startPeriod: z.string().optional().describe("e.g. 2015")
723
+ }
724
+ },
725
+ async ({ startPeriod }) => {
726
+ const qs = startPeriod ? `?startPeriod=${encodeURIComponent(startPeriod)}` : "";
727
+ return runJson(`/au-abs/cpi${qs}`);
728
+ }
729
+ );
730
+ server.registerTool(
731
+ "transit_regions",
732
+ {
733
+ description: "List Australian public transport regions available on Milypay (live GTFS-RT + planned).",
734
+ inputSchema: {}
735
+ },
736
+ async () => runJson("/au-transit/regions")
737
+ );
738
+ server.registerTool(
739
+ "transit_vehicles",
740
+ {
741
+ description: "Live public transport vehicle positions (GTFS-RT). region=seq (QLD Translink) or sa (Adelaide).",
742
+ inputSchema: {
743
+ region: z.string().describe("seq or sa"),
744
+ routeId: z.string().optional(),
745
+ limit: z.number().int().min(1).max(200).optional()
746
+ }
747
+ },
748
+ async ({ region, routeId, limit }) => {
749
+ const qs = new URLSearchParams();
750
+ if (routeId) qs.set("routeId", routeId);
751
+ if (limit) qs.set("limit", String(limit));
752
+ const q = qs.toString();
753
+ return runJson(`/au-transit/${encodeURIComponent(region)}/vehicles${q ? `?${q}` : ""}`);
754
+ }
755
+ );
756
+ server.registerTool(
757
+ "transit_trip_updates",
758
+ {
759
+ description: "Live trip delays and stop ETAs (GTFS-RT).",
760
+ inputSchema: {
761
+ region: z.string().describe("seq or sa"),
762
+ routeId: z.string().optional(),
763
+ stopId: z.string().optional(),
764
+ limit: z.number().int().min(1).max(150).optional()
765
+ }
766
+ },
767
+ async ({ region, routeId, stopId, limit }) => {
768
+ const qs = new URLSearchParams();
769
+ if (routeId) qs.set("routeId", routeId);
770
+ if (stopId) qs.set("stopId", stopId);
771
+ if (limit) qs.set("limit", String(limit));
772
+ const q = qs.toString();
773
+ return runJson(`/au-transit/${encodeURIComponent(region)}/trip-updates${q ? `?${q}` : ""}`);
774
+ }
775
+ );
776
+ server.registerTool(
777
+ "transit_alerts",
778
+ {
779
+ description: "Public transport service alerts (GTFS-RT).",
780
+ inputSchema: {
781
+ region: z.string().describe("seq or sa"),
782
+ routeId: z.string().optional(),
783
+ limit: z.number().int().min(1).max(100).optional()
784
+ }
785
+ },
786
+ async ({ region, routeId, limit }) => {
787
+ const qs = new URLSearchParams();
788
+ if (routeId) qs.set("routeId", routeId);
789
+ if (limit) qs.set("limit", String(limit));
790
+ const q = qs.toString();
791
+ return runJson(`/au-transit/${encodeURIComponent(region)}/alerts${q ? `?${q}` : ""}`);
792
+ }
793
+ );
794
+ server.registerTool(
795
+ "transit_summary",
796
+ {
797
+ description: "Summary counts of vehicles, trip updates, and alerts for a transit region.",
798
+ inputSchema: { region: z.string().describe("seq or sa") }
799
+ },
800
+ async ({ region }) => runJson(`/au-transit/${encodeURIComponent(region)}/summary`)
801
+ );
802
+ server.registerTool(
803
+ "energy_nem",
804
+ {
805
+ description: "Live Australian NEM wholesale electricity price and demand for all regions (AEMO). Returns $/MWh spot, demand MW, generation, interconnectors.",
806
+ inputSchema: {}
807
+ },
808
+ async () => runJson("/au-energy/nem")
809
+ );
810
+ server.registerTool(
811
+ "energy_nem_region",
812
+ {
813
+ description: "Live NEM snapshot for one region. region=NSW1|QLD1|SA1|TAS1|VIC1 (or NSW/QLD/SA/TAS/VIC).",
814
+ inputSchema: { region: z.string().describe("NSW1, VIC1, QLD1, SA1, TAS1") }
815
+ },
816
+ async ({ region }) => runJson(`/au-energy/nem/${encodeURIComponent(region)}`)
817
+ );
818
+ server.registerTool(
819
+ "energy_notices",
820
+ {
821
+ description: "Recent AEMO National Electricity Market notices (non-conformance, outages, etc).",
822
+ inputSchema: { limit: z.number().int().min(1).max(50).optional() }
823
+ },
824
+ async ({ limit }) => {
825
+ const q = limit ? `?limit=${limit}` : "";
826
+ return runJson(`/au-energy/notices${q}`);
827
+ }
828
+ );
829
+ server.registerTool(
830
+ "lookup_phone",
831
+ {
832
+ description: "Phone line intelligence (Twilio): valid, country, line type (mobile/landline/voip), carrier. NOT personal identity or caller name. Accepts E.164 (+61\u2026) or AU 04\u2026",
833
+ inputSchema: {
834
+ number: z.string().describe("E.164 phone e.g. +614****5678 or AU mobile 0412345678")
835
+ }
836
+ },
837
+ async ({ number }) => runJson(`/au-phone?number=${encodeURIComponent(number)}`)
838
+ );
839
+ server.registerTool(
840
+ "domains_check",
841
+ {
842
+ description: "Check DNS domain availability via Dynadot (x402 catalogue).",
843
+ inputSchema: { name: z.string() }
844
+ },
845
+ async ({ name }) => runJson(`/domains/check?name=${encodeURIComponent(name)}`)
846
+ );
847
+ server.registerTool(
848
+ "domains_quote",
849
+ {
850
+ description: "Quote domain registration chargeUsd for x402.",
851
+ inputSchema: { name: z.string(), years: z.number().optional() }
852
+ },
853
+ async ({ name, years }) => runJson(`/domains/quote?name=${encodeURIComponent(name)}&years=${years || 1}`)
854
+ );
855
+ server.registerTool(
856
+ "rides_quote",
857
+ {
858
+ description: "Uber ride PRICE estimates only (no booking). start/end lat/lng. Returns product prices and surge.",
859
+ inputSchema: {
860
+ start_lat: z.number(),
861
+ start_lng: z.number(),
862
+ end_lat: z.number(),
863
+ end_lng: z.number(),
864
+ seat_count: z.number().int().min(1).max(10).optional()
865
+ }
866
+ },
867
+ async ({ start_lat, start_lng, end_lat, end_lng, seat_count }) => {
868
+ const qs = new URLSearchParams({
869
+ start_lat: String(start_lat),
870
+ start_lng: String(start_lng),
871
+ end_lat: String(end_lat),
872
+ end_lng: String(end_lng)
873
+ });
874
+ if (seat_count) qs.set("seat_count", String(seat_count));
875
+ return runJson(`/au-rides/quote?${qs}`);
876
+ }
877
+ );
878
+ server.registerTool(
879
+ "rides_eta",
880
+ {
881
+ description: "Uber pickup ETA estimates only (no booking).",
882
+ inputSchema: {
883
+ start_lat: z.number(),
884
+ start_lng: z.number(),
885
+ product_id: z.string().optional()
886
+ }
887
+ },
888
+ async ({ start_lat, start_lng, product_id }) => {
889
+ const qs = new URLSearchParams({
890
+ start_lat: String(start_lat),
891
+ start_lng: String(start_lng)
892
+ });
893
+ if (product_id) qs.set("product_id", product_id);
894
+ return runJson(`/au-rides/eta?${qs}`);
895
+ }
896
+ );
897
+ server.registerTool(
898
+ "rides_products",
899
+ {
900
+ description: "Uber products available at a lat/lng (no booking).",
901
+ inputSchema: { lat: z.number(), lng: z.number() }
902
+ },
903
+ async ({ lat, lng }) => runJson(`/au-rides/products?lat=${encodeURIComponent(String(lat))}&lng=${encodeURIComponent(String(lng))}`)
904
+ );
905
+ server.registerTool(
906
+ "moneygram_status",
907
+ {
908
+ description: "MoneyGram funding status for pre-x402 wallet top-up. MoneyGram does NOT settle x402 \u2014 it funds USDC so you can pay. Demo UI: https://milypay.xyz/fund",
909
+ inputSchema: {}
910
+ },
911
+ async () => runJson(`/ramp/moneygram`)
912
+ );
913
+ server.registerTool(
914
+ "moneygram_session",
915
+ {
916
+ description: "Create a MoneyGram Ramps sandbox session. Returns widgetUrl + sessionToken. Open widget to on-ramp USDC into a Solana wallet, then retry paid x402 calls. mode=on-ramp (fund) or off-ramp (cash out).",
917
+ inputSchema: {
918
+ mode: z.enum(["on-ramp", "off-ramp"]).optional().describe("on-ramp (default) funds wallet; off-ramp cashes out")
919
+ }
920
+ },
921
+ async ({ mode }) => {
922
+ try {
923
+ return ok(
924
+ await postJson(
925
+ `/ramp/moneygram/session`,
926
+ { mode: mode || "on-ramp" },
927
+ opts()
928
+ )
929
+ );
930
+ } catch (e) {
931
+ return fail(e);
932
+ }
933
+ }
934
+ );
935
+ const transport = new StdioServerTransport();
936
+ await server.connect(transport);
937
+ }
223
938
 
224
939
  // src/index.ts
225
- var VERSION = "0.1.0";
226
940
  function parseArgs(argv) {
227
941
  const out = {
228
942
  _: [],
@@ -265,6 +979,7 @@ Usage:
265
979
  milypay <command> [args] [flags]
266
980
 
267
981
  Commands:
982
+ mcp Start MCP server (stdio) for Claude/Cursor
268
983
  services List endpoints + prices
269
984
  call <path> Raw path, e.g. /au-business/abn/51824753556
270
985
  abn <abn> Business by ABN
@@ -280,9 +995,24 @@ Commands:
280
995
  bsb search <query> Search BSBs
281
996
  postage --from <pc> --to <pc> --weight <kg> [--length --width --height]
282
997
  postage --country <cc> --weight <kg>
998
+ fund|moneygram [status|session] MoneyGram wallet funding (pre-x402)
999
+ domains check|quote <name> DNS availability / quote
1000
+ rides quote|eta|products \u2026 Uber estimates (quote-only)
283
1001
  whoami Show configured wallet
284
1002
  help This help
285
1003
 
1004
+ MCP (Claude / Cursor):
1005
+ {
1006
+ "mcpServers": {
1007
+ "milypay": {
1008
+ "command": "npx",
1009
+ "args": ["-y", "milypay", "mcp"],
1010
+ "env": { "MILYPAY_HOST": "demo" }
1011
+ }
1012
+ }
1013
+ }
1014
+ Paid: set MILYPAY_PRIVATE_KEY and MILYPAY_HOST=api
1015
+
286
1016
  Flags:
287
1017
  --demo Force free host (${DEMO_BASE})
288
1018
  --api Force paid host (${API_BASE}) \u2014 needs wallet
@@ -419,7 +1149,21 @@ async function cmdPostage(rest, args) {
419
1149
  print(await getJson(`/au-postage?${qs}`, clientOpts(args)), true);
420
1150
  }
421
1151
  async function main() {
422
- const args = parseArgs(process.argv.slice(2));
1152
+ const rawArgv = process.argv.slice(2);
1153
+ if (rawArgv[0] === "mcp") {
1154
+ for (let i = 1; i < rawArgv.length; i++) {
1155
+ if (rawArgv[i] === "--demo") process.env.MILYPAY_HOST = "demo";
1156
+ else if (rawArgv[i] === "--api") process.env.MILYPAY_HOST = "api";
1157
+ else if ((rawArgv[i] === "--base" || rawArgv[i] === "--base-url") && rawArgv[i + 1]) {
1158
+ process.env.MILYPAY_BASE_URL = rawArgv[++i];
1159
+ } else if (rawArgv[i] === "--rpc" && rawArgv[i + 1]) {
1160
+ process.env.SOLANA_RPC_URL = rawArgv[++i];
1161
+ }
1162
+ }
1163
+ await startMcpServer();
1164
+ return;
1165
+ }
1166
+ const args = parseArgs(rawArgv);
423
1167
  if (args.version) {
424
1168
  print(VERSION, false);
425
1169
  return;
@@ -495,6 +1239,205 @@ async function main() {
495
1239
  print({ address: w.address, source: w.source, api: API_BASE, demo: DEMO_BASE }, true);
496
1240
  break;
497
1241
  }
1242
+ case "abs": {
1243
+ const sub = String(args._[1] || "").toLowerCase();
1244
+ if (sub === "dataflows" || sub === "search" || sub === "list") {
1245
+ const q = args._.slice(2).join(" ");
1246
+ const qs = q ? `?q=${encodeURIComponent(q)}` : "";
1247
+ print(await getJson(`/au-abs/dataflows${qs}`, clientOpts(args)), args.json);
1248
+ break;
1249
+ }
1250
+ if (sub === "dataflow" || sub === "meta") {
1251
+ const id = String(args._[2] || "");
1252
+ if (!id) throw new Error("Usage: milypay abs dataflow <id>");
1253
+ print(await getJson(`/au-abs/dataflow/${encodeURIComponent(id)}`, clientOpts(args)), args.json);
1254
+ break;
1255
+ }
1256
+ if (sub === "data") {
1257
+ const flow = String(args._[2] || "");
1258
+ if (!flow) throw new Error("Usage: milypay abs data <dataflow> [--key k] [--start period]");
1259
+ let key = "";
1260
+ let start = "";
1261
+ const rest2 = args._.slice(3);
1262
+ for (let i = 0; i < rest2.length; i++) {
1263
+ if (rest2[i] === "--key") key = String(rest2[++i] || "");
1264
+ else if (rest2[i] === "--start") start = String(rest2[++i] || "");
1265
+ }
1266
+ const qs = new URLSearchParams();
1267
+ if (key) qs.set("key", key);
1268
+ if (start) qs.set("startPeriod", start);
1269
+ if (!key && !start) qs.set("startPeriod", "2020");
1270
+ const q = qs.toString();
1271
+ print(await getJson(`/au-abs/data/${encodeURIComponent(flow)}${q ? `?${q}` : ""}`, clientOpts(args)), args.json);
1272
+ break;
1273
+ }
1274
+ throw new Error("Usage: milypay abs dataflows|dataflow|data \u2026");
1275
+ }
1276
+ case "cpi": {
1277
+ const start = args._[1] ? String(args._[1]) : "";
1278
+ const qs = start ? `?startPeriod=${encodeURIComponent(start)}` : "";
1279
+ print(await getJson(`/au-abs/cpi${qs}`, clientOpts(args)), args.json);
1280
+ break;
1281
+ }
1282
+ case "transit": {
1283
+ const sub = String(args._[1] || "").toLowerCase();
1284
+ if (sub === "regions" || sub === "list") {
1285
+ print(await getJson(`/au-transit/regions`, clientOpts(args)), args.json);
1286
+ break;
1287
+ }
1288
+ const region = sub;
1289
+ const feedRaw = String(args._[2] || "summary").toLowerCase();
1290
+ const feed = feedRaw === "trips" || feedRaw === "trip" || feedRaw === "trip-updates" ? "trip-updates" : feedRaw === "vehicle" || feedRaw === "vehicles" ? "vehicles" : feedRaw === "alert" || feedRaw === "alerts" ? "alerts" : feedRaw === "summary" ? "summary" : feedRaw;
1291
+ if (!region) throw new Error("Usage: milypay transit regions | transit <seq|sa|vic|nsw> vehicles|trips|alerts|summary [--mode m]");
1292
+ let route = "";
1293
+ let stop = "";
1294
+ let limit = "";
1295
+ let mode = "";
1296
+ const rest2 = args._.slice(3);
1297
+ for (let i = 0; i < rest2.length; i++) {
1298
+ if (rest2[i] === "--route") route = String(rest2[++i] || "");
1299
+ else if (rest2[i] === "--stop") stop = String(rest2[++i] || "");
1300
+ else if (rest2[i] === "--limit") limit = String(rest2[++i] || "");
1301
+ else if (rest2[i] === "--mode") mode = String(rest2[++i] || "");
1302
+ }
1303
+ const qs = new URLSearchParams();
1304
+ if (route) qs.set("routeId", route);
1305
+ if (stop) qs.set("stopId", stop);
1306
+ if (limit) qs.set("limit", limit);
1307
+ if (mode) qs.set("mode", mode);
1308
+ const q = qs.toString();
1309
+ print(
1310
+ await getJson(`/au-transit/${encodeURIComponent(region)}/${feed}${q ? `?${q}` : ""}`, clientOpts(args)),
1311
+ args.json
1312
+ );
1313
+ break;
1314
+ }
1315
+ case "energy":
1316
+ case "nem": {
1317
+ const sub = String(args._[1] || "").toLowerCase();
1318
+ if (sub === "notices" || sub === "notice") {
1319
+ const lim = args._[2] != null ? String(args._[2]) : "";
1320
+ const q = lim ? `?limit=${encodeURIComponent(lim)}` : "";
1321
+ print(await getJson(`/au-energy/notices${q}`, clientOpts(args)), args.json);
1322
+ break;
1323
+ }
1324
+ if (!sub || sub === "all" || sub === "summary") {
1325
+ print(await getJson(`/au-energy/nem`, clientOpts(args)), args.json);
1326
+ break;
1327
+ }
1328
+ print(await getJson(`/au-energy/nem/${encodeURIComponent(sub)}`, clientOpts(args)), args.json);
1329
+ break;
1330
+ }
1331
+ case "phone":
1332
+ case "lookup-phone": {
1333
+ const num = String(args._[1] || "");
1334
+ if (!num) throw new Error("Usage: milypay phone +614****5678 (or 0412345678)");
1335
+ print(await getJson(`/au-phone?number=${encodeURIComponent(num)}`, clientOpts(args)), args.json);
1336
+ break;
1337
+ }
1338
+ case "domains":
1339
+ case "domain": {
1340
+ const sub = String(args._[1] || "check").toLowerCase();
1341
+ const name = String(args._[2] || args._[1] || "");
1342
+ if (sub === "check" || sub.includes(".") && !["check", "quote", "register"].includes(sub)) {
1343
+ const n = sub.includes(".") ? sub : name;
1344
+ if (!n || !n.includes(".")) throw new Error("Usage: milypay domains check example.com");
1345
+ print(await getJson(`/domains/check?name=${encodeURIComponent(n)}`, clientOpts(args)), args.json);
1346
+ break;
1347
+ }
1348
+ if (sub === "quote") {
1349
+ if (!name.includes(".")) throw new Error("Usage: milypay domains quote example.com [years]");
1350
+ const years = args._[3] || "1";
1351
+ print(await getJson(`/domains/quote?name=${encodeURIComponent(name)}&years=${encodeURIComponent(String(years))}`, clientOpts(args)), args.json);
1352
+ break;
1353
+ }
1354
+ if (sub === "register") {
1355
+ throw new Error("Register via paid API: POST /domains/register with x402 for quote chargeUsd");
1356
+ }
1357
+ throw new Error("Usage: milypay domains check|quote <name>");
1358
+ }
1359
+ case "rides":
1360
+ case "ride":
1361
+ case "uber": {
1362
+ const sub = String(args._[1] || "quote").toLowerCase();
1363
+ if (sub === "products") {
1364
+ const lat = args._[2];
1365
+ const lng = args._[3];
1366
+ if (lat == null || lng == null) {
1367
+ throw new Error("Usage: milypay rides products <lat> <lng>");
1368
+ }
1369
+ print(
1370
+ await getJson(
1371
+ `/au-rides/products?lat=${encodeURIComponent(String(lat))}&lng=${encodeURIComponent(String(lng))}`,
1372
+ clientOpts(args)
1373
+ ),
1374
+ args.json
1375
+ );
1376
+ break;
1377
+ }
1378
+ if (sub === "eta") {
1379
+ const slat = args._[2];
1380
+ const slng = args._[3];
1381
+ if (slat == null || slng == null) {
1382
+ throw new Error("Usage: milypay rides eta <start_lat> <start_lng>");
1383
+ }
1384
+ print(
1385
+ await getJson(
1386
+ `/au-rides/eta?start_lat=${encodeURIComponent(String(slat))}&start_lng=${encodeURIComponent(String(slng))}`,
1387
+ clientOpts(args)
1388
+ ),
1389
+ args.json
1390
+ );
1391
+ break;
1392
+ }
1393
+ const off = sub === "quote" ? 2 : 1;
1394
+ const startLat = args._[off];
1395
+ const startLng = args._[off + 1];
1396
+ const endLat = args._[off + 2];
1397
+ const endLng = args._[off + 3];
1398
+ if (startLat == null || startLng == null || endLat == null || endLng == null) {
1399
+ throw new Error(
1400
+ "Usage: milypay rides quote <start_lat> <start_lng> <end_lat> <end_lng>"
1401
+ );
1402
+ }
1403
+ const qs = new URLSearchParams({
1404
+ start_lat: String(startLat),
1405
+ start_lng: String(startLng),
1406
+ end_lat: String(endLat),
1407
+ end_lng: String(endLng)
1408
+ });
1409
+ print(await getJson(`/au-rides/quote?${qs}`, clientOpts(args)), args.json);
1410
+ break;
1411
+ }
1412
+ case "fund":
1413
+ case "moneygram":
1414
+ case "ramp":
1415
+ case "mg": {
1416
+ const sub = String(args._[1] || "status").toLowerCase();
1417
+ if (sub === "status" || sub === "info" || sub === "catalogue") {
1418
+ print(await getJson(`/ramp/moneygram`, clientOpts(args)), args.json);
1419
+ break;
1420
+ }
1421
+ if (sub === "session" || sub === "on" || sub === "on-ramp" || sub === "onramp" || sub === "off" || sub === "off-ramp" || sub === "offramp") {
1422
+ let mode = "on-ramp";
1423
+ if (sub === "off" || sub === "off-ramp" || sub === "offramp") mode = "off-ramp";
1424
+ const modeArg = String(args._[2] || "").toLowerCase();
1425
+ if (modeArg === "off" || modeArg === "off-ramp" || modeArg === "offramp") mode = "off-ramp";
1426
+ if (modeArg === "on" || modeArg === "on-ramp" || modeArg === "onramp") mode = "on-ramp";
1427
+ if (sub === "on" || sub === "on-ramp" || sub === "onramp") mode = "on-ramp";
1428
+ const data = await postJson(`/ramp/moneygram/session`, { mode }, clientOpts(args));
1429
+ print(data, args.json);
1430
+ const widget = data.widgetUrl;
1431
+ if (widget && !args.quiet) {
1432
+ process.stderr.write(`
1433
+ Open widget: ${widget}
1434
+ Demo UI: https://milypay.xyz/fund
1435
+ `);
1436
+ }
1437
+ break;
1438
+ }
1439
+ throw new Error("Usage: milypay fund status|session [on-ramp|off-ramp]");
1440
+ }
498
1441
  default:
499
1442
  throw new Error(`Unknown command: ${cmd}
500
1443