mcp-server-agentpay 1.0.0
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 +60 -0
- package/index.js +221 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# mcp-server-agentpay
|
|
2
|
+
|
|
3
|
+
MCP server for **AgentPay** — the payment gateway for autonomous AI agents.
|
|
4
|
+
|
|
5
|
+
Fund a wallet once, give your agent the key, and it discovers, provisions, and pays for tool APIs on its own.
|
|
6
|
+
|
|
7
|
+
## Quick Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Add to Claude Code
|
|
11
|
+
claude mcp add agentpay -- npx mcp-server-agentpay
|
|
12
|
+
|
|
13
|
+
# Set your gateway key
|
|
14
|
+
export AGENTPAY_GATEWAY_KEY="apg_your_key_here"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Get a Gateway Key
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
curl -X POST https://agentpay.metaltorque.dev/gateway/register \
|
|
21
|
+
-H "Content-Type: application/json" \
|
|
22
|
+
-d '{"email": "you@example.com"}'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You get $1 in free credits to start.
|
|
26
|
+
|
|
27
|
+
## Tools
|
|
28
|
+
|
|
29
|
+
| Tool | Description |
|
|
30
|
+
|------|-------------|
|
|
31
|
+
| `list_tools` | List all available tools with pricing |
|
|
32
|
+
| `discover_tools` | Search tools by keyword/capability |
|
|
33
|
+
| `call_tool` | Call any tool method (auto-provisions, metered) |
|
|
34
|
+
| `check_balance` | Check wallet balance and provisioned tools |
|
|
35
|
+
| `provision_tool` | Pre-provision access to a tool |
|
|
36
|
+
| `get_usage` | View recent call history and costs |
|
|
37
|
+
| `fund_wallet` | Get Stripe checkout URL to add credits |
|
|
38
|
+
|
|
39
|
+
## How It Works
|
|
40
|
+
|
|
41
|
+
1. **Register** — create a wallet, get a gateway key
|
|
42
|
+
2. **Fund** — add credits via Stripe ($10–$600 packages)
|
|
43
|
+
3. **Discover** — agent searches for tools by capability
|
|
44
|
+
4. **Call** — agent calls any tool, gateway handles auth + billing
|
|
45
|
+
|
|
46
|
+
The agent never needs to know about individual tool APIs, accounts, or payment. One key, every tool.
|
|
47
|
+
|
|
48
|
+
## Environment Variables
|
|
49
|
+
|
|
50
|
+
| Variable | Required | Description |
|
|
51
|
+
|----------|----------|-------------|
|
|
52
|
+
| `AGENTPAY_GATEWAY_KEY` | Yes | Your gateway API key (starts with `apg_`) |
|
|
53
|
+
| `AGENTPAY_URL` | No | Custom gateway URL (default: `https://agentpay.metaltorque.dev`) |
|
|
54
|
+
|
|
55
|
+
## Available Tools (via gateway)
|
|
56
|
+
|
|
57
|
+
- **Security Audit** — scan websites for vulnerabilities, SSL issues, OWASP risks
|
|
58
|
+
- **IndexForge SEO** — submit URLs to Google/Bing, scan sitemaps, check index status
|
|
59
|
+
|
|
60
|
+
More tools added regularly. Tool providers can register at the gateway.
|
package/index.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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
|
+
|
|
9
|
+
// ── Config ──────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
const GATEWAY_KEY = process.env.AGENTPAY_GATEWAY_KEY || "";
|
|
12
|
+
const BASE_URL = (process.env.AGENTPAY_URL || "https://agentpay.metaltorque.dev").replace(/\/$/, "");
|
|
13
|
+
|
|
14
|
+
// ── HTTP helper ─────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
function request(method, urlPath, body, timeout = 120_000) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const fullUrl = `${BASE_URL}${urlPath}`;
|
|
19
|
+
const mod = fullUrl.startsWith("https") ? https : http;
|
|
20
|
+
const parsed = new URL(fullUrl);
|
|
21
|
+
|
|
22
|
+
const headers = {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
"User-Agent": "mcp-server-agentpay/1.0.0",
|
|
25
|
+
};
|
|
26
|
+
if (GATEWAY_KEY) headers["X-Gateway-Key"] = GATEWAY_KEY;
|
|
27
|
+
|
|
28
|
+
const opts = {
|
|
29
|
+
hostname: parsed.hostname,
|
|
30
|
+
port: parsed.port || (parsed.protocol === "https:" ? 443 : 80),
|
|
31
|
+
path: parsed.pathname + parsed.search,
|
|
32
|
+
method,
|
|
33
|
+
headers,
|
|
34
|
+
timeout,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const req = mod.request(opts, (res) => {
|
|
38
|
+
let data = "";
|
|
39
|
+
res.on("data", (c) => (data += c));
|
|
40
|
+
res.on("end", () => {
|
|
41
|
+
try {
|
|
42
|
+
const json = JSON.parse(data);
|
|
43
|
+
if (res.statusCode >= 400) return reject(new Error(json.error || `HTTP ${res.statusCode}`));
|
|
44
|
+
resolve(json);
|
|
45
|
+
} catch {
|
|
46
|
+
if (res.statusCode >= 400) return reject(new Error(`HTTP ${res.statusCode}: ${data.slice(0, 300)}`));
|
|
47
|
+
resolve(data);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
req.on("error", reject);
|
|
53
|
+
req.on("timeout", () => { req.destroy(); reject(new Error("Request timed out")); });
|
|
54
|
+
if (body) req.write(JSON.stringify(body));
|
|
55
|
+
req.end();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function noKeyError() {
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: "text", text: "Error: AGENTPAY_GATEWAY_KEY environment variable is required.\n\nRegister at https://agentpay.metaltorque.dev to get a gateway key.\nYou get $1 in free credits to start." }],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ── MCP Server ──────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
const server = new McpServer({
|
|
68
|
+
name: "agentpay",
|
|
69
|
+
version: "1.0.0",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// ── Tool: discover_tools ────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
server.tool(
|
|
75
|
+
"discover_tools",
|
|
76
|
+
"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.",
|
|
77
|
+
{
|
|
78
|
+
query: z.string().describe("Search keyword (e.g. 'security', 'seo', 'indexing', 'vulnerability')"),
|
|
79
|
+
},
|
|
80
|
+
async ({ query }) => {
|
|
81
|
+
try {
|
|
82
|
+
const result = await request("POST", "/gateway/discover", { query });
|
|
83
|
+
if (result.count === 0) {
|
|
84
|
+
return { content: [{ type: "text", text: `No tools found for "${query}". Try: security, seo, indexing, vulnerability, audit` }] };
|
|
85
|
+
}
|
|
86
|
+
return { content: [{ type: "text", text: JSON.stringify(result.tools, null, 2) }] };
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// ── Tool: list_tools ────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
server.tool(
|
|
96
|
+
"list_tools",
|
|
97
|
+
"List all available tools in the AgentPay gateway with their descriptions, methods, and pricing. No authentication required.",
|
|
98
|
+
{},
|
|
99
|
+
async () => {
|
|
100
|
+
try {
|
|
101
|
+
const result = await request("GET", "/gateway/tools");
|
|
102
|
+
return { content: [{ type: "text", text: JSON.stringify(result.tools, null, 2) }] };
|
|
103
|
+
} catch (e) {
|
|
104
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// ── Tool: check_balance ─────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
server.tool(
|
|
112
|
+
"check_balance",
|
|
113
|
+
"Check your AgentPay wallet balance, total credits funded, total spent, and which tools you have provisioned access to.",
|
|
114
|
+
{},
|
|
115
|
+
async () => {
|
|
116
|
+
if (!GATEWAY_KEY) return noKeyError();
|
|
117
|
+
try {
|
|
118
|
+
const result = await request("GET", "/gateway/balance");
|
|
119
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// ── Tool: call_tool ─────────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
server.tool(
|
|
129
|
+
"call_tool",
|
|
130
|
+
"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.",
|
|
131
|
+
{
|
|
132
|
+
tool: z.string().describe("Tool ID (e.g. 'agent-audit', 'indexforge')"),
|
|
133
|
+
method: z.string().describe("Method name (e.g. 'security_scan', 'scan_sitemap')"),
|
|
134
|
+
params_json: z.string().optional().describe("Method parameters as JSON string (e.g. '{\"url\": \"example.com\"}'). Omit if no params needed."),
|
|
135
|
+
},
|
|
136
|
+
async ({ tool, method, params_json }) => {
|
|
137
|
+
if (!GATEWAY_KEY) return noKeyError();
|
|
138
|
+
try {
|
|
139
|
+
let params = {};
|
|
140
|
+
if (params_json) {
|
|
141
|
+
try { params = JSON.parse(params_json); } catch { return { content: [{ type: "text", text: "Error: params_json must be valid JSON" }] }; }
|
|
142
|
+
}
|
|
143
|
+
const result = await request("POST", "/gateway/call", { tool, method, params }, 600_000);
|
|
144
|
+
const meta = `[Cost: $${(result.cost || 0).toFixed(2)} | Balance: $${(result.balance || 0).toFixed(2)} | Time: ${result.elapsed || 0}ms]`;
|
|
145
|
+
return {
|
|
146
|
+
content: [{ type: "text", text: `${meta}\n\n${JSON.stringify(result.result, null, 2)}` }],
|
|
147
|
+
};
|
|
148
|
+
} catch (e) {
|
|
149
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// ── Tool: provision_tool ────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
server.tool(
|
|
157
|
+
"provision_tool",
|
|
158
|
+
"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.",
|
|
159
|
+
{
|
|
160
|
+
tool: z.string().describe("Tool ID to provision (e.g. 'indexforge', 'agent-audit')"),
|
|
161
|
+
},
|
|
162
|
+
async ({ tool }) => {
|
|
163
|
+
if (!GATEWAY_KEY) return noKeyError();
|
|
164
|
+
try {
|
|
165
|
+
const result = await request("POST", "/gateway/provision", { tool });
|
|
166
|
+
return { content: [{ type: "text", text: `${result.status}: ${result.message}` }] };
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// ── Tool: get_usage ─────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
server.tool(
|
|
176
|
+
"get_usage",
|
|
177
|
+
"View your recent tool call history — which tools you called, what methods, how much each cost, and when.",
|
|
178
|
+
{
|
|
179
|
+
limit: z.number().default(20).describe("Number of recent calls to show (default: 20, max: 200)"),
|
|
180
|
+
},
|
|
181
|
+
async ({ limit }) => {
|
|
182
|
+
if (!GATEWAY_KEY) return noKeyError();
|
|
183
|
+
try {
|
|
184
|
+
const result = await request("GET", `/gateway/usage?limit=${limit}`);
|
|
185
|
+
return { content: [{ type: "text", text: JSON.stringify(result.usage, null, 2) }] };
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// ── Tool: fund_wallet ───────────────────────────────────────────────
|
|
193
|
+
|
|
194
|
+
server.tool(
|
|
195
|
+
"fund_wallet",
|
|
196
|
+
"Get a Stripe checkout URL to add credits to your wallet. Returns a link that a human can open to complete payment. Credits are added instantly after payment.",
|
|
197
|
+
{
|
|
198
|
+
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)"),
|
|
199
|
+
},
|
|
200
|
+
async ({ package: pkg }) => {
|
|
201
|
+
if (!GATEWAY_KEY) return noKeyError();
|
|
202
|
+
try {
|
|
203
|
+
const result = await request("POST", "/gateway/fund", { package: pkg });
|
|
204
|
+
return { content: [{ type: "text", text: `Checkout URL (share with a human to complete payment):\n${result.checkoutUrl}\n\nPackage: ${pkg} (${result.credits} credits)` }] };
|
|
205
|
+
} catch (e) {
|
|
206
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
// ── Start ───────────────────────────────────────────────────────────
|
|
212
|
+
|
|
213
|
+
async function main() {
|
|
214
|
+
const transport = new StdioServerTransport();
|
|
215
|
+
await server.connect(transport);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
main().catch((e) => {
|
|
219
|
+
console.error("MCP server error:", e);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-server-agentpay",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"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.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"mcp-server-agentpay": "index.js"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"mcp",
|
|
10
|
+
"mcp-server",
|
|
11
|
+
"model-context-protocol",
|
|
12
|
+
"agent-payment",
|
|
13
|
+
"agent-wallet",
|
|
14
|
+
"agent-gateway",
|
|
15
|
+
"payment-gateway",
|
|
16
|
+
"ai-agent",
|
|
17
|
+
"ai-tools",
|
|
18
|
+
"autonomous-agent",
|
|
19
|
+
"tool-discovery",
|
|
20
|
+
"tool-marketplace",
|
|
21
|
+
"api-marketplace",
|
|
22
|
+
"metered-billing",
|
|
23
|
+
"pay-per-use",
|
|
24
|
+
"claude",
|
|
25
|
+
"claude-code",
|
|
26
|
+
"llm",
|
|
27
|
+
"llm-tools",
|
|
28
|
+
"chatgpt",
|
|
29
|
+
"openai",
|
|
30
|
+
"agent-economy",
|
|
31
|
+
"machine-to-machine",
|
|
32
|
+
"api-credits"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"author": "MetalTorque",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/joepangallo/agent-pay"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@modelcontextprotocol/sdk": "^1.27.0"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"index.js",
|
|
48
|
+
"README.md"
|
|
49
|
+
]
|
|
50
|
+
}
|