agentcash 0.3.5 → 0.3.7

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.
@@ -2,24 +2,22 @@ import {
2
2
  buildRequest,
3
3
  createFetchWithPayment,
4
4
  requestSchema
5
- } from "./chunk-NUYR6S4R.js";
5
+ } from "./chunk-7E4JDDBW.js";
6
6
  import {
7
+ TEMPO_RPC_URL,
7
8
  checkEndpoint,
8
9
  detectPaymentProtocols,
9
10
  discoverResources,
10
11
  getInputSchema,
11
- getOriginIndex,
12
12
  getSiwxExtension,
13
13
  getTempoBalance,
14
- getTempoChainId,
15
- getTempoRpcUrl,
16
14
  getWalletInfo,
17
15
  safeCreateSIWxPayload,
18
16
  safeGetMppChallenge,
19
17
  safeGetPaymentRequired,
20
18
  submitErrorReport
21
- } from "./chunk-LDXTW6MC.js";
22
- import "./chunk-LXLFCKRE.js";
19
+ } from "./chunk-RP5AGYAT.js";
20
+ import "./chunk-SBLBP4FH.js";
23
21
  import {
24
22
  DEFAULT_NETWORK,
25
23
  getWallet,
@@ -52,7 +50,9 @@ import { randomBytes } from "crypto";
52
50
  import { z } from "zod";
53
51
  import { x402Client, x402HTTPClient } from "@x402/core/client";
54
52
  import { ExactEvmScheme } from "@x402/evm/exact/client";
55
- import { Mpay, tempo } from "mpay/client";
53
+ import { Mppx, tempo as tempoMethod } from "mppx/client";
54
+ import { createClient, http } from "viem";
55
+ import { tempo } from "viem/chains";
56
56
 
57
57
  // src/server/tools/response/lib.ts
58
58
  var parsedResponseToToolContentPart = (data) => {
@@ -124,8 +124,8 @@ var mcpError = async (err2) => {
124
124
  }
125
125
  return mcpErrorJson({ ...error });
126
126
  };
127
- var mcpErrorFetch = async (surface3, response) => {
128
- return mcpError(fetchHttpErr(surface3, response));
127
+ var mcpErrorFetch = async (surface2, response) => {
128
+ return mcpError(fetchHttpErr(surface2, response));
129
129
  };
130
130
 
131
131
  // src/server/tools/response/success.ts
@@ -168,9 +168,9 @@ var checkBalance = async ({
168
168
  amountNeeded,
169
169
  message,
170
170
  flags,
171
- surface: surface3
171
+ surface: surface2
172
172
  }) => {
173
- const balanceResult = await getBalance({ address, flags, surface: surface3 });
173
+ const balanceResult = await getBalance({ address, flags, surface: surface2 });
174
174
  if (balanceResult.isErr()) {
175
175
  log.error(JSON.stringify(balanceResult.error, null, 2));
176
176
  return;
@@ -274,11 +274,12 @@ var registerFetchTool = ({
274
274
  ]
275
275
  });
276
276
  const x402HttpClient = new x402HTTPClient(coreClient);
277
- const mpayClient = Mpay.create({
277
+ const mppxClient = Mppx.create({
278
+ polyfill: false,
278
279
  methods: [
279
- tempo({
280
+ tempoMethod({
280
281
  account,
281
- rpcUrl: { [getTempoChainId()]: getTempoRpcUrl() }
282
+ getClient: () => createClient({ chain: tempo, transport: http(TEMPO_RPC_URL) })
282
283
  })
283
284
  ]
284
285
  });
@@ -313,7 +314,7 @@ var registerFetchTool = ({
313
314
  });
314
315
  const fetchResult = await createFetchWithPayment({
315
316
  surface: toolName,
316
- clients: { x402: x402HttpClient, mpp: mpayClient },
317
+ clients: { x402: x402HttpClient, mpp: mppxClient },
317
318
  paymentMethod,
318
319
  account,
319
320
  flags,
@@ -504,7 +505,7 @@ var registerCheckEndpointTool = ({
504
505
  toolName3,
505
506
  {
506
507
  title: "Check Endpoint Schema",
507
- description: `Probe endpoint to check if payment-protected. By default checks all HTTP methods (GET, POST, PUT, DELETE, PATCH) in parallel. Returns pricing, input schema, and payment methods for each method that responds with 402 or 2xx. Use before fetch to preview costs. No payment made.`,
508
+ description: `Probe endpoint to check if payment-protected. By default checks only the HTTP methods declared in the endpoint's OpenAPI spec (falls back to all methods if no spec is available). Returns pricing, input schema, and payment methods for each method that responds with 402 or 2xx. Use before fetch to preview costs. No payment made.`,
508
509
  inputSchema: checkEndpointInputSchema,
509
510
  annotations: {
510
511
  readOnlyHint: true,
@@ -754,40 +755,45 @@ function registerDiscoveryTools(server) {
754
755
  import z7 from "zod";
755
756
  import { x402HTTPClient as x402HTTPClient3 } from "@x402/core/client";
756
757
  import { x402Client as x402Client3 } from "@x402/core/client";
757
-
758
- // src/server/resources/_lib.ts
759
- var surface = "getWebPageMetadata";
760
- var getWebPageMetadata = (url) => {
761
- return safeFetch(surface, new Request(url)).andThen((response) => safeParseResponse(surface, response)).andThen((parsedResponse) => {
762
- if (parsedResponse.type === "text") {
763
- return ok(parseMetadataFromResponse(parsedResponse.data));
764
- }
765
- return err("user", surface, {
766
- cause: "invalid_response_type",
767
- message: "Invalid response type"
768
- });
769
- });
770
- };
771
- var parseMetadataFromResponse = (html) => {
772
- const titleMatch = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
773
- const title = titleMatch ? titleMatch[1].trim().replace(/\s+/g, " ") : null;
774
- let descriptionMatch = /<meta\s+name=["']description["']\s+content=["']([^"']*)["']/i.exec(html);
775
- descriptionMatch ??= /<meta\s+property=["']og:description["']\s+content=["']([^"']*)["']/i.exec(
776
- html
777
- );
778
- descriptionMatch ??= /<meta\s+content=["']([^"']*)["']\s+name=["']description["']/i.exec(html);
779
- descriptionMatch ??= /<meta\s+content=["']([^"']*)["']\s+property=["']og:description["']/i.exec(
780
- html
781
- );
782
- const description = descriptionMatch ? descriptionMatch[1].trim().replace(/\s+/g, " ") : null;
783
- return {
784
- title,
785
- description
786
- };
758
+ var ORIGIN_METADATA = {
759
+ ["https://enrichx402.com" /* EnrichX402 */]: {
760
+ title: "EnrichX402",
761
+ description: "People/org search, Google Maps, Grok twitter search, Exa web search, LinkedIn data, Firecrawl scrape, WhitePages, email enrichment"
762
+ },
763
+ ["https://socialx402.com" /* SocialX402 */]: {
764
+ title: "SocialX402",
765
+ description: "Social media data for Twitter, Instagram, TikTok, YouTube, Facebook, Reddit"
766
+ },
767
+ ["https://stablestudio.io" /* StableStudio */]: {
768
+ title: "StableStudio",
769
+ description: "Generate and edit images and videos"
770
+ },
771
+ ["https://agentupload.dev" /* AgentUpload */]: {
772
+ title: "AgentUpload",
773
+ description: "Upload and share files"
774
+ },
775
+ ["https://x402email.com" /* X402Email */]: {
776
+ title: "X402 Email",
777
+ description: "Send emails"
778
+ },
779
+ ["https://x402scan.com" /* X402Scan */]: {
780
+ title: "X402 Scan",
781
+ description: "x402 protocol explorer"
782
+ },
783
+ ["https://shirt.sh" /* Shirt */]: {
784
+ title: "Shirt",
785
+ description: "Shirt.sh"
786
+ },
787
+ ["https://x402puppet.com" /* X402Puppet */]: {
788
+ title: "X402 Puppet",
789
+ description: "Browser automation"
790
+ },
791
+ ["https://x402facilitator.com" /* X402Facilitator */]: {
792
+ title: "X402 Facilitator",
793
+ description: "Payment facilitation"
794
+ }
787
795
  };
788
-
789
- // src/server/resources/origins.ts
790
- var surface2 = "registerOrigins";
796
+ var surface = "registerOrigins";
791
797
  var wellKnownResourceItem = z7.union([
792
798
  z7.string(),
793
799
  z7.object({
@@ -799,170 +805,167 @@ var wellKnownResourceItem = z7.union([
799
805
  var wellKnownSchema = z7.object({
800
806
  resources: z7.array(wellKnownResourceItem)
801
807
  });
802
- var registerOrigins = async ({ server }) => {
803
- await Promise.all(
804
- ORIGINS.map(async (origin) => {
805
- const domain = new URL(origin).hostname;
806
- const metadataResult = await getWebPageMetadata(origin);
807
- const metadata = metadataResult.isOk() ? metadataResult.value : null;
808
- server.registerResource(
809
- domain,
810
- `api://${domain}`,
811
- {
812
- title: metadata?.title ?? origin,
813
- description: metadata?.description ?? "",
814
- mimeType: "application/json"
815
- },
816
- async (uri) => {
817
- const baseUrl = uri.toString().replace("api://", "https://");
818
- const [x402WellKnown, mppWellKnown] = await Promise.all([
819
- safeFetchJson(
820
- surface2,
821
- new Request(`${baseUrl}/.well-known/x402`),
822
- wellKnownSchema
823
- ),
824
- safeFetchJson(
825
- surface2,
826
- new Request(`${baseUrl}/.well-known/mpp`),
827
- wellKnownSchema
828
- )
829
- ]);
830
- const allResourceUrls = /* @__PURE__ */ new Set();
831
- const addResource = (r) => {
832
- if (typeof r === "string") {
833
- allResourceUrls.add(r);
834
- return;
835
- }
836
- const url = r.path ? `${baseUrl}${r.path}` : r.url ?? "";
837
- if (url) allResourceUrls.add(url);
838
- };
839
- if (x402WellKnown.isOk()) {
840
- for (const r of x402WellKnown.value.resources) {
841
- addResource(r);
842
- }
808
+ var registerOrigins = ({ server }) => {
809
+ for (const origin of ORIGINS) {
810
+ const domain = new URL(origin).hostname;
811
+ const metadata = ORIGIN_METADATA[origin];
812
+ server.registerResource(
813
+ domain,
814
+ `api://${domain}`,
815
+ {
816
+ title: metadata?.title ?? domain,
817
+ description: metadata?.description ?? "",
818
+ mimeType: "application/json"
819
+ },
820
+ async (uri) => {
821
+ const baseUrl = uri.toString().replace("api://", "https://");
822
+ const [x402WellKnown, mppWellKnown] = await Promise.all([
823
+ safeFetchJson(
824
+ surface,
825
+ new Request(`${baseUrl}/.well-known/x402`),
826
+ wellKnownSchema
827
+ ),
828
+ safeFetchJson(
829
+ surface,
830
+ new Request(`${baseUrl}/.well-known/mpp`),
831
+ wellKnownSchema
832
+ )
833
+ ]);
834
+ const allResourceUrls = /* @__PURE__ */ new Set();
835
+ const addResource = (r) => {
836
+ if (typeof r === "string") {
837
+ allResourceUrls.add(r);
838
+ return;
843
839
  }
844
- if (mppWellKnown.isOk()) {
845
- for (const r of mppWellKnown.value.resources) {
846
- addResource(r);
847
- }
840
+ const url = r.path ? `${baseUrl}${r.path}` : r.url ?? "";
841
+ if (url) allResourceUrls.add(url);
842
+ };
843
+ if (x402WellKnown.isOk()) {
844
+ for (const r of x402WellKnown.value.resources) {
845
+ addResource(r);
848
846
  }
849
- if (allResourceUrls.size === 0) {
850
- console.error(
851
- `Failed to fetch well-known for ${origin}:`,
852
- x402WellKnown.isErr() ? x402WellKnown.error : "no x402",
853
- mppWellKnown.isErr() ? mppWellKnown.error : "no mpp"
854
- );
855
- return {
856
- contents: [
857
- {
858
- uri: domain,
859
- text: JSON.stringify(
860
- { error: "Failed to fetch well-known resources" },
861
- null,
862
- 2
863
- ),
864
- mimeType: "application/json"
865
- }
866
- ]
867
- };
847
+ }
848
+ if (mppWellKnown.isOk()) {
849
+ for (const r of mppWellKnown.value.resources) {
850
+ addResource(r);
868
851
  }
869
- const resources = await Promise.all(
870
- Array.from(allResourceUrls).map(async (resource) => {
871
- const postResult = await getResourceResponse(
872
- resource,
873
- new Request(resource, {
874
- method: "POST",
875
- headers: {
876
- "Content-Type": "application/json"
877
- }
878
- })
879
- );
880
- if (postResult.isOk()) {
881
- return postResult.value;
882
- }
883
- const getResult = await getResourceResponse(
884
- resource,
885
- new Request(resource, { method: "GET" })
886
- );
887
- if (getResult.isOk()) {
888
- return getResult.value;
889
- }
890
- console.error(`Failed to get resource response for ${resource}`);
891
- return null;
892
- })
852
+ }
853
+ if (allResourceUrls.size === 0) {
854
+ console.error(
855
+ `Failed to fetch well-known for ${origin}:`,
856
+ x402WellKnown.isErr() ? x402WellKnown.error : "no x402",
857
+ mppWellKnown.isErr() ? mppWellKnown.error : "no mpp"
893
858
  );
894
- const payload = {
895
- server: origin,
896
- name: metadata?.title,
897
- description: metadata?.description,
898
- resources: resources.filter(Boolean).map((resource) => {
899
- if (!resource) return null;
900
- const entry = {
901
- url: resource.resource,
902
- protocols: resource.protocols
903
- };
904
- if (resource.mpp) {
905
- entry.mpp = {
906
- method: resource.mpp.method,
907
- intent: resource.mpp.intent
908
- };
909
- }
910
- if (resource.x402) {
911
- const schema = getInputSchema(resource.x402.extensions);
912
- entry.x402 = {
913
- schema,
914
- mimeType: resource.x402.mimeType
915
- };
859
+ return {
860
+ contents: [
861
+ {
862
+ uri: domain,
863
+ text: JSON.stringify(
864
+ { error: "Failed to fetch well-known resources" },
865
+ null,
866
+ 2
867
+ ),
868
+ mimeType: "application/json"
916
869
  }
917
- return entry;
918
- })
870
+ ]
919
871
  };
920
- const stringifyResult = safeStringifyJson(
921
- surface2,
922
- payload
923
- );
924
- if (stringifyResult.isErr()) {
925
- console.error(
926
- `Failed to stringify response for ${origin}:`,
927
- stringifyResult.error
928
- );
929
- return {
930
- contents: [
931
- {
932
- uri: domain,
933
- text: JSON.stringify({
934
- error: "Failed to stringify response"
935
- }),
936
- mimeType: "application/json"
872
+ }
873
+ const resources = await Promise.all(
874
+ Array.from(allResourceUrls).map(async (resource) => {
875
+ const postResult = await getResourceResponse(
876
+ resource,
877
+ new Request(resource, {
878
+ method: "POST",
879
+ headers: {
880
+ "Content-Type": "application/json"
937
881
  }
938
- ]
882
+ })
883
+ );
884
+ if (postResult.isOk()) {
885
+ return postResult.value;
886
+ }
887
+ const getResult = await getResourceResponse(
888
+ resource,
889
+ new Request(resource, { method: "GET" })
890
+ );
891
+ if (getResult.isOk()) {
892
+ return getResult.value;
893
+ }
894
+ console.error(`Failed to get resource response for ${resource}`);
895
+ return null;
896
+ })
897
+ );
898
+ const payload = {
899
+ server: origin,
900
+ name: metadata?.title,
901
+ description: metadata?.description,
902
+ resources: resources.filter(Boolean).map((resource) => {
903
+ if (!resource) return null;
904
+ const entry = {
905
+ url: resource.resource,
906
+ protocols: resource.protocols
939
907
  };
940
- }
908
+ if (resource.mpp) {
909
+ entry.mpp = {
910
+ method: resource.mpp.method,
911
+ intent: resource.mpp.intent
912
+ };
913
+ }
914
+ if (resource.x402) {
915
+ const schema = getInputSchema(resource.x402.extensions);
916
+ entry.x402 = {
917
+ schema,
918
+ mimeType: resource.x402.mimeType
919
+ };
920
+ }
921
+ return entry;
922
+ })
923
+ };
924
+ const stringifyResult = safeStringifyJson(
925
+ surface,
926
+ payload
927
+ );
928
+ if (stringifyResult.isErr()) {
929
+ console.error(
930
+ `Failed to stringify response for ${origin}:`,
931
+ stringifyResult.error
932
+ );
941
933
  return {
942
934
  contents: [
943
935
  {
944
936
  uri: domain,
945
- text: stringifyResult.value,
937
+ text: JSON.stringify({
938
+ error: "Failed to stringify response"
939
+ }),
946
940
  mimeType: "application/json"
947
941
  }
948
942
  ]
949
943
  };
950
944
  }
951
- );
952
- })
953
- );
945
+ return {
946
+ contents: [
947
+ {
948
+ uri: domain,
949
+ text: stringifyResult.value,
950
+ mimeType: "application/json"
951
+ }
952
+ ]
953
+ };
954
+ }
955
+ );
956
+ }
954
957
  };
955
958
  var getResourceResponse = async (resource, request) => {
956
- const fetchResult = await safeFetch(surface2, request);
959
+ const fetchResult = await safeFetch(surface, request);
957
960
  if (fetchResult.isErr()) {
958
- return err("fetch", surface2, {
961
+ return err("fetch", surface, {
959
962
  cause: "network",
960
963
  message: `Failed to fetch resource: ${resource}`
961
964
  });
962
965
  }
963
966
  const response = fetchResult.value;
964
967
  if (response.status !== 402) {
965
- return err("fetch", surface2, {
968
+ return err("fetch", surface, {
966
969
  cause: "not_402",
967
970
  message: `Resource did not return 402: ${resource}`
968
971
  });
@@ -971,7 +974,7 @@ var getResourceResponse = async (resource, request) => {
971
974
  let mppInfo = null;
972
975
  let x402Info = null;
973
976
  if (protocols.includes("mpp")) {
974
- const challengeResult = safeGetMppChallenge(surface2, response);
977
+ const challengeResult = safeGetMppChallenge(surface, response);
975
978
  if (challengeResult.isOk()) {
976
979
  const challenge = challengeResult.value;
977
980
  mppInfo = { method: challenge.method, intent: challenge.intent };
@@ -980,7 +983,7 @@ var getResourceResponse = async (resource, request) => {
980
983
  if (protocols.includes("x402")) {
981
984
  const client = new x402HTTPClient3(new x402Client3());
982
985
  const paymentRequiredResult = await safeGetPaymentRequired(
983
- surface2,
986
+ surface,
984
987
  client,
985
988
  response
986
989
  );
@@ -993,7 +996,7 @@ var getResourceResponse = async (resource, request) => {
993
996
  }
994
997
  }
995
998
  if (!mppInfo && !x402Info) {
996
- return err("parse", surface2, {
999
+ return err("parse", surface, {
997
1000
  cause: "parse_failed",
998
1001
  message: `Failed to parse any payment protocol for: ${resource}`
999
1002
  });
@@ -1224,7 +1227,7 @@ import { dirname, join } from "path";
1224
1227
  import { fileURLToPath } from "url";
1225
1228
  function getVersion() {
1226
1229
  if (true) {
1227
- return "0.3.5";
1230
+ return "0.3.7";
1228
1231
  }
1229
1232
  const __dirname2 = dirname(fileURLToPath(import.meta.url));
1230
1233
  const pkg = JSON.parse(
@@ -1236,42 +1239,18 @@ var MCP_VERSION = getVersion();
1236
1239
  var DIST_TAG = MCP_VERSION.includes("-beta") ? "beta" : "latest";
1237
1240
 
1238
1241
  // src/server/lib/instructions.ts
1239
- async function buildServerInstructions() {
1240
- const sections = [];
1241
- for (const origin of ORIGINS) {
1242
- const indexResult = await resultFromPromise(
1243
- "openapi",
1244
- "buildServerInstructions",
1245
- getOriginIndex(origin),
1246
- () => ({
1247
- cause: "index_fetch",
1248
- message: `Failed to build index for origin: ${origin}`
1249
- })
1250
- );
1251
- if (indexResult.isErr()) {
1252
- log.debug(`Failed to build index for origin: ${origin}`);
1253
- continue;
1254
- }
1255
- const index = indexResult.value;
1256
- if (!index || index.length === 0) continue;
1257
- const domain = new URL(origin).hostname;
1258
- const lines = index.map(
1259
- (e) => ` ${e.method} ${e.path} \u2014 ${e.summary}${e.price ? ` (${e.price})` : ""}`
1260
- );
1261
- sections.push(`${domain}:
1262
- ${lines.join("\n")}`);
1263
- }
1264
- if (sections.length === 0) return "";
1265
- return [
1266
- "Available APIs:",
1267
- "",
1268
- ...sections,
1269
- "",
1270
- "Workflow:",
1271
- "1. Use check_endpoint_schema to get the full input schema for an endpoint before calling it.",
1272
- "2. Use fetch to make the request (handles payment automatically).",
1273
- "3. For APIs not listed above, use discover_api_endpoints first to find available endpoints."
1274
- ].join("\n");
1242
+ function buildServerInstructions() {
1243
+ return `Known API origins:
1244
+ - ${"https://enrichx402.com" /* EnrichX402 */} \u2014 People/org search, Google Maps, Grok twitter search, Exa web search, LinkedIn data, Firecrawl scrape, WhitePages, email enrichment, Hunter email verifier
1245
+ - ${"https://socialx402.com" /* SocialX402 */} \u2014 Social media data (Twitter, Instagram, TikTok, YouTube, Facebook, Reddit)
1246
+ - ${"https://stablestudio.io" /* StableStudio */} \u2014 Generate and edit images/videos
1247
+ - ${"https://agentupload.dev" /* AgentUpload */} \u2014 Upload and share files
1248
+ - ${"https://x402email.com" /* X402Email */} \u2014 Send emails
1249
+
1250
+ Workflow:
1251
+ 1. Use discover_api_endpoints to find available endpoints on an origin.
1252
+ 2. Use check_endpoint_schema to get the full input schema + pricing for an endpoint.
1253
+ 3. Use fetch to make the request (handles payment automatically).`;
1275
1254
  }
1276
1255
 
1277
1256
  // src/server/index.ts
@@ -1296,7 +1275,7 @@ var startServer = async (flags) => {
1296
1275
  surface: "startServer"
1297
1276
  });
1298
1277
  }
1299
- const instructions = await buildServerInstructions();
1278
+ const instructions = buildServerInstructions();
1300
1279
  const server = new McpServer(
1301
1280
  {
1302
1281
  name: "agentcash",
@@ -1345,4 +1324,4 @@ var startServer = async (flags) => {
1345
1324
  export {
1346
1325
  startServer
1347
1326
  };
1348
- //# sourceMappingURL=server-SCEZADBF.js.map
1327
+ //# sourceMappingURL=server-BEKXJWYB.js.map