apex-psi-mcp 1.3.0 → 1.3.1
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/LICENSE +29 -29
- package/README.md +260 -234
- package/conformance/agent-03-example.json +962 -351
- package/dist/payment.d.ts +33 -0
- package/dist/payment.js +46 -0
- package/package.json +82 -78
package/LICENSE
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 APEX Intelligence Empire / ROCKYFILMS888 PTY LTD (ABN 71 672 237 795), Victoria, Australia.
|
|
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.
|
|
22
|
-
|
|
23
|
-
NOTE ON SCOPE: this MIT grant covers the VERIFICATION software in this
|
|
24
|
-
repository only. The PSI-SEAL/1 canonical seal schema is a separately
|
|
25
|
-
copyrighted technical specification, and the APEX PSI Sealing Engine
|
|
26
|
-
(generator) is licensed separately — see LICENSE-ENGINE.txt in the APEX-PSI
|
|
27
|
-
repository. "APEX PSI", "PSI-SEAL" and the seal device are trade marks of
|
|
28
|
-
Apex Intelligence Empire; no right in them is granted here. Verification is
|
|
29
|
-
free forever and requires no account, no fee and no relationship with us.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 APEX Intelligence Empire / ROCKYFILMS888 PTY LTD (ABN 71 672 237 795), Victoria, Australia.
|
|
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.
|
|
22
|
+
|
|
23
|
+
NOTE ON SCOPE: this MIT grant covers the VERIFICATION software in this
|
|
24
|
+
repository only. The PSI-SEAL/1 canonical seal schema is a separately
|
|
25
|
+
copyrighted technical specification, and the APEX PSI Sealing Engine
|
|
26
|
+
(generator) is licensed separately — see LICENSE-ENGINE.txt in the APEX-PSI
|
|
27
|
+
repository. "APEX PSI", "PSI-SEAL" and the seal device are trade marks of
|
|
28
|
+
Apex Intelligence Empire; no right in them is granted here. Verification is
|
|
29
|
+
free forever and requires no account, no fee and no relationship with us.
|
package/README.md
CHANGED
|
@@ -1,234 +1,260 @@
|
|
|
1
|
-
<p align="center"><img src="https://raw.githubusercontent.com/kawal393/apex-psi-mcp-server/main/assets/apex-psi-icon.png" alt="APEX PSI mark: a check inside a hexagonal seal" width="96" height="96"></p>
|
|
2
|
-
|
|
3
|
-
# APEX PSI MCP server
|
|
4
|
-
|
|
5
|
-
[](https://mcprush.com/to/apex-psi-mcp?ref=badge)
|
|
6
|
-
|
|
7
|
-
> **Apex PSI is not a tool and not a product. It is the verification substrate — the layer beneath proof. It does not judge. It does not certify. It only remembers.** This server is one application built on that layer.
|
|
8
|
-
|
|
9
|
-
Machine-readable setup for agents and directory scrapers: [llms-install.md](https://github.com/kawal393/apex-psi-mcp-server/blob/main/llms-install.md).
|
|
10
|
-
|
|
11
|
-
One config line gives any MCP-capable agent (Claude, Cursor, Qoder, Cline, Windsurf, and the rest) five evidence tools: `seal`, `verify`, `anchor`, `cite`, `verify_chain`.
|
|
12
|
-
|
|
13
|
-
A seal records the SHA-256 hash of a decision, document or artefact in a public append-only ledger and returns a receipt. Anyone can look that hash up again — free, forever, with no account, no key and no cooperation from us.
|
|
14
|
-
|
|
15
|
-
**What a receipt proves:** that this exact content existed at this timestamp, and has not changed since.
|
|
16
|
-
**What it never proves:** that the content is true. A seal is an audit trail, not a verdict.
|
|
17
|
-
|
|
18
|
-
## Tools
|
|
19
|
-
|
|
20
|
-
| Tool | What it actually does |
|
|
21
|
-
|------|-------------|
|
|
22
|
-
| **seal** | Writes the record's SHA-256 hash to the ledger and returns a receipt carrying an Ed25519 signature over the Merkle leaf, an ML-DSA-65 post-quantum signature, and — when a slot is available — an LMS-W4-SHA256 signature. The receipt's own `algorithm` field states which of those it got. |
|
|
23
|
-
| **verify** | Looks a hash (or a whole receipt) up in the ledger and reports whether it is present and unchanged. Integrity, not truth. |
|
|
24
|
-
| **anchor** | Reads the Bitcoin/OpenTimestamps anchoring state of the ledger's pending Merkle roots. Pass `action: "anchor"` explicitly to request that pending roots be submitted — an anchor is confirmed only when a real block is found. |
|
|
25
|
-
| **cite** | Turns a receipt into a citation (APA, BibTeX, MLA) that points at a public, independently checkable record. |
|
|
26
|
-
| **verify_chain** | Recomputes each hash's presence and Merkle continuity across a chain of receipts. A recomputation result, not an opinion. |
|
|
27
|
-
|
|
28
|
-
## Install
|
|
29
|
-
|
|
30
|
-
Add to your MCP client config:
|
|
31
|
-
|
|
32
|
-
```json
|
|
33
|
-
{
|
|
34
|
-
"mcpServers": {
|
|
35
|
-
"apex-psi": {
|
|
36
|
-
"command": "npx",
|
|
37
|
-
"args": ["-y", "apex-psi-mcp"]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Or locally: `npm install apex-psi-mcp`.
|
|
44
|
-
|
|
45
|
-
## Prove it works in two minutes
|
|
46
|
-
|
|
47
|
-
1. Ask the agent: *"Seal the sentence 'hello psi' with APEX PSI."*
|
|
48
|
-
2. Take the `decision_hash` from the receipt and paste it into the public verifier:
|
|
49
|
-
<https://www.ai-governance-standard.com/verify>
|
|
50
|
-
|
|
51
|
-
If the site returns the record, the seal is real. You never had to trust this server, our npm
|
|
52
|
-
package, or our word — which is the entire point of the protocol.
|
|
53
|
-
|
|
54
|
-
## Limits, stated plainly
|
|
55
|
-
|
|
56
|
-
Free use needs no account and no key: **20 operations per minute and 100 per day**, enforced per
|
|
57
|
-
server instance — a flood guard rather than a subscription quota. Above that, an API key raises the
|
|
58
|
-
ceiling; capacity is priced, **the finding never is**. Verification itself is unlimited and free:
|
|
59
|
-
running the verifier locally costs nothing at all —
|
|
60
|
-
[`apex-psi-verifier`](https://www.npmjs.com/package/apex-psi-verifier) on npm,
|
|
61
|
-
[`psi-verifier`](https://pypi.org/project/psi-verifier/) on PyPI.
|
|
62
|
-
|
|
63
|
-
## Make the seal unavoidable: the execution gate
|
|
64
|
-
|
|
65
|
-
The five tools above are available to an agent, but nothing in MCP makes an agent call them. An
|
|
66
|
-
agent that never calls `seal` leaves no gap in the ledger — the ledger stays complete and says
|
|
67
|
-
nothing about that action. If your agent can move money, send a request or write to a system, that
|
|
68
|
-
gap is the whole problem.
|
|
69
|
-
|
|
70
|
-
So this package also ships a **gate**: a small module that seals first and acts second, inside the
|
|
71
|
-
process that performs the side effect.
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
import { createGate, createNotarySealer } from "apex-psi-mcp/gate";
|
|
75
|
-
|
|
76
|
-
const gate = createGate({ sealer: createNotarySealer(), label: "payments-bot" });
|
|
77
|
-
|
|
78
|
-
const { value, receipt } = await gate.run(
|
|
79
|
-
() => payments.transfer({ amount: 500, to: "acct-42" }),
|
|
80
|
-
{ tool: "transfer", amount: 500, to: "acct-42" },
|
|
81
|
-
);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
If the seal fails, `payments.transfer` is never called — the gate throws `GateClosedError`. A gate
|
|
85
|
-
with no sealer configured refuses every action, because a gate nobody configured must not look like
|
|
86
|
-
a gate that is working.
|
|
87
|
-
|
|
88
|
-
What the gate does and does not do, stated plainly:
|
|
89
|
-
|
|
90
|
-
- It enforces the **order**: the receipt exists before the action runs.
|
|
91
|
-
- It cannot reach a process that never routes its side effect through it.
|
|
92
|
-
- It cannot attest what a model did inside a GPU; the receipt covers the action as you declared it
|
|
93
|
-
and the order in which the two happened.
|
|
94
|
-
- `createLocalSealer()` seals into an in-process hash chain with no network and no account — a local
|
|
95
|
-
permit, not a ledger receipt. `createNotarySealer()` returns a ledger receipt.
|
|
96
|
-
|
|
97
|
-
The same gate exists in the Python runtime as `apex_psi.ExecutionGate`. The two implementations
|
|
98
|
-
fingerprint the same bytes: `fingerprint({"b":1,"a":[1,2],"c":"x"})` is
|
|
99
|
-
`95c12ab4ca0e8f3c485ea1b1b1a2b24976d07180baf5ecad0d81b5bbaf07532b` in both, and a CI check on each
|
|
100
|
-
side pins that number.
|
|
101
|
-
|
|
102
|
-
## The receiver gate: refusing an action that was not permitted
|
|
103
|
-
|
|
104
|
-
The gate above lives on the sender's side, and it is optional: an agent that
|
|
105
|
-
never calls `seal` leaves no gap in the ledger, and the ledger stays complete
|
|
106
|
-
and says nothing about that action. The receiver gate is the half that is not
|
|
107
|
-
optional, because it sits in the process that performs the side effect.
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
import { createReceiverGate } from "apex-psi-mcp/receiver";
|
|
111
|
-
|
|
112
|
-
const gate = createReceiverGate({
|
|
113
|
-
resolveKey: (kid) => keyring[kid], // kid -> Ed25519 public key
|
|
114
|
-
mode: "enforce", // "shadow" observes without blocking
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const result = await gate.authorize({
|
|
118
|
-
envelope,
|
|
119
|
-
mandate,
|
|
120
|
-
proposal,
|
|
121
|
-
decision,
|
|
122
|
-
tool: "transfer",
|
|
123
|
-
args: { amount: "10.00", to: "acct-42" },
|
|
124
|
-
actorKid: "agent-key",
|
|
125
|
-
});
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
`authorize` returns `{ allowed, enforced, wouldAllow, reason, report, permit }`.
|
|
129
|
-
In `enforce` mode a refused action never runs: `gate.run(request, fn)` throws
|
|
130
|
-
`ReceiverRefusedError` and `fn` is not called. `reason` is a stable code —
|
|
131
|
-
`missing_authority`, `decision_not_allow`, `outside_window`, `over_spend`,
|
|
132
|
-
`over_actions`, `replay`, `args_mismatch`, `scope_not_permitted`,
|
|
133
|
-
`currency_not_permitted`, `settlement_did_mismatch`, `signature_invalid`,
|
|
134
|
-
`key_unresolved`, `algorithm_unavailable`, `decision_key_is_action_key`,
|
|
135
|
-
`mandate_key_is_decision_key`, `mandate_key_is_action_key` — and the report
|
|
136
|
-
carries the reason codes of `draft-singh-psi-agent-03` for the checks the
|
|
137
|
-
contract defines.
|
|
138
|
-
|
|
139
|
-
`shadow` mode turns the gate on without breaking anything: it reports the same
|
|
140
|
-
reasons and lets the action through, recording what would have been refused.
|
|
141
|
-
It does not refuse.
|
|
142
|
-
|
|
143
|
-
What the receiver recomputes, from `draft-singh-psi-agent-03`:
|
|
144
|
-
|
|
145
|
-
- The mandate, proposal, decision and envelope each recompute to the identifier
|
|
146
|
-
they carry, and each signature verifies under the key it names. An algorithm
|
|
147
|
-
this server does not implement is reported, never guessed at.
|
|
148
|
-
- Every statement carries the run identifier of the envelope. The proposal
|
|
149
|
-
names the mandate, and the decision names the proposal.
|
|
150
|
-
- Amounts are decimal strings compared exactly — never as floating point — and
|
|
151
|
-
the asset is compared as an exact, case-sensitive string.
|
|
152
|
-
- The mandate's window, action count and spend limit hold.
|
|
153
|
-
- A proposal already accepted once is a replay and is refused.
|
|
154
|
-
- The acting key is neither the decision key nor the mandate key.
|
|
155
|
-
|
|
156
|
-
Settlement statuses stay distinct. `authorised` records that a limit was
|
|
157
|
-
reserved; it does not record that money moved, and nothing here reports it as
|
|
158
|
-
money moved.
|
|
159
|
-
|
|
160
|
-
## The sender: seal first, act second, bind the settlement
|
|
161
|
-
|
|
162
|
-
`createMandatedSender` wraps an action in the mandate that permitted it:
|
|
163
|
-
|
|
164
|
-
```js
|
|
165
|
-
import { createNotarySealer } from "apex-psi-mcp/gate";
|
|
166
|
-
import { createMandatedSender } from "apex-psi-mcp/sender";
|
|
167
|
-
|
|
168
|
-
const sender = createMandatedSender({
|
|
169
|
-
mandate,
|
|
170
|
-
proposal,
|
|
171
|
-
decision,
|
|
172
|
-
sealer: createNotarySealer(),
|
|
173
|
-
actorKid: "agent-key",
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const { value, receipt, actionRecord, chainRoot } = await sender.execute(
|
|
177
|
-
"transfer",
|
|
178
|
-
{ amount: "10.00", to: "acct-42" },
|
|
179
|
-
() => payments.transfer({ amount: "10.00", to: "acct-42" }),
|
|
180
|
-
);
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
The sender refuses arguments the proposal never described, a decision that did
|
|
184
|
-
not say `allow`, and a tool outside the mandate's scope. The seal happens
|
|
185
|
-
before the action, so a failed seal leaves the action uncalled. A retry of the
|
|
186
|
-
same proposal runs the action once. `bindSettlement` refuses a settlement whose
|
|
187
|
-
decision does not match, whose currency the mandate does not permit, or whose
|
|
188
|
-
amount exceeds the mandate's limit.
|
|
189
|
-
|
|
190
|
-
##
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/kawal393/apex-psi-mcp-server/main/assets/apex-psi-icon.png" alt="APEX PSI mark: a check inside a hexagonal seal" width="96" height="96"></p>
|
|
2
|
+
|
|
3
|
+
# APEX PSI MCP server
|
|
4
|
+
|
|
5
|
+
[](https://mcprush.com/to/apex-psi-mcp?ref=badge)
|
|
6
|
+
|
|
7
|
+
> **Apex PSI is not a tool and not a product. It is the verification substrate — the layer beneath proof. It does not judge. It does not certify. It only remembers.** This server is one application built on that layer.
|
|
8
|
+
|
|
9
|
+
Machine-readable setup for agents and directory scrapers: [llms-install.md](https://github.com/kawal393/apex-psi-mcp-server/blob/main/llms-install.md).
|
|
10
|
+
|
|
11
|
+
One config line gives any MCP-capable agent (Claude, Cursor, Qoder, Cline, Windsurf, and the rest) five evidence tools: `seal`, `verify`, `anchor`, `cite`, `verify_chain`.
|
|
12
|
+
|
|
13
|
+
A seal records the SHA-256 hash of a decision, document or artefact in a public append-only ledger and returns a receipt. Anyone can look that hash up again — free, forever, with no account, no key and no cooperation from us.
|
|
14
|
+
|
|
15
|
+
**What a receipt proves:** that this exact content existed at this timestamp, and has not changed since.
|
|
16
|
+
**What it never proves:** that the content is true. A seal is an audit trail, not a verdict.
|
|
17
|
+
|
|
18
|
+
## Tools
|
|
19
|
+
|
|
20
|
+
| Tool | What it actually does |
|
|
21
|
+
|------|-------------|
|
|
22
|
+
| **seal** | Writes the record's SHA-256 hash to the ledger and returns a receipt carrying an Ed25519 signature over the Merkle leaf, an ML-DSA-65 post-quantum signature, and — when a slot is available — an LMS-W4-SHA256 signature. The receipt's own `algorithm` field states which of those it got. |
|
|
23
|
+
| **verify** | Looks a hash (or a whole receipt) up in the ledger and reports whether it is present and unchanged. Integrity, not truth. |
|
|
24
|
+
| **anchor** | Reads the Bitcoin/OpenTimestamps anchoring state of the ledger's pending Merkle roots. Pass `action: "anchor"` explicitly to request that pending roots be submitted — an anchor is confirmed only when a real block is found. |
|
|
25
|
+
| **cite** | Turns a receipt into a citation (APA, BibTeX, MLA) that points at a public, independently checkable record. |
|
|
26
|
+
| **verify_chain** | Recomputes each hash's presence and Merkle continuity across a chain of receipts. A recomputation result, not an opinion. |
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
Add to your MCP client config:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"apex-psi": {
|
|
36
|
+
"command": "npx",
|
|
37
|
+
"args": ["-y", "apex-psi-mcp"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or locally: `npm install apex-psi-mcp`.
|
|
44
|
+
|
|
45
|
+
## Prove it works in two minutes
|
|
46
|
+
|
|
47
|
+
1. Ask the agent: *"Seal the sentence 'hello psi' with APEX PSI."*
|
|
48
|
+
2. Take the `decision_hash` from the receipt and paste it into the public verifier:
|
|
49
|
+
<https://www.ai-governance-standard.com/verify>
|
|
50
|
+
|
|
51
|
+
If the site returns the record, the seal is real. You never had to trust this server, our npm
|
|
52
|
+
package, or our word — which is the entire point of the protocol.
|
|
53
|
+
|
|
54
|
+
## Limits, stated plainly
|
|
55
|
+
|
|
56
|
+
Free use needs no account and no key: **20 operations per minute and 100 per day**, enforced per
|
|
57
|
+
server instance — a flood guard rather than a subscription quota. Above that, an API key raises the
|
|
58
|
+
ceiling; capacity is priced, **the finding never is**. Verification itself is unlimited and free:
|
|
59
|
+
running the verifier locally costs nothing at all —
|
|
60
|
+
[`apex-psi-verifier`](https://www.npmjs.com/package/apex-psi-verifier) on npm,
|
|
61
|
+
[`psi-verifier`](https://pypi.org/project/psi-verifier/) on PyPI.
|
|
62
|
+
|
|
63
|
+
## Make the seal unavoidable: the execution gate
|
|
64
|
+
|
|
65
|
+
The five tools above are available to an agent, but nothing in MCP makes an agent call them. An
|
|
66
|
+
agent that never calls `seal` leaves no gap in the ledger — the ledger stays complete and says
|
|
67
|
+
nothing about that action. If your agent can move money, send a request or write to a system, that
|
|
68
|
+
gap is the whole problem.
|
|
69
|
+
|
|
70
|
+
So this package also ships a **gate**: a small module that seals first and acts second, inside the
|
|
71
|
+
process that performs the side effect.
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { createGate, createNotarySealer } from "apex-psi-mcp/gate";
|
|
75
|
+
|
|
76
|
+
const gate = createGate({ sealer: createNotarySealer(), label: "payments-bot" });
|
|
77
|
+
|
|
78
|
+
const { value, receipt } = await gate.run(
|
|
79
|
+
() => payments.transfer({ amount: 500, to: "acct-42" }),
|
|
80
|
+
{ tool: "transfer", amount: 500, to: "acct-42" },
|
|
81
|
+
);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
If the seal fails, `payments.transfer` is never called — the gate throws `GateClosedError`. A gate
|
|
85
|
+
with no sealer configured refuses every action, because a gate nobody configured must not look like
|
|
86
|
+
a gate that is working.
|
|
87
|
+
|
|
88
|
+
What the gate does and does not do, stated plainly:
|
|
89
|
+
|
|
90
|
+
- It enforces the **order**: the receipt exists before the action runs.
|
|
91
|
+
- It cannot reach a process that never routes its side effect through it.
|
|
92
|
+
- It cannot attest what a model did inside a GPU; the receipt covers the action as you declared it
|
|
93
|
+
and the order in which the two happened.
|
|
94
|
+
- `createLocalSealer()` seals into an in-process hash chain with no network and no account — a local
|
|
95
|
+
permit, not a ledger receipt. `createNotarySealer()` returns a ledger receipt.
|
|
96
|
+
|
|
97
|
+
The same gate exists in the Python runtime as `apex_psi.ExecutionGate`. The two implementations
|
|
98
|
+
fingerprint the same bytes: `fingerprint({"b":1,"a":[1,2],"c":"x"})` is
|
|
99
|
+
`95c12ab4ca0e8f3c485ea1b1b1a2b24976d07180baf5ecad0d81b5bbaf07532b` in both, and a CI check on each
|
|
100
|
+
side pins that number.
|
|
101
|
+
|
|
102
|
+
## The receiver gate: refusing an action that was not permitted
|
|
103
|
+
|
|
104
|
+
The gate above lives on the sender's side, and it is optional: an agent that
|
|
105
|
+
never calls `seal` leaves no gap in the ledger, and the ledger stays complete
|
|
106
|
+
and says nothing about that action. The receiver gate is the half that is not
|
|
107
|
+
optional, because it sits in the process that performs the side effect.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { createReceiverGate } from "apex-psi-mcp/receiver";
|
|
111
|
+
|
|
112
|
+
const gate = createReceiverGate({
|
|
113
|
+
resolveKey: (kid) => keyring[kid], // kid -> Ed25519 public key
|
|
114
|
+
mode: "enforce", // "shadow" observes without blocking
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const result = await gate.authorize({
|
|
118
|
+
envelope,
|
|
119
|
+
mandate,
|
|
120
|
+
proposal,
|
|
121
|
+
decision,
|
|
122
|
+
tool: "transfer",
|
|
123
|
+
args: { amount: "10.00", to: "acct-42" },
|
|
124
|
+
actorKid: "agent-key",
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`authorize` returns `{ allowed, enforced, wouldAllow, reason, report, permit }`.
|
|
129
|
+
In `enforce` mode a refused action never runs: `gate.run(request, fn)` throws
|
|
130
|
+
`ReceiverRefusedError` and `fn` is not called. `reason` is a stable code —
|
|
131
|
+
`missing_authority`, `decision_not_allow`, `outside_window`, `over_spend`,
|
|
132
|
+
`over_actions`, `replay`, `args_mismatch`, `scope_not_permitted`,
|
|
133
|
+
`currency_not_permitted`, `settlement_did_mismatch`, `signature_invalid`,
|
|
134
|
+
`key_unresolved`, `algorithm_unavailable`, `decision_key_is_action_key`,
|
|
135
|
+
`mandate_key_is_decision_key`, `mandate_key_is_action_key` — and the report
|
|
136
|
+
carries the reason codes of `draft-singh-psi-agent-03` for the checks the
|
|
137
|
+
contract defines.
|
|
138
|
+
|
|
139
|
+
`shadow` mode turns the gate on without breaking anything: it reports the same
|
|
140
|
+
reasons and lets the action through, recording what would have been refused.
|
|
141
|
+
It does not refuse.
|
|
142
|
+
|
|
143
|
+
What the receiver recomputes, from `draft-singh-psi-agent-03`:
|
|
144
|
+
|
|
145
|
+
- The mandate, proposal, decision and envelope each recompute to the identifier
|
|
146
|
+
they carry, and each signature verifies under the key it names. An algorithm
|
|
147
|
+
this server does not implement is reported, never guessed at.
|
|
148
|
+
- Every statement carries the run identifier of the envelope. The proposal
|
|
149
|
+
names the mandate, and the decision names the proposal.
|
|
150
|
+
- Amounts are decimal strings compared exactly — never as floating point — and
|
|
151
|
+
the asset is compared as an exact, case-sensitive string.
|
|
152
|
+
- The mandate's window, action count and spend limit hold.
|
|
153
|
+
- A proposal already accepted once is a replay and is refused.
|
|
154
|
+
- The acting key is neither the decision key nor the mandate key.
|
|
155
|
+
|
|
156
|
+
Settlement statuses stay distinct. `authorised` records that a limit was
|
|
157
|
+
reserved; it does not record that money moved, and nothing here reports it as
|
|
158
|
+
money moved.
|
|
159
|
+
|
|
160
|
+
## The sender: seal first, act second, bind the settlement
|
|
161
|
+
|
|
162
|
+
`createMandatedSender` wraps an action in the mandate that permitted it:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
import { createNotarySealer } from "apex-psi-mcp/gate";
|
|
166
|
+
import { createMandatedSender } from "apex-psi-mcp/sender";
|
|
167
|
+
|
|
168
|
+
const sender = createMandatedSender({
|
|
169
|
+
mandate,
|
|
170
|
+
proposal,
|
|
171
|
+
decision,
|
|
172
|
+
sealer: createNotarySealer(),
|
|
173
|
+
actorKid: "agent-key",
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const { value, receipt, actionRecord, chainRoot } = await sender.execute(
|
|
177
|
+
"transfer",
|
|
178
|
+
{ amount: "10.00", to: "acct-42" },
|
|
179
|
+
() => payments.transfer({ amount: "10.00", to: "acct-42" }),
|
|
180
|
+
);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The sender refuses arguments the proposal never described, a decision that did
|
|
184
|
+
not say `allow`, and a tool outside the mandate's scope. The seal happens
|
|
185
|
+
before the action, so a failed seal leaves the action uncalled. A retry of the
|
|
186
|
+
same proposal runs the action once. `bindSettlement` refuses a settlement whose
|
|
187
|
+
decision does not match, whose currency the mandate does not permit, or whose
|
|
188
|
+
amount exceeds the mandate's limit.
|
|
189
|
+
|
|
190
|
+
## The money rules of a payment door
|
|
191
|
+
|
|
192
|
+
The receiver gate checks a spend limit only against a settlement, and a
|
|
193
|
+
payment request carries no settlement. A limit belongs to the mandate, so
|
|
194
|
+
applying it to the amount about to be charged is a separate rule, and it
|
|
195
|
+
lives in its own module so the door and its tests run the same code:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
import { evaluatePayment } from "apex-psi-mcp/payment";
|
|
199
|
+
|
|
200
|
+
const verdict = evaluatePayment({ tool, args, mandate }, tiers, {
|
|
201
|
+
expectedTool: "checkout",
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
It refuses a request that names another tool, a tier the server does not sell,
|
|
206
|
+
an amount that is not minor units, an amount above the tier's ceiling or above
|
|
207
|
+
the mandate's `max_spend`, and a currency the mandate does not permit. The
|
|
208
|
+
comparison is exact decimal: `1101` is over `11.00` and `1099` is under it.
|
|
209
|
+
|
|
210
|
+
## Prove the gate in two commands
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
npm run check:agent # the built receiver refuses every case it must refuse
|
|
214
|
+
npm run check:parity # Node and Python sign the same bytes
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`conformance/agent-03.json` holds the frozen contract: the profile, the signed
|
|
218
|
+
bytes rule, the decimal rule, and the refusal cases the suite proves.
|
|
219
|
+
|
|
220
|
+
`conformance/agent-03-example.json` holds one signed run you can verify
|
|
221
|
+
yourself: the statements, the public keyring, one request that must be
|
|
222
|
+
permitted, and seventeen requests that must each be refused for a stated reason.
|
|
223
|
+
Those reasons were measured against the built gate, and
|
|
224
|
+
`npm run check:example` fails if the gate ever answers differently. The keys in
|
|
225
|
+
that file are test keys, made for the file and discarded when it was written;
|
|
226
|
+
they sign nothing outside the file.
|
|
227
|
+
|
|
228
|
+
It also carries a `payment` section: one permitted payment, with the tier and
|
|
229
|
+
the amount in it, and seven refusals a payment door must make. Each one names
|
|
230
|
+
whether the gate refuses it or the door's own money rules do, so a reader can
|
|
231
|
+
tell the two halves apart. `npm run check:payment` proves both halves against
|
|
232
|
+
the built modules.
|
|
233
|
+
|
|
234
|
+
## Configuration
|
|
235
|
+
|
|
236
|
+
Environment variables (both optional):
|
|
237
|
+
|
|
238
|
+
- `APEX_API_BASE` — override the notary endpoint. Default:
|
|
239
|
+
`https://qhtntebpcribjiwrdtdd.supabase.co/functions/v1`
|
|
240
|
+
- `APEX_API_KEY` — raises the daily ceiling for a workload. Never required to seal or verify.
|
|
241
|
+
|
|
242
|
+
## What this server does not do
|
|
243
|
+
|
|
244
|
+
- It does not store your content. Only the hash leaves your machine.
|
|
245
|
+
- It does not certify, grade, score or approve anything.
|
|
246
|
+
- It exposes no edit or delete path: the interface this server uses is write-once sealing plus
|
|
247
|
+
read-only lookup. The check that matters is yours to run — re-verify any receipt at any time, and
|
|
248
|
+
any change shows up as a failed lookup.
|
|
249
|
+
- It is not a legal opinion, and no court has agreed to accept a receipt in advance.
|
|
250
|
+
|
|
251
|
+
## Links
|
|
252
|
+
|
|
253
|
+
- **Protocol and standard:** <https://www.ai-governance-standard.com>
|
|
254
|
+
- **Public verifier:** <https://www.ai-governance-standard.com/verify>
|
|
255
|
+
- **Machine-readable summary for AI answers:** <https://www.ai-governance-standard.com/llms.txt>
|
|
256
|
+
- **npm:** <https://www.npmjs.com/package/apex-psi-mcp>
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT
|