tereno-mcp 0.1.3 → 0.1.4
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 +22 -6
- package/bin/tereno-mcp.mjs +61 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,9 +93,21 @@ miss nothing to reuse — this call computes it, and the next asker pays les
|
|
|
93
93
|
| 🤝 `demand_pledge` | free | Name a capability you would pay for. Credit only after the same wallet pays for it later |
|
|
94
94
|
|
|
95
95
|
Calling a paid tool returns a `402` carrying the payment challenge in
|
|
96
|
-
`error.data.paymentRequired
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
`error.data.paymentRequired`, the payable resource URL in `error.data.resource`,
|
|
97
|
+
and the terms (network, asset, amount, `payTo`) in `error.data.offer`.
|
|
98
|
+
|
|
99
|
+
**Over stdio you cannot pay by retrying the tool call.** stdio has no headers in
|
|
100
|
+
either direction, so there is nowhere for a `PAYMENT-SIGNATURE` to travel back
|
|
101
|
+
through. Two ways to settle, both of which leave **this package never touching a
|
|
102
|
+
private key**:
|
|
103
|
+
|
|
104
|
+
- **Pay the resource over HTTP.** Sign `error.data.paymentRequired` with your
|
|
105
|
+
x402 client and send the signed request to `error.data.resource`. It returns
|
|
106
|
+
the same payload the tool would have, receipt included, billed once.
|
|
107
|
+
- **Use the remote server instead of this package.** If your client supports
|
|
108
|
+
remote MCP, point it at `https://www.tereno.xyz/api/mcp`. That transport does
|
|
109
|
+
have headers, so signing the challenge and retrying the same tool call is the
|
|
110
|
+
normal flow and everything stays inside MCP.
|
|
99
111
|
|
|
100
112
|
> 🔒 `transaction_intent_guard` is never cached, shared or resold. An unsigned
|
|
101
113
|
> transaction is intent, and it stays with the wallet that paid for it.
|
|
@@ -116,9 +128,13 @@ It is a **stdio transport** in front of the hosted endpoint at
|
|
|
116
128
|
the tool list, the prices and the payment challenge all come from the same place
|
|
117
129
|
an HTTP agent sees — and this package needs no release when a capability changes.
|
|
118
130
|
|
|
119
|
-
The one thing it translates is payment
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
The one thing it translates is payment, and the translation is lossy in one
|
|
132
|
+
direction. Over HTTP the challenge arrives in a response header and the caller
|
|
133
|
+
retries with a `PAYMENT-SIGNATURE` header. stdio has neither, so the challenge is
|
|
134
|
+
folded into the JSON-RPC error payload where a client can still reach it, while
|
|
135
|
+
the signature has no way back in. That is why a paid call is settled against the
|
|
136
|
+
resource URL rather than by retrying the tool, and why a client that speaks
|
|
137
|
+
remote MCP should prefer the hosted endpoint.
|
|
122
138
|
|
|
123
139
|
**No private key is ever read, stored or transmitted.** There are no
|
|
124
140
|
dependencies, and the whole thing is one readable file — [read it](./bin/tereno-mcp.mjs)
|
package/bin/tereno-mcp.mjs
CHANGED
|
@@ -7,15 +7,24 @@
|
|
|
7
7
|
// the payment challenge all come from the same place an HTTP agent sees, and
|
|
8
8
|
// this package never has to be redeployed when a capability changes.
|
|
9
9
|
//
|
|
10
|
-
// The one thing it does translate is payment
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// The one thing it does translate is payment, and the translation is lossy in a
|
|
11
|
+
// way worth naming. Over HTTP the 402 challenge arrives in a response header and
|
|
12
|
+
// the caller retries with a PAYMENT-SIGNATURE header. stdio has no headers in
|
|
13
|
+
// either direction: the challenge can still be folded into the JSON-RPC error
|
|
14
|
+
// payload, but the signature has nowhere to come back through. So a paid tool
|
|
15
|
+
// cannot be settled by retrying it here, and saying otherwise sends an agent
|
|
16
|
+
// round a loop with no exit.
|
|
17
|
+
//
|
|
18
|
+
// What it does instead is hand the call off: the challenge names the capability's
|
|
19
|
+
// own invoke URL, which is payable by any x402 HTTP client and returns the same
|
|
20
|
+
// payload this tool would have. The 402 below says that explicitly and points at
|
|
21
|
+
// that URL rather than at this endpoint.
|
|
13
22
|
|
|
14
23
|
import { createInterface } from "node:readline";
|
|
15
24
|
|
|
16
25
|
// Travels in the user-agent, and the demand panel counts installs by it, so it
|
|
17
26
|
// has to track the published version rather than drift from it.
|
|
18
|
-
const VERSION = "0.1.
|
|
27
|
+
const VERSION = "0.1.4";
|
|
19
28
|
const BASE_URL = (process.env.TERENO_BASE_URL || "https://www.tereno.xyz").replace(/\/+$/, "");
|
|
20
29
|
const ENDPOINT = BASE_URL + "/api/mcp";
|
|
21
30
|
const WALLET = process.env.TERENO_WALLET?.trim();
|
|
@@ -33,6 +42,33 @@ function errorFor(id, code, message, data) {
|
|
|
33
42
|
return { jsonrpc: "2.0", id: id ?? null, error: data === undefined ? { code, message } : { code, message, data } };
|
|
34
43
|
}
|
|
35
44
|
|
|
45
|
+
// Reads the offer out of the base64 x402 challenge. This is not reimplementing
|
|
46
|
+
// payment: it is the only way to tell the agent *where* to pay, because the
|
|
47
|
+
// payable resource is the capability's invoke URL and never this JSON-RPC
|
|
48
|
+
// endpoint. Everything is optional on purpose, so a challenge whose shape we do
|
|
49
|
+
// not recognise degrades to "the challenge carries it" instead of throwing.
|
|
50
|
+
function readOffer(challenge) {
|
|
51
|
+
if (!challenge) return null;
|
|
52
|
+
try {
|
|
53
|
+
const decoded = JSON.parse(Buffer.from(challenge, "base64").toString("utf8"));
|
|
54
|
+
const accepts = Array.isArray(decoded?.accepts) ? decoded.accepts[0] : null;
|
|
55
|
+
const url = typeof decoded?.resource?.url === "string" ? decoded.resource.url : null;
|
|
56
|
+
if (!url && !accepts) return null;
|
|
57
|
+
return {
|
|
58
|
+
url,
|
|
59
|
+
network: accepts?.network ?? null,
|
|
60
|
+
asset: accepts?.asset ?? null,
|
|
61
|
+
// Smallest unit of `asset`, not USD. Naming it loosely is how an agent
|
|
62
|
+
// ends up signing six orders of magnitude more than it meant to.
|
|
63
|
+
amountInAssetUnits: accepts?.amount ?? null,
|
|
64
|
+
payTo: accepts?.payTo ?? null,
|
|
65
|
+
maxTimeoutSeconds: accepts?.maxTimeoutSeconds ?? null,
|
|
66
|
+
};
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
36
72
|
async function forward(request) {
|
|
37
73
|
const controller = new AbortController();
|
|
38
74
|
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
@@ -56,12 +92,28 @@ async function forward(request) {
|
|
|
56
92
|
|
|
57
93
|
if (response.status === 402) {
|
|
58
94
|
const challenge = response.headers.get(PAYMENT_REQUIRED_HEADER);
|
|
95
|
+
const offer = readOffer(challenge);
|
|
96
|
+
const where = offer?.url
|
|
97
|
+
? `send the signed request to data.resource (${offer.url})`
|
|
98
|
+
: "send the signed request to the resource URL named inside that challenge";
|
|
59
99
|
return errorFor(request.id, 402,
|
|
60
|
-
"Payment required
|
|
61
|
-
+ "
|
|
62
|
-
+ "
|
|
63
|
-
+
|
|
64
|
-
|
|
100
|
+
"Payment required, and this transport cannot carry the payment. stdio has no "
|
|
101
|
+
+ "headers, so retrying this tool call with a PAYMENT-SIGNATURE is not possible "
|
|
102
|
+
+ "and no argument on this tool accepts one. Settle it over HTTP instead: sign "
|
|
103
|
+
+ `data.paymentRequired with an x402 client and ${where}. That returns the same `
|
|
104
|
+
+ "payload this tool would have returned, including the receipt, and it is billed "
|
|
105
|
+
+ "once. Free here, needing no wallet and no payment: tereno_catalog, tereno_price, "
|
|
106
|
+
+ "tereno_receipt, tereno_evidence_reference and demand_pledge. Call tereno_price "
|
|
107
|
+
+ "first if you only wanted to know the cost.",
|
|
108
|
+
{
|
|
109
|
+
paymentRequired: challenge,
|
|
110
|
+
// The payable resource, which is the capability's invoke URL. This
|
|
111
|
+
// used to carry the MCP endpoint, which is not payable and is not
|
|
112
|
+
// what an x402 client should be pointed at.
|
|
113
|
+
resource: offer?.url ?? null,
|
|
114
|
+
offer,
|
|
115
|
+
mcpEndpoint: ENDPOINT,
|
|
116
|
+
});
|
|
65
117
|
}
|
|
66
118
|
|
|
67
119
|
const text = await response.text();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tereno-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"mcpName": "xyz.tereno/tereno",
|
|
5
5
|
"description": "MCP server for Tereno on Base: check a contract, a transaction or a web page before you act on it. Free catalog, pricing and receipt tools; paid answers settle per call with x402 in USDC.",
|
|
6
6
|
"type": "module",
|