rwagenthub-mcp 1.0.4 → 1.0.6
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/index.js +14 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -35,28 +35,29 @@ async function callGateway(api, inputs) {
|
|
|
35
35
|
});
|
|
36
36
|
if (res.status === 402) {
|
|
37
37
|
const body = await res.json().catch(() => ({}));
|
|
38
|
-
const reason = body?.error?.invalidReason ?? body?.error ?? "payment_failed";
|
|
38
|
+
const reason = body?.details ?? body?.error?.invalidReason ?? body?.error ?? "payment_failed";
|
|
39
39
|
throw new Error(`payment_failed:${reason}`);
|
|
40
40
|
}
|
|
41
41
|
return res.json();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
// ── Type mapper:
|
|
45
|
-
function toZod(
|
|
44
|
+
// ── Type mapper: JSON Schema property → Zod ───────────────────────────────────
|
|
45
|
+
function toZod(propName, prop, requiredList) {
|
|
46
46
|
let schema;
|
|
47
|
-
if (
|
|
47
|
+
if (prop.type === "number") {
|
|
48
48
|
schema = z.number();
|
|
49
|
-
} else if (
|
|
49
|
+
} else if (prop.type === "boolean") {
|
|
50
50
|
schema = z.boolean();
|
|
51
|
-
} else if (
|
|
51
|
+
} else if (prop.oneOf) {
|
|
52
52
|
schema = z.union([z.string(), z.array(z.string())]);
|
|
53
53
|
} else {
|
|
54
54
|
schema = z.string();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
if (
|
|
57
|
+
if (prop.description) schema = schema.describe(prop.description);
|
|
58
|
+
const isRequired = requiredList?.includes(propName);
|
|
59
|
+
if (!isRequired) schema = schema.optional();
|
|
60
|
+
if (prop.default !== undefined) schema = schema.default(prop.default);
|
|
60
61
|
return schema;
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -73,9 +74,10 @@ async function main() {
|
|
|
73
74
|
const server = new McpServer({ name: "agenthub", version: "1.0.0" });
|
|
74
75
|
|
|
75
76
|
for (const api of apis) {
|
|
77
|
+
const { properties = {}, required: requiredList = [] } = api.inputSchema ?? {};
|
|
76
78
|
const zodShape = {};
|
|
77
|
-
for (const [fieldName,
|
|
78
|
-
zodShape[fieldName] = toZod(
|
|
79
|
+
for (const [fieldName, prop] of Object.entries(properties)) {
|
|
80
|
+
zodShape[fieldName] = toZod(fieldName, prop, requiredList);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
server.tool(
|
|
@@ -104,15 +106,8 @@ async function main() {
|
|
|
104
106
|
msg.toLowerCase().includes("insufficient_funds") ||
|
|
105
107
|
msg.toLowerCase().includes("failed to create payment payload");
|
|
106
108
|
if (isPaymentError) {
|
|
107
|
-
const isNoFunds =
|
|
108
|
-
msg.includes("insufficient_funds") ||
|
|
109
|
-
msg.toLowerCase().includes("insufficient funds") ||
|
|
110
|
-
msg.toLowerCase().includes("failed to create payment payload");
|
|
111
|
-
const detail = isNoFunds
|
|
112
|
-
? `Insufficient USDC balance on Base.\nWallet: ${account.address}\n\nTop up your wallet with USDC on Base and try again.`
|
|
113
|
-
: `Payment rejected by gateway (${msg.replace("payment_failed:", "")}).\nWallet: ${account.address}`;
|
|
114
109
|
return {
|
|
115
|
-
content: [{ type: "text", text: `Payment failed: ${
|
|
110
|
+
content: [{ type: "text", text: `Payment failed: insufficient USDC balance on Base.\nWallet: ${account.address}\n\nTop up your wallet with USDC on Base and try again.` }],
|
|
116
111
|
isError: true,
|
|
117
112
|
};
|
|
118
113
|
}
|
package/package.json
CHANGED