@paystage/mcp 0.4.0 → 0.5.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 +8 -0
- package/dist/policy-cli.d.ts +3 -0
- package/dist/policy-cli.js +91 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -188,3 +188,11 @@ signer, which is the entire product.
|
|
|
188
188
|
| `decode_payment_required` | what does this base64 402 header actually say |
|
|
189
189
|
| `validate_policy` | is this policy document valid, and if not why |
|
|
190
190
|
|
|
191
|
+
## Check a policy file before you run anything
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
npx -y -p @paystage/mcp paystage-policy check policy.json
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Exit `0` valid, `1` invalid (one line per offending field), `2` unreadable. Offline, no key, no signup —
|
|
198
|
+
the same schema the evaluator enforces, so a file that passes here is a file that will load there.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `paystage-policy check <file>` — does this policy parse?
|
|
4
|
+
*
|
|
5
|
+
* The most common support question is not "what verdict" but "why does my policy file not load". The
|
|
6
|
+
* answer today requires installing a package, writing a script and reading a stack trace. This answers
|
|
7
|
+
* it in one command, offline, with the exact message the evaluator would have produced.
|
|
8
|
+
*
|
|
9
|
+
* paystage-policy check policy.json # exit 0 valid · 1 invalid · 2 unreadable
|
|
10
|
+
* paystage-policy check --json policy.json
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { parsePolicy } from "@paystage/policy";
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const asJson = args.includes("--json");
|
|
16
|
+
const positional = args.filter((a) => !a.startsWith("-"));
|
|
17
|
+
const verb = positional[0] === "check" ? "check" : null;
|
|
18
|
+
const file = verb ? positional[1] : positional[0];
|
|
19
|
+
if (!file) {
|
|
20
|
+
console.error("usage: paystage-policy check <policy.json> [--json]");
|
|
21
|
+
process.exit(2);
|
|
22
|
+
}
|
|
23
|
+
let raw;
|
|
24
|
+
try {
|
|
25
|
+
raw = readFileSync(file, "utf8");
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
29
|
+
if (asJson)
|
|
30
|
+
console.log(JSON.stringify({ ok: false, stage: "read", error: message }, null, 2));
|
|
31
|
+
else
|
|
32
|
+
console.error(`cannot read ${file}: ${message}`);
|
|
33
|
+
process.exit(2);
|
|
34
|
+
}
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = JSON.parse(raw);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
+
if (asJson)
|
|
42
|
+
console.log(JSON.stringify({ ok: false, stage: "json", error: message }, null, 2));
|
|
43
|
+
else
|
|
44
|
+
console.error(`${file} is not valid JSON: ${message}`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const policy = parsePolicy(parsed);
|
|
49
|
+
if (asJson) {
|
|
50
|
+
console.log(JSON.stringify({ ok: true, file, policy }, null, 2));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const caps = [
|
|
54
|
+
policy.max_amount ? `max_amount ${policy.max_amount.value}` : "no max_amount",
|
|
55
|
+
Array.isArray(policy.allowed_networks) && policy.allowed_networks.length
|
|
56
|
+
? `networks ${policy.allowed_networks.join(", ")}`
|
|
57
|
+
: "no allowed_networks",
|
|
58
|
+
policy.unknown_payee ? `unknown_payee ${policy.unknown_payee}` : "unknown_payee unset",
|
|
59
|
+
];
|
|
60
|
+
console.log(`${file}: valid`);
|
|
61
|
+
console.log(` ${caps.join(" · ")}`);
|
|
62
|
+
}
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
// The Zod message is the point: it names the field and the problem, which is what a stack trace
|
|
67
|
+
// buries. Print it verbatim rather than wrapping it.
|
|
68
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
69
|
+
if (asJson) {
|
|
70
|
+
console.log(JSON.stringify({ ok: false, stage: "policy", error: message }, null, 2));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
console.error(`${file}: invalid`);
|
|
74
|
+
try {
|
|
75
|
+
const issues = JSON.parse(message);
|
|
76
|
+
if (Array.isArray(issues)) {
|
|
77
|
+
// One line per field, because that is the question: which field, and what is wrong with it.
|
|
78
|
+
for (const issue of issues) {
|
|
79
|
+
const where = Array.isArray(issue.path) && issue.path.length ? issue.path.join(".") : "(root)";
|
|
80
|
+
console.error(` ${where}: ${issue.message ?? "invalid"}`);
|
|
81
|
+
}
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Not the structured form; fall through to the raw message.
|
|
87
|
+
}
|
|
88
|
+
console.error(message.split("\n").map((l) => ` ${l}`).join("\n"));
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=policy-cli.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paystage/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "PayStage umbrella MCP: payment preflight, auth watch, HIP-3 trade preflight, and velocity rate/spend-pattern checks",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"bin": {
|
|
21
21
|
"paystage-mcp": "dist/cli.js",
|
|
22
|
-
"paystage-verify": "dist/verify-cli.js"
|
|
22
|
+
"paystage-verify": "dist/verify-cli.js",
|
|
23
|
+
"paystage-policy": "dist/policy-cli.js"
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
25
26
|
"dist",
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"vitest": "^4.1.12"
|
|
68
69
|
},
|
|
69
70
|
"scripts": {
|
|
70
|
-
"build": "tsc && chmod +x dist/cli.js dist/verify-cli.js",
|
|
71
|
+
"build": "tsc && chmod +x dist/cli.js dist/verify-cli.js dist/policy-cli.js",
|
|
71
72
|
"test": "vitest run",
|
|
72
73
|
"typecheck": "tsc --noEmit",
|
|
73
74
|
"prepublishOnly": "npm run build"
|