tereno-mcp 0.1.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 ADDED
@@ -0,0 +1,85 @@
1
+ # tereno-mcp
2
+
3
+ MCP server for [Tereno](https://www.tereno.xyz) on Base. Check a contract, a
4
+ transaction or a web page before you act on it, and get a verdict with the
5
+ evidence behind it, the limits of that evidence, and the block it stops being
6
+ valid at.
7
+
8
+ Three tools are free and need no wallet. The rest are paid per call with
9
+ [x402](https://x402.org) in USDC on Base, from $0.001.
10
+
11
+ ## Install
12
+
13
+ Claude Desktop, Claude Code, Cursor, Cline, Windsurf and anything else that
14
+ speaks MCP over stdio:
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "tereno": {
20
+ "command": "npx",
21
+ "args": ["-y", "tereno-mcp"]
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ Nothing else to configure. Restart the client and the free tools work.
28
+
29
+ ## Free tools
30
+
31
+ | Tool | Answers |
32
+ | --- | --- |
33
+ | `tereno_catalog` | Everything Tereno can answer, the price tiers, how long each answer stays valid, and whether it is shared or private. |
34
+ | `tereno_price` | What one specific call would cost right now, and whether the answer already exists. No wallet, no commitment. |
35
+ | `tereno_receipt` | What a settled call actually charged: tier, list price, credit applied, price paid, and whether it settled on chain. |
36
+
37
+ `tereno_price` is the one worth knowing about. Deterministic answers are shared,
38
+ so an answer another agent already paid for costs less while it is still fresh:
39
+
40
+ ```
41
+ cacheStatus: "hit" someone already computed this and it is fresh — reuse price
42
+ cacheStatus: "partial" the durable half survived — only the expired part is recomputed
43
+ cacheStatus: "miss" nothing to reuse — this call computes it, and the next asker pays less
44
+ ```
45
+
46
+ ## Paid tools
47
+
48
+ `contract_guard`, `contract_change`, `contract_interface`, `token_metadata`,
49
+ `chain_snapshot`, `evidence_artifact`, `web_compile`, `transaction_intent_guard`.
50
+
51
+ Calling one returns a `402` carrying the payment challenge in `error.data.paymentRequired`.
52
+ Sign it and retry with a `PAYMENT-SIGNATURE` header to get the answer. If your
53
+ agent already has an x402 wallet, that retry is the normal flow and nothing here
54
+ needs a private key.
55
+
56
+ `transaction_intent_guard` is never cached, shared or resold: an unsigned
57
+ transaction is intent, and it stays with the wallet that paid for it.
58
+
59
+ ## Configuration
60
+
61
+ | Variable | Default | Purpose |
62
+ | --- | --- | --- |
63
+ | `TERENO_WALLET` | none | Base address announced before payment, so a challenge can be bound to the wallet that will settle it. Optional; every free tool works without it. |
64
+ | `TERENO_BASE_URL` | `https://www.tereno.xyz` | Point at another deployment. |
65
+ | `TERENO_TIMEOUT_MS` | `45000` | Upstream request timeout. |
66
+
67
+ No private key is ever read, stored or transmitted by this package.
68
+
69
+ ## What this package is
70
+
71
+ A stdio transport in front of the hosted endpoint at
72
+ `https://www.tereno.xyz/api/mcp`. Messages are forwarded verbatim, so the tool
73
+ list, the prices and the payment challenge come from the same place an HTTP
74
+ agent sees, and this package does not need a release when a capability changes.
75
+
76
+ The one thing it translates is payment: over HTTP the challenge arrives in a
77
+ response header, and stdio has no headers, so it is folded into the JSON-RPC
78
+ error payload where a client can still reach it.
79
+
80
+ If your client supports remote MCP servers, you can skip this package and point
81
+ it at `https://www.tereno.xyz/api/mcp` directly.
82
+
83
+ ## Licence
84
+
85
+ MIT
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Tereno MCP server: a stdio transport in front of the hosted JSON-RPC endpoint.
4
+ //
5
+ // Nothing about the protocol is reimplemented here. Every message is forwarded
6
+ // verbatim to https://www.tereno.xyz/api/mcp, so the tool list, the prices and
7
+ // the payment challenge all come from the same place an HTTP agent sees, and
8
+ // this package never has to be redeployed when a capability changes.
9
+ //
10
+ // The one thing it does translate is payment. Over HTTP the 402 challenge
11
+ // arrives in a response header; stdio has no headers, so the challenge is
12
+ // folded into the JSON-RPC error payload where an MCP client can still reach it.
13
+
14
+ import { createInterface } from "node:readline";
15
+
16
+ const VERSION = "0.1.0";
17
+ const BASE_URL = (process.env.TERENO_BASE_URL || "https://www.tereno.xyz").replace(/\/+$/, "");
18
+ const ENDPOINT = BASE_URL + "/api/mcp";
19
+ const WALLET = process.env.TERENO_WALLET?.trim();
20
+ const TIMEOUT_MS = Number(process.env.TERENO_TIMEOUT_MS || 45_000);
21
+ const PAYMENT_REQUIRED_HEADER = "payment-required";
22
+
23
+ function send(message) {
24
+ process.stdout.write(JSON.stringify(message) + "\n");
25
+ }
26
+
27
+ function errorFor(id, code, message, data) {
28
+ return { jsonrpc: "2.0", id: id ?? null, error: data === undefined ? { code, message } : { code, message, data } };
29
+ }
30
+
31
+ async function forward(request) {
32
+ const controller = new AbortController();
33
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
34
+ try {
35
+ const headers = {
36
+ "content-type": "application/json",
37
+ accept: "application/json",
38
+ "user-agent": `tereno-mcp/${VERSION} (stdio)`,
39
+ };
40
+ // Identifies the caller before payment, so a challenge can be bound to the
41
+ // wallet that will settle it. Optional: everything free works without it.
42
+ if (WALLET) headers["x-agent-wallet"] = WALLET;
43
+
44
+ const response = await fetch(ENDPOINT, {
45
+ method: "POST", headers, body: JSON.stringify(request), signal: controller.signal,
46
+ });
47
+
48
+ // Notifications get 202 and no body, and expect nothing written back.
49
+ if (response.status === 202) return null;
50
+
51
+ if (response.status === 402) {
52
+ const challenge = response.headers.get(PAYMENT_REQUIRED_HEADER);
53
+ return errorFor(request.id, 402,
54
+ "Payment required. This tool is paid per call with x402 in USDC on Base. "
55
+ + "Sign the challenge in data.paymentRequired and retry with a PAYMENT-SIGNATURE header, "
56
+ + "or call tereno_price first to see what it costs. The free tools (tereno_catalog, "
57
+ + "tereno_price, tereno_receipt) need no payment and no wallet.",
58
+ { paymentRequired: challenge, resource: ENDPOINT });
59
+ }
60
+
61
+ const text = await response.text();
62
+ if (!text) return errorFor(request.id, -32603, `Tereno returned an empty body (HTTP ${response.status})`);
63
+ try {
64
+ return JSON.parse(text);
65
+ } catch {
66
+ return errorFor(request.id, -32603, `Tereno returned a non-JSON body (HTTP ${response.status})`);
67
+ }
68
+ } catch (error) {
69
+ const aborted = error?.name === "AbortError";
70
+ return errorFor(request.id, -32000,
71
+ aborted ? `Tereno did not answer within ${TIMEOUT_MS}ms` : `Tereno is unreachable: ${error?.message ?? String(error)}`);
72
+ } finally {
73
+ clearTimeout(timer);
74
+ }
75
+ }
76
+
77
+ const input = createInterface({ input: process.stdin });
78
+ // Requests are answered concurrently, so stdin closing is not the end: a piped
79
+ // client sends every line and closes immediately, and exiting there would drop
80
+ // answers that were still in flight.
81
+ const inFlight = new Set();
82
+ let stdinClosed = false;
83
+
84
+ function drain() {
85
+ if (stdinClosed && inFlight.size === 0) process.exit(0);
86
+ }
87
+
88
+ input.on("line", (line) => {
89
+ const trimmed = line.trim();
90
+ if (!trimmed) return;
91
+
92
+ let request;
93
+ try {
94
+ request = JSON.parse(trimmed);
95
+ } catch {
96
+ // No id is recoverable from an unparseable line, so this is the one case
97
+ // the spec answers with a null id.
98
+ send(errorFor(null, -32700, "Parse error: each stdio line must be one JSON-RPC 2.0 message"));
99
+ return;
100
+ }
101
+
102
+ // A notification carries no id and must not be answered, even on failure.
103
+ const isNotification = request.id === undefined || request.id === null;
104
+ const pending = forward(request)
105
+ .then((response) => { if (response && !isNotification) send(response); })
106
+ .catch((error) => { if (!isNotification) send(errorFor(request.id, -32603, String(error?.message ?? error))); })
107
+ .finally(() => { inFlight.delete(pending); drain(); });
108
+ inFlight.add(pending);
109
+ });
110
+
111
+ // Closing stdin is how an MCP client says it is done.
112
+ input.on("close", () => { stdinClosed = true; drain(); });
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "tereno-mcp",
3
+ "version": "0.1.0",
4
+ "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.",
5
+ "type": "module",
6
+ "bin": {
7
+ "tereno-mcp": "bin/tereno-mcp.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "model-context-protocol",
19
+ "modelcontextprotocol",
20
+ "x402",
21
+ "base",
22
+ "agent",
23
+ "ai-agent",
24
+ "smart-contract",
25
+ "contract-security",
26
+ "onchain",
27
+ "usdc",
28
+ "web-to-markdown"
29
+ ],
30
+ "homepage": "https://www.tereno.xyz",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/RobMartello/tereno.git",
34
+ "directory": "clients/tereno-mcp"
35
+ },
36
+ "license": "MIT",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }