mcp-server-agentpay 1.0.3 → 1.0.4

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.
Files changed (3) hide show
  1. package/index.js +20 -5
  2. package/package.json +3 -2
  3. package/server.json +2 -2
package/index.js CHANGED
@@ -14,11 +14,19 @@ const BASE_URL = (process.env.AGENTPAY_URL || "https://agentpay.metaltorque.dev"
14
14
 
15
15
  // ── HTTP helper ─────────────────────────────────────────────────────
16
16
 
17
+ const MAX_RESPONSE_SIZE = 5 * 1024 * 1024; // 5MB
18
+
17
19
  function request(method, urlPath, body, timeout = 120_000) {
18
20
  return new Promise((resolve, reject) => {
19
21
  const fullUrl = `${BASE_URL}${urlPath}`;
20
- const mod = fullUrl.startsWith("https") ? https : http;
21
22
  const parsed = new URL(fullUrl);
23
+ const isHttps = parsed.protocol === "https:";
24
+
25
+ if (!isHttps && GATEWAY_KEY) {
26
+ return reject(new Error("Refusing to send gateway key over insecure HTTP. Use HTTPS."));
27
+ }
28
+
29
+ const mod = isHttps ? https : http;
22
30
 
23
31
  const headers = {
24
32
  "Content-Type": "application/json",
@@ -28,7 +36,7 @@ function request(method, urlPath, body, timeout = 120_000) {
28
36
 
29
37
  const opts = {
30
38
  hostname: parsed.hostname,
31
- port: parsed.port || (parsed.protocol === "https:" ? 443 : 80),
39
+ port: parsed.port || (isHttps ? 443 : 80),
32
40
  path: parsed.pathname + parsed.search,
33
41
  method,
34
42
  headers,
@@ -37,7 +45,12 @@ function request(method, urlPath, body, timeout = 120_000) {
37
45
 
38
46
  const req = mod.request(opts, (res) => {
39
47
  let data = "";
40
- res.on("data", (c) => (data += c));
48
+ let size = 0;
49
+ res.on("data", (c) => {
50
+ size += c.length;
51
+ if (size > MAX_RESPONSE_SIZE) { req.destroy(); return reject(new Error("Response too large")); }
52
+ data += c;
53
+ });
41
54
  res.on("end", () => {
42
55
  try {
43
56
  const json = JSON.parse(data);
@@ -142,7 +155,9 @@ server.tool(
142
155
  try { params = JSON.parse(params_json); } catch { return { content: [{ type: "text", text: "Error: params_json must be valid JSON" }] }; }
143
156
  }
144
157
  const result = await request("POST", "/gateway/call", { tool, method, params }, 600_000);
145
- const meta = `[Cost: $${(result.cost || 0).toFixed(2)} | Balance: $${(result.balance || 0).toFixed(2)} | Time: ${result.elapsed || 0}ms]`;
158
+ const cost = Number(result.cost) || 0;
159
+ const balance = Number(result.balance) || 0;
160
+ const meta = `[Cost: $${cost.toFixed(2)} | Balance: $${balance.toFixed(2)} | Time: ${result.elapsed || 0}ms]`;
146
161
  return {
147
162
  content: [{ type: "text", text: `${meta}\n\n${JSON.stringify(result.result, null, 2)}` }],
148
163
  };
@@ -177,7 +192,7 @@ server.tool(
177
192
  "get_usage",
178
193
  "View your recent tool call history — which tools you called, what methods, how much each cost, and when.",
179
194
  {
180
- limit: z.number().default(20).describe("Number of recent calls to show (default: 20, max: 200)"),
195
+ limit: z.number().int().min(1).max(200).default(20).describe("Number of recent calls to show (default: 20, max: 200)"),
181
196
  },
182
197
  async ({ limit }) => {
183
198
  if (!GATEWAY_KEY) return noKeyError();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-server-agentpay",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "mcpName": "io.github.joepangallo/agent-pay",
5
5
  "description": "MCP server for AgentPay — the payment gateway for autonomous AI agents. Lets agents discover, provision, and pay for MCP tool APIs with a single gateway key.",
6
6
  "bin": {
@@ -44,7 +44,8 @@
44
44
  "url": "https://github.com/joepangallo/agent-pay"
45
45
  },
46
46
  "dependencies": {
47
- "@modelcontextprotocol/sdk": "^1.27.0"
47
+ "@modelcontextprotocol/sdk": "^1.27.0",
48
+ "zod": "^3.23.0"
48
49
  },
49
50
  "engines": {
50
51
  "node": ">=18"
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/joepangallo/agent-pay",
7
7
  "source": "github"
8
8
  },
9
- "version": "1.0.3",
9
+ "version": "1.0.4",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-server-agentpay",
14
- "version": "1.0.3",
14
+ "version": "1.0.4",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },