mcp-server-agentpay 1.1.1 → 1.1.2
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/README.md +41 -40
- package/core.js +625 -0
- package/index.js +10 -493
- package/package.json +4 -4
- package/server.json +5 -5
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# mcp-server-agentpay
|
|
2
2
|
|
|
3
|
-
<a href="https://glama.ai/mcp/servers/@joepangallo/mcp-server-agentpay"><img width="380" height="200" src="https://glama.ai/mcp/servers/@joepangallo/mcp-server-agentpay/badge" alt="AgentPay MCP server" /></a>
|
|
4
|
-
|
|
5
3
|
MCP server for **AgentPay** — the payment gateway for autonomous AI agents.
|
|
6
4
|
|
|
7
|
-
Fund a wallet once, give your agent the key, and it discovers, provisions, and pays for tool APIs on its own.
|
|
5
|
+
Fund a wallet once, give your agent the key, and it discovers, provisions, and pays for tool APIs on its own.
|
|
8
6
|
|
|
9
7
|
## Quick Setup
|
|
10
8
|
|
|
@@ -25,7 +23,8 @@ Or add to `~/.claude/settings.json`:
|
|
|
25
23
|
"command": "npx",
|
|
26
24
|
"args": ["-y", "mcp-server-agentpay"],
|
|
27
25
|
"env": {
|
|
28
|
-
"AGENTPAY_GATEWAY_KEY": "apg_your_key_here"
|
|
26
|
+
"AGENTPAY_GATEWAY_KEY": "apg_your_key_here",
|
|
27
|
+
"AGENTPAY_URL": "https://pay.leddconsulting.com"
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -42,28 +41,42 @@ curl -X POST https://pay.leddconsulting.com/gateway/register \
|
|
|
42
41
|
|
|
43
42
|
You get $1 in free credits to start.
|
|
44
43
|
|
|
45
|
-
## Tools
|
|
44
|
+
## Tools (13 total)
|
|
46
45
|
|
|
47
46
|
| Tool | Description |
|
|
48
47
|
|------|-------------|
|
|
49
|
-
| `discover_tools` | Search tools by keyword
|
|
48
|
+
| `discover_tools` | Search tools by keyword |
|
|
50
49
|
| `list_tools` | List all available tools with pricing |
|
|
51
50
|
| `check_balance` | Check wallet balance and provisioned tools |
|
|
52
51
|
| `call_tool` | Call any tool method (metered, auto-provisions) |
|
|
53
52
|
| `provision_tool` | Pre-provision access to a tool |
|
|
54
53
|
| `get_usage` | View recent call history and costs |
|
|
55
54
|
| `fund_wallet_stripe` | Get Stripe checkout URL for credits |
|
|
56
|
-
| `fund_wallet_x402` | Get x402 crypto funding info
|
|
55
|
+
| `fund_wallet_x402` | Get x402 crypto funding info |
|
|
57
56
|
| `x402_info` | View x402 payment options and setup |
|
|
57
|
+
| `reliability_dashboard` | Admin: view circuit breaker + health dashboard |
|
|
58
|
+
| `reliability_tool_detail` | Admin: detailed reliability view per tool |
|
|
59
|
+
| `reliability_reset` | Admin: force-close a tripped circuit |
|
|
60
|
+
| `reliability_config` | Admin: update per-tool reliability settings |
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
The 4 reliability tools require `AGENTPAY_ADMIN_KEY`.
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
## Funding Methods
|
|
65
|
+
|
|
66
|
+
### Stripe (human-in-the-loop)
|
|
67
|
+
Use `fund_wallet_stripe` — returns a checkout URL for a human to complete.
|
|
68
|
+
|
|
69
|
+
### x402 USDC (fully autonomous)
|
|
70
|
+
Use `fund_wallet_x402` — returns endpoint, network, and instructions for autonomous USDC payments via the x402 protocol. No human needed.
|
|
71
|
+
|
|
72
|
+
## Credit Packages
|
|
73
|
+
|
|
74
|
+
| Package | Price | Credits | Bonus |
|
|
75
|
+
|---------|-------|---------|-------|
|
|
76
|
+
| test | $1 | 1 | — |
|
|
77
|
+
| starter | $25 | 25 | — |
|
|
78
|
+
| pro | $100 | 103 | 3% |
|
|
79
|
+
| scale | $500 | 525 | 5% |
|
|
67
80
|
|
|
68
81
|
## How It Works
|
|
69
82
|
|
|
@@ -74,45 +87,33 @@ You get $1 in free credits to start.
|
|
|
74
87
|
|
|
75
88
|
The agent never needs to know about individual tool APIs, accounts, or payment. One key, every tool.
|
|
76
89
|
|
|
77
|
-
## Funding Methods
|
|
78
|
-
|
|
79
|
-
### Stripe (human-in-the-loop)
|
|
80
|
-
Use `fund_wallet_stripe` — returns a checkout URL for a human to complete.
|
|
81
|
-
|
|
82
|
-
### x402 USDC (fully autonomous)
|
|
83
|
-
Use `fund_wallet_x402` — returns endpoint, network, and instructions for autonomous USDC payments via the [x402 protocol](https://www.x402.org/). No human needed.
|
|
84
|
-
|
|
85
|
-
### Credit Packages
|
|
86
|
-
|
|
87
|
-
| Package | Price | Credits |
|
|
88
|
-
|---------|-------|---------|
|
|
89
|
-
| micro | $10 | 10 |
|
|
90
|
-
| small | $45 | 50 |
|
|
91
|
-
| medium | $80 | 100 |
|
|
92
|
-
| large | $350 | 500 |
|
|
93
|
-
| whale | $600 | 1,000 |
|
|
94
|
-
|
|
95
90
|
## Environment Variables
|
|
96
91
|
|
|
97
92
|
| Variable | Required | Description |
|
|
98
93
|
|----------|----------|-------------|
|
|
99
94
|
| `AGENTPAY_GATEWAY_KEY` | Yes | Your gateway API key (starts with `apg_`) |
|
|
100
|
-
| `AGENTPAY_ADMIN_KEY` | No | Admin key for reliability
|
|
95
|
+
| `AGENTPAY_ADMIN_KEY` | No | Admin key for reliability tools (`reliability_*`) |
|
|
101
96
|
| `AGENTPAY_URL` | No | Custom gateway URL (default: `https://pay.leddconsulting.com`) |
|
|
102
97
|
|
|
98
|
+
Advanced optional toggles:
|
|
99
|
+
|
|
100
|
+
| Variable | Default | Description |
|
|
101
|
+
|----------|---------|-------------|
|
|
102
|
+
| `AGENTPAY_ENABLE_ADMIN_TOOLS` | `true` | Enable/disable `reliability_*` MCP tools |
|
|
103
|
+
| `AGENTPAY_ENFORCE_HOST_ALLOWLIST` | `false` | Enforce host allowlist for `AGENTPAY_URL` |
|
|
104
|
+
| `AGENTPAY_ALLOWED_HOSTS` | `pay.leddconsulting.com,agentpay.leddconsulting.com,localhost,127.0.0.1` | Comma-separated allowlist used when enforcement is enabled |
|
|
105
|
+
| `AGENTPAY_SESSION_BUDGET` | unset | Optional session spending cap in credits |
|
|
106
|
+
| `AGENTPAY_REAL_MONEY_WARNINGS` | `false` | Use stricter warning text in paid-tool/funding descriptions |
|
|
107
|
+
|
|
103
108
|
## Available Tools (via gateway)
|
|
104
109
|
|
|
105
110
|
- **Security Audit** — scan websites for vulnerabilities, SSL issues, OWASP risks
|
|
106
111
|
- **IndexForge SEO** — submit URLs to Google/Bing, scan sitemaps, check index status
|
|
107
112
|
|
|
108
|
-
More tools added regularly.
|
|
113
|
+
More tools added regularly. Tool providers can register at the gateway.
|
|
109
114
|
|
|
110
115
|
## Links
|
|
111
116
|
|
|
112
|
-
- [
|
|
113
|
-
- [
|
|
117
|
+
- [GitHub](https://github.com/joepangallo/agent-pay)
|
|
118
|
+
- [API Docs](https://pay.leddconsulting.com/docs) — alias: `https://agentpay.leddconsulting.com`
|
|
114
119
|
- [MCP Registry](https://registry.modelcontextprotocol.io) — `io.github.joepangallo/agent-pay`
|
|
115
|
-
|
|
116
|
-
## License
|
|
117
|
-
|
|
118
|
-
MIT
|
package/core.js
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
2
|
+
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
3
|
+
const { z } = require("zod");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
|
|
7
|
+
const DEFAULT_BASE_URL = "https://pay.leddconsulting.com";
|
|
8
|
+
const DEFAULT_ALLOWED_HOSTS = ["pay.leddconsulting.com", "agentpay.leddconsulting.com", "localhost", "127.0.0.1"];
|
|
9
|
+
const MAX_RESPONSE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
10
|
+
|
|
11
|
+
const CALL_TOOL_DESCRIPTION = "Call any tool method through the AgentPay gateway. Automatically provisions access on first use. Credits are deducted per call. Use discover_tools or list_tools first to see available tools and methods.";
|
|
12
|
+
const CALL_TOOL_DESCRIPTION_REAL_MONEY = "Call any tool method through the AgentPay gateway. Automatically provisions access on first use. Credits are deducted per call (real money). Use discover_tools or list_tools first to see available tools and methods. IMPORTANT: Each call costs real credits. Only call when explicitly instructed by the user.";
|
|
13
|
+
|
|
14
|
+
const X402_DESCRIPTION = "Get x402 crypto funding info for your wallet. Returns the endpoint URL, network, and setup instructions. To actually pay, your HTTP client needs @x402/fetch which automatically handles the 402 payment flow with USDC. This is the fully autonomous funding method - no human needed.";
|
|
15
|
+
const X402_DESCRIPTION_REAL_MONEY = "Get x402 crypto funding info for your wallet. Returns the endpoint URL, network, and setup instructions. IMPORTANT: This spends real USDC on Base mainnet. Only call when explicitly instructed by the user. To actually pay, your HTTP client needs @x402/fetch which automatically handles the 402 payment flow.";
|
|
16
|
+
|
|
17
|
+
function parseBoolean(rawValue, fallback) {
|
|
18
|
+
if (rawValue === undefined || rawValue === null || rawValue === "") return fallback;
|
|
19
|
+
const normalized = String(rawValue).trim().toLowerCase();
|
|
20
|
+
if (["1", "true", "yes", "y", "on"].includes(normalized)) return true;
|
|
21
|
+
if (["0", "false", "no", "n", "off"].includes(normalized)) return false;
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseNumber(rawValue, fallback) {
|
|
26
|
+
if (rawValue === undefined || rawValue === null || rawValue === "") return fallback;
|
|
27
|
+
const parsed = Number(rawValue);
|
|
28
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseAllowedHosts(rawValue, fallbackHosts) {
|
|
32
|
+
if (rawValue === undefined || rawValue === null || rawValue === "") return [...fallbackHosts];
|
|
33
|
+
const hosts = String(rawValue)
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((host) => host.trim())
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
if (hosts.length === 0) return [...fallbackHosts];
|
|
38
|
+
return hosts;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function textResponse(text) {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: "text", text }],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function buildMcpOptionsFromEnv({ version, defaults = {} }) {
|
|
48
|
+
const baseUrl = (process.env.AGENTPAY_URL || defaults.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
49
|
+
const gatewayKey = process.env.AGENTPAY_GATEWAY_KEY || defaults.gatewayKey || "";
|
|
50
|
+
const adminKey = process.env.AGENTPAY_ADMIN_KEY || defaults.adminKey || "";
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
version,
|
|
54
|
+
baseUrl,
|
|
55
|
+
gatewayKey,
|
|
56
|
+
adminKey,
|
|
57
|
+
includeAdminTools: parseBoolean(process.env.AGENTPAY_ENABLE_ADMIN_TOOLS, defaults.includeAdminTools ?? true),
|
|
58
|
+
enforceHostAllowlist: parseBoolean(process.env.AGENTPAY_ENFORCE_HOST_ALLOWLIST, defaults.enforceHostAllowlist ?? false),
|
|
59
|
+
allowedHosts: parseAllowedHosts(process.env.AGENTPAY_ALLOWED_HOSTS, defaults.allowedHosts || DEFAULT_ALLOWED_HOSTS),
|
|
60
|
+
sessionBudget: parseNumber(process.env.AGENTPAY_SESSION_BUDGET, defaults.sessionBudget ?? null),
|
|
61
|
+
realMoneyWarnings: parseBoolean(process.env.AGENTPAY_REAL_MONEY_WARNINGS, defaults.realMoneyWarnings ?? false),
|
|
62
|
+
userAgentName: defaults.userAgentName || "mcp-server-agentpay",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function createAgentPayMcpServer(options = {}) {
|
|
67
|
+
const {
|
|
68
|
+
version,
|
|
69
|
+
baseUrl,
|
|
70
|
+
gatewayKey,
|
|
71
|
+
adminKey,
|
|
72
|
+
includeAdminTools = true,
|
|
73
|
+
enforceHostAllowlist = false,
|
|
74
|
+
allowedHosts = DEFAULT_ALLOWED_HOSTS,
|
|
75
|
+
sessionBudget = null,
|
|
76
|
+
realMoneyWarnings = false,
|
|
77
|
+
userAgentName = "mcp-server-agentpay",
|
|
78
|
+
} = options;
|
|
79
|
+
|
|
80
|
+
if (!version) {
|
|
81
|
+
throw new Error("MCP server version is required.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let parsedBaseUrl;
|
|
85
|
+
try {
|
|
86
|
+
parsedBaseUrl = new URL(baseUrl || DEFAULT_BASE_URL);
|
|
87
|
+
} catch {
|
|
88
|
+
throw new Error(`[agentpay] Invalid AGENTPAY_URL: ${baseUrl}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (parsedBaseUrl.protocol !== "https:" && parsedBaseUrl.protocol !== "http:") {
|
|
92
|
+
throw new Error(`[agentpay] Unsupported AGENTPAY_URL protocol: ${parsedBaseUrl.protocol}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (enforceHostAllowlist) {
|
|
96
|
+
const host = parsedBaseUrl.hostname;
|
|
97
|
+
if (!allowedHosts.includes(host)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`[agentpay] SECURITY: AGENTPAY_URL host \"${host}\" not in allowlist. Allowed: ${allowedHosts.join(", ")}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const resolvedBaseUrl = parsedBaseUrl.toString().replace(/\/$/, "");
|
|
105
|
+
const hasSessionBudget = Number.isFinite(sessionBudget) && Number(sessionBudget) > 0;
|
|
106
|
+
const resolvedSessionBudget = hasSessionBudget ? Number(sessionBudget) : null;
|
|
107
|
+
let sessionSpent = 0;
|
|
108
|
+
|
|
109
|
+
function doRequest({ method, urlPath, body, timeout = 120_000, headers, authLabel }) {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const fullUrl = `${resolvedBaseUrl}${urlPath}`;
|
|
112
|
+
let parsed;
|
|
113
|
+
try {
|
|
114
|
+
parsed = new URL(fullUrl);
|
|
115
|
+
} catch {
|
|
116
|
+
reject(new Error(`Invalid request URL: ${fullUrl}`));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const isHttps = parsed.protocol === "https:";
|
|
121
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
122
|
+
reject(new Error(`Unsupported URL protocol: ${parsed.protocol}`));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!isHttps && authLabel) {
|
|
127
|
+
reject(new Error(`Refusing to send ${authLabel} over insecure HTTP. Use HTTPS.`));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const mod = isHttps ? https : http;
|
|
132
|
+
const opts = {
|
|
133
|
+
hostname: parsed.hostname,
|
|
134
|
+
port: parsed.port || (isHttps ? 443 : 80),
|
|
135
|
+
path: parsed.pathname + parsed.search,
|
|
136
|
+
method,
|
|
137
|
+
headers,
|
|
138
|
+
timeout,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const req = mod.request(opts, (res) => {
|
|
142
|
+
let data = "";
|
|
143
|
+
let size = 0;
|
|
144
|
+
|
|
145
|
+
res.on("data", (chunk) => {
|
|
146
|
+
size += chunk.length;
|
|
147
|
+
if (size > MAX_RESPONSE_SIZE) {
|
|
148
|
+
req.destroy();
|
|
149
|
+
reject(new Error("Response too large"));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
data += chunk;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
res.on("end", () => {
|
|
156
|
+
try {
|
|
157
|
+
const json = JSON.parse(data);
|
|
158
|
+
if (res.statusCode >= 400) {
|
|
159
|
+
reject(new Error(json.error || `HTTP ${res.statusCode}`));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
resolve(json);
|
|
163
|
+
} catch {
|
|
164
|
+
if (res.statusCode >= 400) {
|
|
165
|
+
reject(new Error(`HTTP ${res.statusCode}: ${data.slice(0, 300)}`));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
resolve(data);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
req.on("error", reject);
|
|
174
|
+
req.on("timeout", () => {
|
|
175
|
+
req.destroy();
|
|
176
|
+
reject(new Error("Request timed out"));
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (body) req.write(JSON.stringify(body));
|
|
180
|
+
req.end();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function gatewayRequest(method, urlPath, body, timeout = 120_000) {
|
|
185
|
+
const headers = {
|
|
186
|
+
"Content-Type": "application/json",
|
|
187
|
+
"User-Agent": `${userAgentName}/${version}`,
|
|
188
|
+
};
|
|
189
|
+
if (gatewayKey) headers["X-Gateway-Key"] = gatewayKey;
|
|
190
|
+
|
|
191
|
+
return doRequest({
|
|
192
|
+
method,
|
|
193
|
+
urlPath,
|
|
194
|
+
body,
|
|
195
|
+
timeout,
|
|
196
|
+
headers,
|
|
197
|
+
authLabel: gatewayKey ? "gateway key" : null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function adminRequest(method, urlPath, body, timeout = 30_000) {
|
|
202
|
+
const headers = {
|
|
203
|
+
"Content-Type": "application/json",
|
|
204
|
+
"User-Agent": `${userAgentName}/${version}`,
|
|
205
|
+
Authorization: `Bearer ${adminKey}`,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return doRequest({
|
|
209
|
+
method,
|
|
210
|
+
urlPath,
|
|
211
|
+
body,
|
|
212
|
+
timeout,
|
|
213
|
+
headers,
|
|
214
|
+
authLabel: adminKey ? "admin key" : null,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function noKeyError() {
|
|
219
|
+
return textResponse(
|
|
220
|
+
"Error: AGENTPAY_GATEWAY_KEY environment variable is required.\n\nRegister at https://pay.leddconsulting.com to get a gateway key.\nYou get $1 in free credits to start."
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function noAdminKeyError() {
|
|
225
|
+
return textResponse(
|
|
226
|
+
"Error: AGENTPAY_ADMIN_KEY environment variable is required for reliability endpoints.\n\nThis is the admin key configured on the AgentPay server."
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const server = new McpServer({
|
|
231
|
+
name: "agentpay",
|
|
232
|
+
version,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
server.tool(
|
|
236
|
+
"discover_tools",
|
|
237
|
+
"Search for available AI tools by keyword or capability. Returns matching tools with descriptions, methods, and per-call pricing. Use this to find what tools are available before calling them.",
|
|
238
|
+
{
|
|
239
|
+
query: z.string().describe("Search keyword (e.g. 'security', 'seo', 'indexing', 'vulnerability')"),
|
|
240
|
+
},
|
|
241
|
+
async ({ query }) => {
|
|
242
|
+
try {
|
|
243
|
+
const result = await gatewayRequest("POST", "/gateway/discover", { query });
|
|
244
|
+
if (result.count === 0) {
|
|
245
|
+
return textResponse(`No tools found for \"${query}\". Try: security, seo, indexing, vulnerability, audit`);
|
|
246
|
+
}
|
|
247
|
+
return textResponse(JSON.stringify(result.tools ?? [], null, 2));
|
|
248
|
+
} catch (error) {
|
|
249
|
+
return textResponse(`Error: ${error.message}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
server.tool(
|
|
255
|
+
"list_tools",
|
|
256
|
+
"List all available tools in the AgentPay gateway with their descriptions, methods, and pricing. No authentication required.",
|
|
257
|
+
{},
|
|
258
|
+
async () => {
|
|
259
|
+
try {
|
|
260
|
+
const result = await gatewayRequest("GET", "/gateway/tools");
|
|
261
|
+
return textResponse(JSON.stringify(result.tools ?? [], null, 2));
|
|
262
|
+
} catch (error) {
|
|
263
|
+
return textResponse(`Error: ${error.message}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
server.tool(
|
|
269
|
+
"check_balance",
|
|
270
|
+
"Check your AgentPay wallet balance, total credits funded, total spent, and which tools you have provisioned access to.",
|
|
271
|
+
{},
|
|
272
|
+
async () => {
|
|
273
|
+
if (!gatewayKey) return noKeyError();
|
|
274
|
+
try {
|
|
275
|
+
const result = await gatewayRequest("GET", "/gateway/balance");
|
|
276
|
+
return textResponse(JSON.stringify(result, null, 2));
|
|
277
|
+
} catch (error) {
|
|
278
|
+
return textResponse(`Error: ${error.message}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
server.tool(
|
|
284
|
+
"call_tool",
|
|
285
|
+
realMoneyWarnings ? CALL_TOOL_DESCRIPTION_REAL_MONEY : CALL_TOOL_DESCRIPTION,
|
|
286
|
+
{
|
|
287
|
+
tool: z.string().describe("Tool ID (e.g. 'agent-audit', 'indexforge')"),
|
|
288
|
+
method: z.string().describe("Method name (e.g. 'security_scan', 'scan_sitemap')"),
|
|
289
|
+
params_json: z
|
|
290
|
+
.string()
|
|
291
|
+
.optional()
|
|
292
|
+
.describe("Method parameters as JSON string (e.g. '{\"url\": \"example.com\"}'). Omit if no params needed."),
|
|
293
|
+
},
|
|
294
|
+
async ({ tool, method, params_json }) => {
|
|
295
|
+
if (!gatewayKey) return noKeyError();
|
|
296
|
+
|
|
297
|
+
if (hasSessionBudget && sessionSpent >= resolvedSessionBudget) {
|
|
298
|
+
return textResponse(
|
|
299
|
+
`Session budget exhausted ($${sessionSpent.toFixed(2)}/$${resolvedSessionBudget}). Restart the MCP server or increase AGENTPAY_SESSION_BUDGET to continue.`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
let params = {};
|
|
305
|
+
if (params_json) {
|
|
306
|
+
try {
|
|
307
|
+
params = JSON.parse(params_json);
|
|
308
|
+
} catch {
|
|
309
|
+
return textResponse("Error: params_json must be valid JSON");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const result = await gatewayRequest("POST", "/gateway/call", { tool, method, params }, 600_000);
|
|
314
|
+
const cost = Number(result.cost) || 0;
|
|
315
|
+
if (hasSessionBudget) {
|
|
316
|
+
sessionSpent += cost;
|
|
317
|
+
}
|
|
318
|
+
const balance = Number(result.balance) || 0;
|
|
319
|
+
|
|
320
|
+
const sessionMeta = hasSessionBudget
|
|
321
|
+
? ` | Session: $${sessionSpent.toFixed(2)}/$${resolvedSessionBudget}`
|
|
322
|
+
: "";
|
|
323
|
+
const meta = `[Cost: $${cost.toFixed(2)} | Balance: $${balance.toFixed(2)}${sessionMeta} | Time: ${result.elapsed || 0}ms]`;
|
|
324
|
+
|
|
325
|
+
return textResponse(`${meta}\n\n${JSON.stringify(result.result, null, 2)}`);
|
|
326
|
+
} catch (error) {
|
|
327
|
+
return textResponse(`Error: ${error.message}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
server.tool(
|
|
333
|
+
"provision_tool",
|
|
334
|
+
"Pre-provision access to a specific tool. This auto-creates an account on the tool's backend. Not required - call_tool auto-provisions on first use - but useful to confirm access before making calls.",
|
|
335
|
+
{
|
|
336
|
+
tool: z.string().describe("Tool ID to provision (e.g. 'indexforge', 'agent-audit')"),
|
|
337
|
+
},
|
|
338
|
+
async ({ tool }) => {
|
|
339
|
+
if (!gatewayKey) return noKeyError();
|
|
340
|
+
try {
|
|
341
|
+
const result = await gatewayRequest("POST", "/gateway/provision", { tool });
|
|
342
|
+
return textResponse(`${result.status}: ${result.message}`);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
return textResponse(`Error: ${error.message}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
server.tool(
|
|
350
|
+
"get_usage",
|
|
351
|
+
"View your recent tool call history - which tools you called, what methods, how much each cost, and when.",
|
|
352
|
+
{
|
|
353
|
+
limit: z.number().int().min(1).max(200).default(20).describe("Number of recent calls to show (default: 20, max: 200)"),
|
|
354
|
+
},
|
|
355
|
+
async ({ limit }) => {
|
|
356
|
+
if (!gatewayKey) return noKeyError();
|
|
357
|
+
try {
|
|
358
|
+
const result = await gatewayRequest("GET", `/gateway/usage?limit=${limit}`);
|
|
359
|
+
return textResponse(JSON.stringify(result.usage ?? [], null, 2));
|
|
360
|
+
} catch (error) {
|
|
361
|
+
return textResponse(`Error: ${error.message}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
server.tool(
|
|
367
|
+
"fund_wallet_stripe",
|
|
368
|
+
"Get a Stripe checkout URL to add credits. Requires a human to open the link and pay. Use fund_wallet_x402 for fully autonomous crypto payments instead.",
|
|
369
|
+
{
|
|
370
|
+
package: z
|
|
371
|
+
.enum(["test", "starter", "pro", "scale"])
|
|
372
|
+
.describe("Credit package: test ($1/1cr), starter ($25/25cr), pro ($100/103cr, 3% bonus), scale ($500/525cr, 5% bonus)"),
|
|
373
|
+
},
|
|
374
|
+
async ({ package: pkg }) => {
|
|
375
|
+
if (!gatewayKey) return noKeyError();
|
|
376
|
+
try {
|
|
377
|
+
const result = await gatewayRequest("POST", "/gateway/fund", { package: pkg });
|
|
378
|
+
return textResponse(
|
|
379
|
+
`Checkout URL (share with a human to complete payment):\n${result.checkoutUrl}\n\nPackage: ${pkg} (${result.credits} credits)`
|
|
380
|
+
);
|
|
381
|
+
} catch (error) {
|
|
382
|
+
return textResponse(`Error: ${error.message}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
server.tool(
|
|
388
|
+
"fund_wallet_x402",
|
|
389
|
+
realMoneyWarnings ? X402_DESCRIPTION_REAL_MONEY : X402_DESCRIPTION,
|
|
390
|
+
{
|
|
391
|
+
package: z
|
|
392
|
+
.enum(["test", "starter", "pro", "scale"])
|
|
393
|
+
.describe("Credit package: test ($1/1cr), starter ($25/25cr), pro ($100/103cr, 3% bonus), scale ($500/525cr, 5% bonus)"),
|
|
394
|
+
},
|
|
395
|
+
async ({ package: pkg }) => {
|
|
396
|
+
if (!gatewayKey) return noKeyError();
|
|
397
|
+
try {
|
|
398
|
+
const info = await gatewayRequest("GET", "/gateway/fund/x402");
|
|
399
|
+
const option = info.options?.find((candidate) => candidate.package === pkg);
|
|
400
|
+
if (!option) {
|
|
401
|
+
return textResponse(`Package \"${pkg}\" not found. Available: ${info.options?.map((candidate) => candidate.package).join(", ")}`);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return textResponse(
|
|
405
|
+
`x402 Crypto Funding for ${pkg} package (${option.credits} credits, ${option.price} USDC):\n\n` +
|
|
406
|
+
`Endpoint: POST ${resolvedBaseUrl}${option.endpoint}\n` +
|
|
407
|
+
`Network: ${option.network}\n` +
|
|
408
|
+
`PayTo: ${option.payTo}\n\n` +
|
|
409
|
+
`To pay autonomously, make an HTTP request to the endpoint above.\n` +
|
|
410
|
+
`If using @x402/fetch, the 402 payment flow is handled automatically:\n\n` +
|
|
411
|
+
` const fetchWithPayment = wrapFetchWithPayment(fetch, x402Client);\n` +
|
|
412
|
+
` const res = await fetchWithPayment(\"${resolvedBaseUrl}/gateway/fund/x402/${pkg}\", {\n` +
|
|
413
|
+
` method: \"POST\",\n` +
|
|
414
|
+
` headers: { \"X-Gateway-Key\": \"your_key\" }\n` +
|
|
415
|
+
" });\n\n" +
|
|
416
|
+
`The agent's EVM wallet needs USDC on ${option.network}.\n` +
|
|
417
|
+
"Setup: npm install @x402/fetch @x402/evm\n" +
|
|
418
|
+
"Env: EVM_PRIVATE_KEY=0x... (agent wallet with USDC)"
|
|
419
|
+
);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
return textResponse(`Error: ${error.message}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
server.tool(
|
|
427
|
+
"x402_info",
|
|
428
|
+
"Get information about x402 crypto payment support - which networks, tokens, and funding options are available for autonomous wallet funding.",
|
|
429
|
+
{},
|
|
430
|
+
async () => {
|
|
431
|
+
try {
|
|
432
|
+
const info = await gatewayRequest("GET", "/gateway/fund/x402");
|
|
433
|
+
return textResponse(JSON.stringify(info, null, 2));
|
|
434
|
+
} catch (error) {
|
|
435
|
+
return textResponse(`x402 not enabled on this gateway. Error: ${error.message}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
if (includeAdminTools) {
|
|
441
|
+
server.tool(
|
|
442
|
+
"reliability_dashboard",
|
|
443
|
+
"View the full reliability dashboard - circuit breaker states, health metrics (latency p50/p95/p99, success rates), and recent events for all tool backends. Requires admin key.",
|
|
444
|
+
{},
|
|
445
|
+
async () => {
|
|
446
|
+
if (!adminKey) return noAdminKeyError();
|
|
447
|
+
try {
|
|
448
|
+
const result = await adminRequest("GET", "/admin/reliability");
|
|
449
|
+
const circuits = result.circuits || {};
|
|
450
|
+
const health = result.health || {};
|
|
451
|
+
const events = result.events || [];
|
|
452
|
+
|
|
453
|
+
let text = "=== Reliability Dashboard ===\\n\\n";
|
|
454
|
+
|
|
455
|
+
text += "CIRCUITS:\\n";
|
|
456
|
+
const toolIds = Object.keys(circuits);
|
|
457
|
+
if (toolIds.length === 0) {
|
|
458
|
+
text += " No circuit data yet (no tool calls made since restart)\\n";
|
|
459
|
+
} else {
|
|
460
|
+
for (const toolId of toolIds) {
|
|
461
|
+
const circuit = circuits[toolId];
|
|
462
|
+
text += ` ${toolId}: ${circuit.state} (failures: ${circuit.failureCount}, successes: ${circuit.successCount})\\n`;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
text += "\\nHEALTH:\\n";
|
|
467
|
+
const healthIds = Object.keys(health);
|
|
468
|
+
if (healthIds.length === 0) {
|
|
469
|
+
text += " No health data yet\\n";
|
|
470
|
+
} else {
|
|
471
|
+
for (const toolId of healthIds) {
|
|
472
|
+
const metric = health[toolId];
|
|
473
|
+
text += ` ${toolId}: ${metric.successRate}% success (${metric.requests.total} calls) - latency avg ${metric.latency.avg}ms, p95 ${metric.latency.p95}ms\\n`;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (events.length > 0) {
|
|
478
|
+
text += `\\nRECENT EVENTS (last ${events.length}):\\n`;
|
|
479
|
+
for (const event of events.slice(-10)) {
|
|
480
|
+
const status = event.success ? "OK" : "FAIL";
|
|
481
|
+
text += ` [${event.timestamp}] ${event.toolId}.${event.method} ${status} ${event.latencyMs}ms${event.error ? " - " + event.error : ""}\\n`;
|
|
482
|
+
}
|
|
483
|
+
if (events.length > 10) {
|
|
484
|
+
text += ` ... and ${events.length - 10} more\\n`;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return textResponse(text);
|
|
489
|
+
} catch (error) {
|
|
490
|
+
return textResponse(`Error: ${error.message}`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
server.tool(
|
|
496
|
+
"reliability_tool_detail",
|
|
497
|
+
"Get detailed reliability info for a specific tool - circuit breaker state, config (thresholds, timeouts), health metrics, and recent events.",
|
|
498
|
+
{
|
|
499
|
+
tool_id: z.string().describe("Tool ID (e.g. 'agent-audit', 'indexforge')"),
|
|
500
|
+
},
|
|
501
|
+
async ({ tool_id: toolId }) => {
|
|
502
|
+
if (!adminKey) return noAdminKeyError();
|
|
503
|
+
try {
|
|
504
|
+
const result = await adminRequest("GET", `/admin/reliability/${encodeURIComponent(toolId)}`);
|
|
505
|
+
const circuit = result.circuit || {};
|
|
506
|
+
const config = result.config || {};
|
|
507
|
+
const health = result.health || {};
|
|
508
|
+
const events = result.events || [];
|
|
509
|
+
|
|
510
|
+
let text = `=== ${toolId} Reliability ===\\n\\n`;
|
|
511
|
+
text += `CIRCUIT: ${circuit.state} (failures: ${circuit.failureCount}, successes: ${circuit.successCount})\\n`;
|
|
512
|
+
text += `CONFIG: threshold=${config.failureThreshold} failures, recovery=${config.recoveryTimeoutMs}ms, timeout=${config.requestTimeoutMs}ms\\n`;
|
|
513
|
+
text += `HEALTH: ${health.successRate}% success (${health.requests?.total || 0} calls)\\n`;
|
|
514
|
+
text += `LATENCY: avg=${health.latency?.avg || 0}ms, p50=${health.latency?.p50 || 0}ms, p95=${health.latency?.p95 || 0}ms, p99=${health.latency?.p99 || 0}ms (${health.latency?.samples || 0} samples)\\n`;
|
|
515
|
+
if (health.lastCall) {
|
|
516
|
+
text += `LAST CALL: ${health.lastCall}\\n`;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (events.length > 0) {
|
|
520
|
+
text += `\\nEVENTS (${events.length}):\\n`;
|
|
521
|
+
for (const event of events.slice(-20)) {
|
|
522
|
+
const status = event.success ? "OK" : "FAIL";
|
|
523
|
+
text += ` [${event.timestamp}] ${event.method} ${status} ${event.latencyMs}ms${event.error ? " - " + event.error : ""}\\n`;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return textResponse(text);
|
|
528
|
+
} catch (error) {
|
|
529
|
+
return textResponse(`Error: ${error.message}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
server.tool(
|
|
535
|
+
"reliability_reset",
|
|
536
|
+
"Force-close a tripped circuit breaker for a tool, allowing calls to resume immediately. Use when a backend has recovered but the circuit has not automatically reset yet.",
|
|
537
|
+
{
|
|
538
|
+
tool_id: z.string().describe("Tool ID to reset (e.g. 'agent-audit', 'indexforge')"),
|
|
539
|
+
},
|
|
540
|
+
async ({ tool_id: toolId }) => {
|
|
541
|
+
if (!adminKey) return noAdminKeyError();
|
|
542
|
+
try {
|
|
543
|
+
const result = await adminRequest("POST", `/admin/reliability/${encodeURIComponent(toolId)}/reset`);
|
|
544
|
+
return textResponse(`Circuit reset for ${toolId}: ${result.previousState} -> ${result.currentState}`);
|
|
545
|
+
} catch (error) {
|
|
546
|
+
return textResponse(`Error: ${error.message}`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
server.tool(
|
|
552
|
+
"reliability_config",
|
|
553
|
+
"Update reliability settings for a specific tool - failure threshold, recovery timeout, and request timeout. Changes take effect immediately.",
|
|
554
|
+
{
|
|
555
|
+
tool_id: z.string().describe("Tool ID to configure (e.g. 'agent-audit', 'indexforge')"),
|
|
556
|
+
failure_threshold: z
|
|
557
|
+
.number()
|
|
558
|
+
.int()
|
|
559
|
+
.min(1)
|
|
560
|
+
.max(100)
|
|
561
|
+
.optional()
|
|
562
|
+
.describe("Number of consecutive failures before circuit opens (1-100)"),
|
|
563
|
+
recovery_timeout_ms: z
|
|
564
|
+
.number()
|
|
565
|
+
.int()
|
|
566
|
+
.min(5000)
|
|
567
|
+
.max(600000)
|
|
568
|
+
.optional()
|
|
569
|
+
.describe("Milliseconds before OPEN circuit tries recovery (5000-600000)"),
|
|
570
|
+
request_timeout_ms: z
|
|
571
|
+
.number()
|
|
572
|
+
.int()
|
|
573
|
+
.min(1000)
|
|
574
|
+
.max(600000)
|
|
575
|
+
.optional()
|
|
576
|
+
.describe("Per-request timeout in milliseconds (1000-600000)"),
|
|
577
|
+
},
|
|
578
|
+
async ({ tool_id: toolId, failure_threshold: failureThreshold, recovery_timeout_ms: recoveryTimeoutMs, request_timeout_ms: requestTimeoutMs }) => {
|
|
579
|
+
if (!adminKey) return noAdminKeyError();
|
|
580
|
+
|
|
581
|
+
const body = {};
|
|
582
|
+
if (failureThreshold !== undefined) body.failureThreshold = failureThreshold;
|
|
583
|
+
if (recoveryTimeoutMs !== undefined) body.recoveryTimeoutMs = recoveryTimeoutMs;
|
|
584
|
+
if (requestTimeoutMs !== undefined) body.requestTimeoutMs = requestTimeoutMs;
|
|
585
|
+
|
|
586
|
+
if (Object.keys(body).length === 0) {
|
|
587
|
+
return textResponse(
|
|
588
|
+
"Error: Provide at least one setting to update (failure_threshold, recovery_timeout_ms, request_timeout_ms)"
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
try {
|
|
593
|
+
const result = await adminRequest("POST", `/admin/reliability/${encodeURIComponent(toolId)}/config`, body);
|
|
594
|
+
const config = result.config || {};
|
|
595
|
+
return textResponse(
|
|
596
|
+
`Config updated for ${toolId}:\\n failureThreshold: ${config.failureThreshold}\\n recoveryTimeoutMs: ${config.recoveryTimeoutMs}\\n requestTimeoutMs: ${config.requestTimeoutMs}`
|
|
597
|
+
);
|
|
598
|
+
} catch (error) {
|
|
599
|
+
return textResponse(`Error: ${error.message}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return {
|
|
606
|
+
server,
|
|
607
|
+
async connectStdio() {
|
|
608
|
+
const transport = new StdioServerTransport();
|
|
609
|
+
await server.connect(transport);
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function startAgentPayMcpFromEnv({ version, defaults = {} }) {
|
|
615
|
+
const options = buildMcpOptionsFromEnv({ version, defaults });
|
|
616
|
+
const runtime = createAgentPayMcpServer(options);
|
|
617
|
+
return runtime.connectStdio();
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
module.exports = {
|
|
621
|
+
DEFAULT_ALLOWED_HOSTS,
|
|
622
|
+
buildMcpOptionsFromEnv,
|
|
623
|
+
createAgentPayMcpServer,
|
|
624
|
+
startAgentPayMcpFromEnv,
|
|
625
|
+
};
|
package/index.js
CHANGED
|
@@ -1,500 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
4
|
-
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
5
|
-
const { z } = require("zod");
|
|
6
|
-
const https = require("https");
|
|
7
|
-
const http = require("http");
|
|
8
3
|
const { version } = require("./package.json");
|
|
4
|
+
const { startAgentPayMcpFromEnv } = require("./core");
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const GATEWAY_KEY = process.env.AGENTPAY_GATEWAY_KEY || "";
|
|
13
|
-
const ADMIN_KEY = process.env.AGENTPAY_ADMIN_KEY || "";
|
|
14
|
-
const BASE_URL = (process.env.AGENTPAY_URL || "https://pay.leddconsulting.com").replace(/\/$/, "");
|
|
15
|
-
|
|
16
|
-
// ── HTTP helper ─────────────────────────────────────────────────────
|
|
17
|
-
|
|
18
|
-
const MAX_RESPONSE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
19
|
-
|
|
20
|
-
function request(method, urlPath, body, timeout = 120_000) {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
const fullUrl = `${BASE_URL}${urlPath}`;
|
|
23
|
-
const parsed = new URL(fullUrl);
|
|
24
|
-
const isHttps = parsed.protocol === "https:";
|
|
25
|
-
|
|
26
|
-
if (!isHttps && GATEWAY_KEY) {
|
|
27
|
-
return reject(new Error("Refusing to send gateway key over insecure HTTP. Use HTTPS."));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const mod = isHttps ? https : http;
|
|
31
|
-
|
|
32
|
-
const headers = {
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
"User-Agent": `mcp-server-agentpay/${version}`,
|
|
35
|
-
};
|
|
36
|
-
if (GATEWAY_KEY) headers["X-Gateway-Key"] = GATEWAY_KEY;
|
|
37
|
-
|
|
38
|
-
const opts = {
|
|
39
|
-
hostname: parsed.hostname,
|
|
40
|
-
port: parsed.port || (isHttps ? 443 : 80),
|
|
41
|
-
path: parsed.pathname + parsed.search,
|
|
42
|
-
method,
|
|
43
|
-
headers,
|
|
44
|
-
timeout,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const req = mod.request(opts, (res) => {
|
|
48
|
-
let data = "";
|
|
49
|
-
let size = 0;
|
|
50
|
-
res.on("data", (c) => {
|
|
51
|
-
size += c.length;
|
|
52
|
-
if (size > MAX_RESPONSE_SIZE) { req.destroy(); return reject(new Error("Response too large")); }
|
|
53
|
-
data += c;
|
|
54
|
-
});
|
|
55
|
-
res.on("end", () => {
|
|
56
|
-
try {
|
|
57
|
-
const json = JSON.parse(data);
|
|
58
|
-
if (res.statusCode >= 400) return reject(new Error(json.error || `HTTP ${res.statusCode}`));
|
|
59
|
-
resolve(json);
|
|
60
|
-
} catch {
|
|
61
|
-
if (res.statusCode >= 400) return reject(new Error(`HTTP ${res.statusCode}: ${data.slice(0, 300)}`));
|
|
62
|
-
resolve(data);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
req.on("error", reject);
|
|
68
|
-
req.on("timeout", () => { req.destroy(); reject(new Error("Request timed out")); });
|
|
69
|
-
if (body) req.write(JSON.stringify(body));
|
|
70
|
-
req.end();
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function noKeyError() {
|
|
75
|
-
return {
|
|
76
|
-
content: [{ type: "text", text: "Error: AGENTPAY_GATEWAY_KEY environment variable is required.\n\nRegister at https://pay.leddconsulting.com to get a gateway key.\nYou get $1 in free credits to start." }],
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function noAdminKeyError() {
|
|
81
|
-
return {
|
|
82
|
-
content: [{ type: "text", text: "Error: AGENTPAY_ADMIN_KEY environment variable is required for reliability endpoints.\n\nThis is the admin key configured on the AgentPay server." }],
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function adminRequest(method, urlPath, body, timeout = 30_000) {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const fullUrl = `${BASE_URL}${urlPath}`;
|
|
89
|
-
const parsed = new URL(fullUrl);
|
|
90
|
-
const isHttps = parsed.protocol === "https:";
|
|
91
|
-
|
|
92
|
-
if (!isHttps && ADMIN_KEY) {
|
|
93
|
-
return reject(new Error("Refusing to send admin key over insecure HTTP. Use HTTPS."));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const mod = isHttps ? https : http;
|
|
97
|
-
|
|
98
|
-
const headers = {
|
|
99
|
-
"Content-Type": "application/json",
|
|
100
|
-
"User-Agent": `mcp-server-agentpay/${version}`,
|
|
101
|
-
"Authorization": `Bearer ${ADMIN_KEY}`,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const opts = {
|
|
105
|
-
hostname: parsed.hostname,
|
|
106
|
-
port: parsed.port || (isHttps ? 443 : 80),
|
|
107
|
-
path: parsed.pathname + parsed.search,
|
|
108
|
-
method,
|
|
109
|
-
headers,
|
|
110
|
-
timeout,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const req = mod.request(opts, (res) => {
|
|
114
|
-
let data = "";
|
|
115
|
-
let size = 0;
|
|
116
|
-
res.on("data", (c) => {
|
|
117
|
-
size += c.length;
|
|
118
|
-
if (size > MAX_RESPONSE_SIZE) { req.destroy(); return reject(new Error("Response too large")); }
|
|
119
|
-
data += c;
|
|
120
|
-
});
|
|
121
|
-
res.on("end", () => {
|
|
122
|
-
try {
|
|
123
|
-
const json = JSON.parse(data);
|
|
124
|
-
if (res.statusCode >= 400) return reject(new Error(json.error || `HTTP ${res.statusCode}`));
|
|
125
|
-
resolve(json);
|
|
126
|
-
} catch {
|
|
127
|
-
if (res.statusCode >= 400) return reject(new Error(`HTTP ${res.statusCode}: ${data.slice(0, 300)}`));
|
|
128
|
-
resolve(data);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
req.on("error", reject);
|
|
134
|
-
req.on("timeout", () => { req.destroy(); reject(new Error("Request timed out")); });
|
|
135
|
-
if (body) req.write(JSON.stringify(body));
|
|
136
|
-
req.end();
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// ── MCP Server ──────────────────────────────────────────────────────
|
|
141
|
-
|
|
142
|
-
const server = new McpServer({
|
|
143
|
-
name: "agentpay",
|
|
6
|
+
startAgentPayMcpFromEnv({
|
|
144
7
|
version,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
query: z.string().describe("Search keyword (e.g. 'security', 'seo', 'indexing', 'vulnerability')"),
|
|
154
|
-
},
|
|
155
|
-
async ({ query }) => {
|
|
156
|
-
try {
|
|
157
|
-
const result = await request("POST", "/gateway/discover", { query });
|
|
158
|
-
if (result.count === 0) {
|
|
159
|
-
return { content: [{ type: "text", text: `No tools found for "${query}". Try: security, seo, indexing, vulnerability, audit` }] };
|
|
160
|
-
}
|
|
161
|
-
return { content: [{ type: "text", text: JSON.stringify(result.tools ?? [], null, 2) }] };
|
|
162
|
-
} catch (e) {
|
|
163
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
// ── Tool: list_tools ────────────────────────────────────────────────
|
|
169
|
-
|
|
170
|
-
server.tool(
|
|
171
|
-
"list_tools",
|
|
172
|
-
"List all available tools in the AgentPay gateway with their descriptions, methods, and pricing. No authentication required.",
|
|
173
|
-
{},
|
|
174
|
-
async () => {
|
|
175
|
-
try {
|
|
176
|
-
const result = await request("GET", "/gateway/tools");
|
|
177
|
-
return { content: [{ type: "text", text: JSON.stringify(result.tools ?? [], null, 2) }] };
|
|
178
|
-
} catch (e) {
|
|
179
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
// ── Tool: check_balance ─────────────────────────────────────────────
|
|
185
|
-
|
|
186
|
-
server.tool(
|
|
187
|
-
"check_balance",
|
|
188
|
-
"Check your AgentPay wallet balance, total credits funded, total spent, and which tools you have provisioned access to.",
|
|
189
|
-
{},
|
|
190
|
-
async () => {
|
|
191
|
-
if (!GATEWAY_KEY) return noKeyError();
|
|
192
|
-
try {
|
|
193
|
-
const result = await request("GET", "/gateway/balance");
|
|
194
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
195
|
-
} catch (e) {
|
|
196
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
// ── Tool: call_tool ─────────────────────────────────────────────────
|
|
202
|
-
|
|
203
|
-
server.tool(
|
|
204
|
-
"call_tool",
|
|
205
|
-
"Call any tool method through the AgentPay gateway. Automatically provisions access on first use. Credits are deducted per call. Use discover_tools or list_tools first to see available tools and methods.",
|
|
206
|
-
{
|
|
207
|
-
tool: z.string().describe("Tool ID (e.g. 'agent-audit', 'indexforge')"),
|
|
208
|
-
method: z.string().describe("Method name (e.g. 'security_scan', 'scan_sitemap')"),
|
|
209
|
-
params_json: z.string().optional().describe("Method parameters as JSON string (e.g. '{\"url\": \"example.com\"}'). Omit if no params needed."),
|
|
210
|
-
},
|
|
211
|
-
async ({ tool, method, params_json }) => {
|
|
212
|
-
if (!GATEWAY_KEY) return noKeyError();
|
|
213
|
-
try {
|
|
214
|
-
let params = {};
|
|
215
|
-
if (params_json) {
|
|
216
|
-
try { params = JSON.parse(params_json); } catch { return { content: [{ type: "text", text: "Error: params_json must be valid JSON" }] }; }
|
|
217
|
-
}
|
|
218
|
-
const result = await request("POST", "/gateway/call", { tool, method, params }, 600_000);
|
|
219
|
-
const cost = Number(result.cost) || 0;
|
|
220
|
-
const balance = Number(result.balance) || 0;
|
|
221
|
-
const meta = `[Cost: $${cost.toFixed(2)} | Balance: $${balance.toFixed(2)} | Time: ${result.elapsed || 0}ms]`;
|
|
222
|
-
return {
|
|
223
|
-
content: [{ type: "text", text: `${meta}\n\n${JSON.stringify(result.result, null, 2)}` }],
|
|
224
|
-
};
|
|
225
|
-
} catch (e) {
|
|
226
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
// ── Tool: provision_tool ────────────────────────────────────────────
|
|
232
|
-
|
|
233
|
-
server.tool(
|
|
234
|
-
"provision_tool",
|
|
235
|
-
"Pre-provision access to a specific tool. This auto-creates an account on the tool's backend. Not required — call_tool auto-provisions on first use — but useful to confirm access before making calls.",
|
|
236
|
-
{
|
|
237
|
-
tool: z.string().describe("Tool ID to provision (e.g. 'indexforge', 'agent-audit')"),
|
|
238
|
-
},
|
|
239
|
-
async ({ tool }) => {
|
|
240
|
-
if (!GATEWAY_KEY) return noKeyError();
|
|
241
|
-
try {
|
|
242
|
-
const result = await request("POST", "/gateway/provision", { tool });
|
|
243
|
-
return { content: [{ type: "text", text: `${result.status}: ${result.message}` }] };
|
|
244
|
-
} catch (e) {
|
|
245
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
// ── Tool: get_usage ─────────────────────────────────────────────────
|
|
251
|
-
|
|
252
|
-
server.tool(
|
|
253
|
-
"get_usage",
|
|
254
|
-
"View your recent tool call history — which tools you called, what methods, how much each cost, and when.",
|
|
255
|
-
{
|
|
256
|
-
limit: z.number().int().min(1).max(200).default(20).describe("Number of recent calls to show (default: 20, max: 200)"),
|
|
257
|
-
},
|
|
258
|
-
async ({ limit }) => {
|
|
259
|
-
if (!GATEWAY_KEY) return noKeyError();
|
|
260
|
-
try {
|
|
261
|
-
const result = await request("GET", `/gateway/usage?limit=${limit}`);
|
|
262
|
-
return { content: [{ type: "text", text: JSON.stringify(result.usage ?? [], null, 2) }] };
|
|
263
|
-
} catch (e) {
|
|
264
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
// ── Tool: fund_wallet_stripe ─────────────────────────────────────────
|
|
270
|
-
|
|
271
|
-
server.tool(
|
|
272
|
-
"fund_wallet_stripe",
|
|
273
|
-
"Get a Stripe checkout URL to add credits. Requires a human to open the link and pay. Use fund_wallet_x402 for fully autonomous crypto payments instead.",
|
|
274
|
-
{
|
|
275
|
-
package: z.enum(["micro", "small", "medium", "large", "whale"]).describe("Credit package: micro ($10/10cr), small ($45/50cr), medium ($80/100cr), large ($350/500cr), whale ($600/1000cr)"),
|
|
276
|
-
},
|
|
277
|
-
async ({ package: pkg }) => {
|
|
278
|
-
if (!GATEWAY_KEY) return noKeyError();
|
|
279
|
-
try {
|
|
280
|
-
const result = await request("POST", "/gateway/fund", { package: pkg });
|
|
281
|
-
return { content: [{ type: "text", text: `Checkout URL (share with a human to complete payment):\n${result.checkoutUrl}\n\nPackage: ${pkg} (${result.credits} credits)` }] };
|
|
282
|
-
} catch (e) {
|
|
283
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
// ── Tool: fund_wallet_x402 ──────────────────────────────────────────
|
|
289
|
-
|
|
290
|
-
server.tool(
|
|
291
|
-
"fund_wallet_x402",
|
|
292
|
-
"Get x402 crypto funding info for your wallet. Returns the endpoint URL, network, and setup instructions. To actually pay, your HTTP client needs @x402/fetch which automatically handles the 402 payment flow with USDC. This is the fully autonomous funding method — no human needed.",
|
|
293
|
-
{
|
|
294
|
-
package: z.enum(["micro", "small", "medium", "large", "whale"]).describe("Credit package: micro ($10/10cr), small ($45/50cr), medium ($80/100cr), large ($350/500cr), whale ($600/1000cr)"),
|
|
295
|
-
},
|
|
296
|
-
async ({ package: pkg }) => {
|
|
297
|
-
if (!GATEWAY_KEY) return noKeyError();
|
|
298
|
-
try {
|
|
299
|
-
const info = await request("GET", "/gateway/fund/x402");
|
|
300
|
-
const option = info.options?.find(o => o.package === pkg);
|
|
301
|
-
if (!option) {
|
|
302
|
-
return { content: [{ type: "text", text: `Package "${pkg}" not found. Available: ${info.options?.map(o => o.package).join(", ")}` }] };
|
|
303
|
-
}
|
|
304
|
-
return {
|
|
305
|
-
content: [{
|
|
306
|
-
type: "text",
|
|
307
|
-
text: `x402 Crypto Funding for ${pkg} package (${option.credits} credits, ${option.price} USDC):\n\n` +
|
|
308
|
-
`Endpoint: POST ${BASE_URL}${option.endpoint}\n` +
|
|
309
|
-
`Network: ${option.network}\n` +
|
|
310
|
-
`PayTo: ${option.payTo}\n\n` +
|
|
311
|
-
`To pay autonomously, make an HTTP request to the endpoint above.\n` +
|
|
312
|
-
`If using @x402/fetch, the 402 payment flow is handled automatically:\n\n` +
|
|
313
|
-
` const fetchWithPayment = wrapFetchWithPayment(fetch, x402Client);\n` +
|
|
314
|
-
` const res = await fetchWithPayment("${BASE_URL}/gateway/fund/x402/${pkg}", {\n` +
|
|
315
|
-
` method: "POST",\n` +
|
|
316
|
-
` headers: { "X-Gateway-Key": "your_key" }\n` +
|
|
317
|
-
` });\n\n` +
|
|
318
|
-
`The agent's EVM wallet needs USDC on ${option.network}.\n` +
|
|
319
|
-
`Setup: npm install @x402/fetch @x402/evm\n` +
|
|
320
|
-
`Env: EVM_PRIVATE_KEY=0x... (agent wallet with USDC)`,
|
|
321
|
-
}],
|
|
322
|
-
};
|
|
323
|
-
} catch (e) {
|
|
324
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
// ── Tool: x402_info ─────────────────────────────────────────────────
|
|
330
|
-
|
|
331
|
-
server.tool(
|
|
332
|
-
"x402_info",
|
|
333
|
-
"Get information about x402 crypto payment support — which networks, tokens, and funding options are available for autonomous wallet funding.",
|
|
334
|
-
{},
|
|
335
|
-
async () => {
|
|
336
|
-
try {
|
|
337
|
-
const info = await request("GET", "/gateway/fund/x402");
|
|
338
|
-
return { content: [{ type: "text", text: JSON.stringify(info, null, 2) }] };
|
|
339
|
-
} catch (e) {
|
|
340
|
-
return { content: [{ type: "text", text: `x402 not enabled on this gateway. Error: ${e.message}` }] };
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
// ── Tool: reliability_dashboard ────────────────────────────────────
|
|
346
|
-
|
|
347
|
-
server.tool(
|
|
348
|
-
"reliability_dashboard",
|
|
349
|
-
"View the full reliability dashboard — circuit breaker states, health metrics (latency p50/p95/p99, success rates), and recent events for all tool backends. Requires admin key.",
|
|
350
|
-
{},
|
|
351
|
-
async () => {
|
|
352
|
-
if (!ADMIN_KEY) return noAdminKeyError();
|
|
353
|
-
try {
|
|
354
|
-
const result = await adminRequest("GET", "/admin/reliability");
|
|
355
|
-
const circuits = result.circuits || {};
|
|
356
|
-
const health = result.health || {};
|
|
357
|
-
const events = result.events || [];
|
|
358
|
-
|
|
359
|
-
let text = "=== Reliability Dashboard ===\n\n";
|
|
360
|
-
|
|
361
|
-
// Circuit states
|
|
362
|
-
text += "CIRCUITS:\n";
|
|
363
|
-
const toolIds = Object.keys(circuits);
|
|
364
|
-
if (toolIds.length === 0) {
|
|
365
|
-
text += " No circuit data yet (no tool calls made since restart)\n";
|
|
366
|
-
} else {
|
|
367
|
-
for (const id of toolIds) {
|
|
368
|
-
const c = circuits[id];
|
|
369
|
-
text += ` ${id}: ${c.state} (failures: ${c.failureCount}, successes: ${c.successCount})\n`;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Health metrics
|
|
374
|
-
text += "\nHEALTH:\n";
|
|
375
|
-
const healthIds = Object.keys(health);
|
|
376
|
-
if (healthIds.length === 0) {
|
|
377
|
-
text += " No health data yet\n";
|
|
378
|
-
} else {
|
|
379
|
-
for (const id of healthIds) {
|
|
380
|
-
const h = health[id];
|
|
381
|
-
text += ` ${id}: ${h.successRate}% success (${h.requests.total} calls) — latency avg ${h.latency.avg}ms, p95 ${h.latency.p95}ms\n`;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Recent events
|
|
386
|
-
if (events.length > 0) {
|
|
387
|
-
text += `\nRECENT EVENTS (last ${events.length}):\n`;
|
|
388
|
-
for (const e of events.slice(-10)) {
|
|
389
|
-
const status = e.success ? "OK" : "FAIL";
|
|
390
|
-
text += ` [${e.timestamp}] ${e.toolId}.${e.method} ${status} ${e.latencyMs}ms${e.error ? " — " + e.error : ""}\n`;
|
|
391
|
-
}
|
|
392
|
-
if (events.length > 10) text += ` ... and ${events.length - 10} more\n`;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return { content: [{ type: "text", text }] };
|
|
396
|
-
} catch (e) {
|
|
397
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
// ── Tool: reliability_tool_detail ─────────────────────────────────
|
|
403
|
-
|
|
404
|
-
server.tool(
|
|
405
|
-
"reliability_tool_detail",
|
|
406
|
-
"Get detailed reliability info for a specific tool — circuit breaker state, config (thresholds, timeouts), health metrics, and recent events.",
|
|
407
|
-
{
|
|
408
|
-
tool_id: z.string().describe("Tool ID (e.g. 'agent-audit', 'indexforge')"),
|
|
409
|
-
},
|
|
410
|
-
async ({ tool_id }) => {
|
|
411
|
-
if (!ADMIN_KEY) return noAdminKeyError();
|
|
412
|
-
try {
|
|
413
|
-
const result = await adminRequest("GET", `/admin/reliability/${encodeURIComponent(tool_id)}`);
|
|
414
|
-
const c = result.circuit || {};
|
|
415
|
-
const cfg = result.config || {};
|
|
416
|
-
const h = result.health || {};
|
|
417
|
-
const events = result.events || [];
|
|
418
|
-
|
|
419
|
-
let text = `=== ${tool_id} Reliability ===\n\n`;
|
|
420
|
-
text += `CIRCUIT: ${c.state} (failures: ${c.failureCount}, successes: ${c.successCount})\n`;
|
|
421
|
-
text += `CONFIG: threshold=${cfg.failureThreshold} failures, recovery=${cfg.recoveryTimeoutMs}ms, timeout=${cfg.requestTimeoutMs}ms\n`;
|
|
422
|
-
text += `HEALTH: ${h.successRate}% success (${h.requests?.total || 0} calls)\n`;
|
|
423
|
-
text += `LATENCY: avg=${h.latency?.avg || 0}ms, p50=${h.latency?.p50 || 0}ms, p95=${h.latency?.p95 || 0}ms, p99=${h.latency?.p99 || 0}ms (${h.latency?.samples || 0} samples)\n`;
|
|
424
|
-
if (h.lastCall) text += `LAST CALL: ${h.lastCall}\n`;
|
|
425
|
-
|
|
426
|
-
if (events.length > 0) {
|
|
427
|
-
text += `\nEVENTS (${events.length}):\n`;
|
|
428
|
-
for (const e of events.slice(-20)) {
|
|
429
|
-
const status = e.success ? "OK" : "FAIL";
|
|
430
|
-
text += ` [${e.timestamp}] ${e.method} ${status} ${e.latencyMs}ms${e.error ? " — " + e.error : ""}\n`;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return { content: [{ type: "text", text }] };
|
|
435
|
-
} catch (e) {
|
|
436
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
// ── Tool: reliability_reset ───────────────────────────────────────
|
|
442
|
-
|
|
443
|
-
server.tool(
|
|
444
|
-
"reliability_reset",
|
|
445
|
-
"Force-close a tripped circuit breaker for a tool, allowing calls to resume immediately. Use when a backend has recovered but the circuit hasn't automatically reset yet.",
|
|
446
|
-
{
|
|
447
|
-
tool_id: z.string().describe("Tool ID to reset (e.g. 'agent-audit', 'indexforge')"),
|
|
448
|
-
},
|
|
449
|
-
async ({ tool_id }) => {
|
|
450
|
-
if (!ADMIN_KEY) return noAdminKeyError();
|
|
451
|
-
try {
|
|
452
|
-
const result = await adminRequest("POST", `/admin/reliability/${encodeURIComponent(tool_id)}/reset`);
|
|
453
|
-
return { content: [{ type: "text", text: `Circuit reset for ${tool_id}: ${result.previousState} → ${result.currentState}` }] };
|
|
454
|
-
} catch (e) {
|
|
455
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
// ── Tool: reliability_config ──────────────────────────────────────
|
|
461
|
-
|
|
462
|
-
server.tool(
|
|
463
|
-
"reliability_config",
|
|
464
|
-
"Update reliability settings for a specific tool — failure threshold, recovery timeout, and request timeout. Changes take effect immediately.",
|
|
465
|
-
{
|
|
466
|
-
tool_id: z.string().describe("Tool ID to configure (e.g. 'agent-audit', 'indexforge')"),
|
|
467
|
-
failure_threshold: z.number().int().min(1).max(100).optional().describe("Number of consecutive failures before circuit opens (1-100)"),
|
|
468
|
-
recovery_timeout_ms: z.number().int().min(5000).max(600000).optional().describe("Milliseconds before OPEN circuit tries recovery (5000-600000)"),
|
|
469
|
-
request_timeout_ms: z.number().int().min(1000).max(600000).optional().describe("Per-request timeout in milliseconds (1000-600000)"),
|
|
470
|
-
},
|
|
471
|
-
async ({ tool_id, failure_threshold, recovery_timeout_ms, request_timeout_ms }) => {
|
|
472
|
-
if (!ADMIN_KEY) return noAdminKeyError();
|
|
473
|
-
const body = {};
|
|
474
|
-
if (failure_threshold !== undefined) body.failureThreshold = failure_threshold;
|
|
475
|
-
if (recovery_timeout_ms !== undefined) body.recoveryTimeoutMs = recovery_timeout_ms;
|
|
476
|
-
if (request_timeout_ms !== undefined) body.requestTimeoutMs = request_timeout_ms;
|
|
477
|
-
if (Object.keys(body).length === 0) {
|
|
478
|
-
return { content: [{ type: "text", text: "Error: Provide at least one setting to update (failure_threshold, recovery_timeout_ms, request_timeout_ms)" }] };
|
|
479
|
-
}
|
|
480
|
-
try {
|
|
481
|
-
const result = await adminRequest("POST", `/admin/reliability/${encodeURIComponent(tool_id)}/config`, body);
|
|
482
|
-
const cfg = result.config || {};
|
|
483
|
-
return { content: [{ type: "text", text: `Config updated for ${tool_id}:\n failureThreshold: ${cfg.failureThreshold}\n recoveryTimeoutMs: ${cfg.recoveryTimeoutMs}\n requestTimeoutMs: ${cfg.requestTimeoutMs}` }] };
|
|
484
|
-
} catch (e) {
|
|
485
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
);
|
|
489
|
-
|
|
490
|
-
// ── Start ───────────────────────────────────────────────────────────
|
|
491
|
-
|
|
492
|
-
async function main() {
|
|
493
|
-
const transport = new StdioServerTransport();
|
|
494
|
-
await server.connect(transport);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
main().catch((e) => {
|
|
498
|
-
console.error("MCP server error:", e);
|
|
8
|
+
defaults: {
|
|
9
|
+
includeAdminTools: true,
|
|
10
|
+
enforceHostAllowlist: false,
|
|
11
|
+
sessionBudget: null,
|
|
12
|
+
realMoneyWarnings: false,
|
|
13
|
+
},
|
|
14
|
+
}).catch((error) => {
|
|
15
|
+
console.error("MCP server error:", error);
|
|
499
16
|
process.exit(1);
|
|
500
17
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-server-agentpay",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"mcpName": "io.github.joepangallo/agent-pay",
|
|
5
5
|
"description": "MCP server for AgentPay — the payment gateway for autonomous AI agents. Discover, provision, and pay for MCP tool APIs. Includes reliability monitoring with circuit breakers and health metrics.",
|
|
6
6
|
"bin": {
|
|
@@ -38,12 +38,11 @@
|
|
|
38
38
|
"web3"
|
|
39
39
|
],
|
|
40
40
|
"license": "MIT",
|
|
41
|
-
"author": "
|
|
41
|
+
"author": "Ledd Consulting",
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|
|
44
|
-
"url": "https://github.com/joepangallo/
|
|
44
|
+
"url": "https://github.com/joepangallo/agent-pay"
|
|
45
45
|
},
|
|
46
|
-
"homepage": "https://pay.leddconsulting.com",
|
|
47
46
|
"dependencies": {
|
|
48
47
|
"@modelcontextprotocol/sdk": "^1.27.0",
|
|
49
48
|
"zod": "^3.23.0"
|
|
@@ -53,6 +52,7 @@
|
|
|
53
52
|
},
|
|
54
53
|
"files": [
|
|
55
54
|
"index.js",
|
|
55
|
+
"core.js",
|
|
56
56
|
"README.md",
|
|
57
57
|
"server.json",
|
|
58
58
|
"package.json"
|
package/server.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.joepangallo/agent-pay",
|
|
4
|
-
"description": "Payment gateway for AI agents
|
|
4
|
+
"description": "Payment gateway for AI agents with tool discovery, provisioning, metering, and reliability tools.",
|
|
5
5
|
"repository": {
|
|
6
|
-
"url": "https://github.com/joepangallo/
|
|
6
|
+
"url": "https://github.com/joepangallo/agent-pay",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.1.
|
|
9
|
+
"version": "1.1.2",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "mcp-server-agentpay",
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.2",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"name": "AGENTPAY_ADMIN_KEY"
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
"description": "AgentPay API URL
|
|
34
|
+
"description": "AgentPay API URL",
|
|
35
35
|
"isRequired": false,
|
|
36
36
|
"format": "string",
|
|
37
37
|
"isSecret": false,
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 MetalTorque
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|