@fangorn-network/westmarch 0.0.1-dev → 0.0.2-dev
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 +2 -2
- package/consume/apps.js +4 -2
- package/consume/corpora.js +1 -1
- package/consume/directory.js +1 -1
- package/consume/embed.js +1 -1
- package/consume/lint.js +1 -1
- package/consume/mcp-bin.js +6 -0
- package/consume/mcp.js +193 -34
- package/consume/ort-preload.js +25 -0
- package/consume/rank.js +1 -1
- package/consume/roles.js +6 -4
- package/consume/shard.js +1 -1
- package/consume/steam.js +1 -1
- package/consume/taste-doc.js +1 -1
- package/consume/taste.js +1 -1
- package/consume/tools.js +28 -5
- package/consume/ui.js +1 -1
- package/consume/view-tools.js +202 -0
- package/consume/x402.js +94 -0
- package/docs/app-to-agent.md +553 -185
- package/package.json +11 -4
- package/publish/agent-card.js +12 -2
- package/publish/cohort.js +1 -1
- package/publish/demand.js +1 -1
- package/publish/enrich.js +1 -1
- package/publish/envelope.js +1 -1
- package/publish/graph.js +1 -1
- package/publish/manifest.js +1 -1
- package/publish/reactions.js +4 -2
- package/publish/settle.js +1 -1
- package/publish/ship.js +378 -0
- package/publish/terms.js +1 -1
- package/publish/vault.js +1 -1
- package/publish/view-cli.js +39 -0
- package/publish/view.js +399 -0
- package/site/agent.js +36 -0
- package/site/dist/assets/__vite-browser-external-CKnVkMRn.js +1 -0
- package/site/dist/assets/embed.worker-CQqmvS52.js +1 -0
- package/site/dist/assets/index-DlzVyQ_9.js +6 -0
- package/site/dist/assets/ort-wasm-simd-threaded.asyncify-DMmc6YqF.wasm +0 -0
- package/site/dist/assets/preload-helper-uBIymjUX.js +1 -0
- package/site/dist/assets/roles-C9V_uDr_.js +1 -0
- package/site/dist/assets/roles-YDRjv_PY.js +1 -0
- package/site/dist/assets/rolldown-runtime-Dd_uD5pT.js +1 -0
- package/site/dist/assets/transformers.web-BgUm7F_-.js +46 -0
- package/site/dist/assets/transformers.web-u9uSoh5E.js +37 -0
- package/site/dist/index.html +20 -0
- package/site/feed.js +62 -0
package/docs/app-to-agent.md
CHANGED
|
@@ -1,169 +1,496 @@
|
|
|
1
|
-
# From
|
|
1
|
+
# From nothing to a running Fangorn app
|
|
2
2
|
|
|
3
|
-
This walks
|
|
3
|
+
This walks an app owner from an empty directory to a live app that people can use in a
|
|
4
|
+
browser and any agent can find, verify and query. By the end you have:
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
- **an app** claimed on Fangorn, owned by your wallet;
|
|
7
|
+
- **a schema** committed on chain: what your data's types are, which field is what, and
|
|
8
|
+
which relations are allowed between them;
|
|
9
|
+
- **your data** committed on chain under your namespace;
|
|
10
|
+
- **a view** of it: your committed data embedded and sharded as static files, so people
|
|
11
|
+
and agents can search it by meaning, updated with one command after each commit;
|
|
12
|
+
- **a static site** with no server: the view, and a page for people;
|
|
13
|
+
- **an agent card** bound to the app on chain, and registered as an ERC-8004 agent;
|
|
14
|
+
- **agents using it:** anyone running `fangorn-mcp` can `open-app` it by name.
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
at the end.
|
|
16
|
+
Where the data comes from is up to you. The guide starts from a JSON array of objects,
|
|
17
|
+
which anything can produce: a scraper, a database export, a converted spreadsheet.
|
|
13
18
|
|
|
14
19
|
```
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
your data ─► data/graph.json ─► fangorn commit/push ─┐
|
|
21
|
+
schema/graph.json ─► fangorn commit/push ────────────┤ (namespace fangorn.schema)
|
|
22
|
+
▼
|
|
23
|
+
chain ─► westmarch-view ─► site/view/
|
|
24
|
+
(embeds only what changed, applies the schema)
|
|
25
|
+
app/ (page) ─► vite build ─► site/ ◄── the page loads site/view
|
|
26
|
+
pipeline/agent-card.mjs ─► site/.well-known/agent-card.json (views: [site/view]) ─► deploy
|
|
27
|
+
│
|
|
28
|
+
fangorn app agent ─► ERC-8004 registration + AppRegistry agent_uri = card URL
|
|
29
|
+
│
|
|
30
|
+
fangorn-mcp: open-app my-app ─► reads the binding, verifies the card, searches the view
|
|
24
31
|
```
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
**Two tiers, one format.**
|
|
34
|
+
- **Free, local:** `westmarch-view` (step 7). It turns your commits into a view on your
|
|
35
|
+
own machine or CI. It embeds on CPU, ~14 records/s, only what changed since the last
|
|
36
|
+
run, and you host the files with your site.
|
|
37
|
+
- **Hosted:** quickbeam watches apps on chain, embeds on a GPU, and serves the view
|
|
38
|
+
itself. It will also do things one app's files can't, such as state across apps. It
|
|
39
|
+
writes the same files, so moving an app to it means changing the `views` URL in its
|
|
40
|
+
card.
|
|
41
|
+
|
|
42
|
+
It runs on Arbitrum Sepolia.
|
|
43
|
+
|
|
44
|
+
## The short way: one config, one command
|
|
45
|
+
|
|
46
|
+
`westmarch-ship` does every step below from one `app.json`, and re-running it is how you
|
|
47
|
+
update: each step checks the chain (or Cloudflare) first and acts only on a difference.
|
|
48
|
+
|
|
49
|
+
```jsonc
|
|
50
|
+
// app.json
|
|
51
|
+
{
|
|
52
|
+
"app": "my-app", "name": "My App", "description": "What it holds, for people and agents.",
|
|
53
|
+
"tags": ["…"],
|
|
54
|
+
"site": { "project": "my-app", "account": "<cloudflare account id>" },
|
|
55
|
+
"types": { "my.thing.v1": { "description": "…",
|
|
56
|
+
"role_map": { "identity": "id", "title": "name", "temporal": "date", "media": "url",
|
|
57
|
+
"tags": ["category"], "text": ["summary"] },
|
|
58
|
+
"presentation": { "facets": ["category"] } } },
|
|
59
|
+
"relations": [],
|
|
60
|
+
"sources": [{ "namespace": "things", "command": ["python", "-m", "my_source"] }],
|
|
61
|
+
"fangorn": "fangorn", // the CLI that signs
|
|
62
|
+
"paid": { "price": "0.01", "network": "arbitrum-sepolia", "description": "the full record" }
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npx westmarch-ship app.json # claim, join, schema, crawl + publish, view, site, card, deploy, agent
|
|
68
|
+
npx westmarch-ship app.json --dry-run # every step, printed, none done
|
|
69
|
+
npx westmarch-ship app.json --no-crawl # rebuild view, site and card from what is on chain
|
|
70
|
+
npx westmarch-ship app.json --replace # each source's crawl becomes its namespace's whole state
|
|
71
|
+
```
|
|
27
72
|
|
|
28
|
-
|
|
29
|
-
|
|
73
|
+
What it does, in order (the long way, below, is the same steps by hand):
|
|
74
|
+
|
|
75
|
+
1. **claim** the app on the first run, and record the claim block (the card's `fromBlock`);
|
|
76
|
+
2. **join** it as a publisher, if the wallet has not;
|
|
77
|
+
3. **commit the schema** (`types`, `relations`) to `fangorn.schema`, if the chain's differs;
|
|
78
|
+
4. **run each source**: a command that publishes into `--namespace` when given `--publish`.
|
|
79
|
+
Every quickbeam scraper Source does. A source with `"each": "rows.json"` is a template,
|
|
80
|
+
one source per row (`{field}`, `{field|slug}`, `{args...}`), so adding a town, a feed or
|
|
81
|
+
an account is adding a row;
|
|
82
|
+
5. **westmarch-view**: the app's commits → `.ship/site/view`, embedding only what changed.
|
|
83
|
+
A removal rewrites the domain, so a retracted record's bytes stop being served;
|
|
84
|
+
6. **the site**: the stock page (search, plus a feed of what is coming up and what just
|
|
85
|
+
happened, by the `temporal` role and the first `facets` field), the agent card and
|
|
86
|
+
`_headers`. With `paid`, also `_worker.js`, which sells each record over x402; only
|
|
87
|
+
records whose sha256 a live row carries are for sale;
|
|
88
|
+
7. **deploy** to Cloudflare Pages (`wrangler`; the project is created if missing);
|
|
89
|
+
8. **register** the ERC-8004 agent and bind the card, if the chain points elsewhere.
|
|
90
|
+
|
|
91
|
+
State lives in `.ship/` next to `app.json`. In CI, cache `.ship/cache` and `.ship/stage`
|
|
92
|
+
and commit `.ship/state.json`; Quorum's `.github/workflows/ship.yml` is a working example
|
|
93
|
+
(daily cron, and on every push to its config).
|
|
94
|
+
|
|
95
|
+
**What was run:** all of it, for Quorum (`https://quorum-bua.pages.dev`, agent `421614:245`):
|
|
96
|
+
five towns' meetings crawled, published, embedded and deployed by `westmarch-ship`, then
|
|
97
|
+
searched and bought (x402, settled on Arbitrum Sepolia) from `fangorn-mcp` in a fresh
|
|
98
|
+
session. Kingsfoil, the reference at the end, predates `ship` and was built by hand.
|
|
99
|
+
|
|
100
|
+
## The long way, by hand
|
|
101
|
+
|
|
102
|
+
What `ship` does, one step at a time: for understanding it, or for doing one step differently.
|
|
103
|
+
|
|
104
|
+
### What you need
|
|
105
|
+
|
|
106
|
+
- Node 22.
|
|
107
|
+
- The Fangorn CLI: `npm i -g @fangorn-network/sdk@2026.9.22-dev` (gives `fangorn`).
|
|
108
|
+
- A wallet on Arbitrum Sepolia with a little ETH. **It owns the app forever**, so use the
|
|
30
109
|
wallet that will publish the data.
|
|
31
|
-
- A Pinata JWT. ERC-8004
|
|
32
|
-
- A static host that serves `/.well-known/` and custom headers
|
|
33
|
-
|
|
110
|
+
- A Pinata JWT. Registering the ERC-8004 agent (step 11) pins a file to IPFS.
|
|
111
|
+
- A static host that serves `/.well-known/` and custom headers. Cloudflare Pages does
|
|
112
|
+
both, and is what the commands below use.
|
|
34
113
|
|
|
35
|
-
|
|
114
|
+
Start the project:
|
|
36
115
|
|
|
37
116
|
```sh
|
|
38
|
-
|
|
39
|
-
|
|
117
|
+
mkdir my-app && cd my-app && npm init -y && npm pkg set type=module
|
|
118
|
+
npm i @fangorn-network/westmarch @huggingface/transformers vite
|
|
119
|
+
mkdir -p data schema pipeline app
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The Fangorn SDK and viem come with westmarch as peer dependencies. transformers embeds:
|
|
123
|
+
your records in `westmarch-view`, and the reader's query in their browser.
|
|
124
|
+
|
|
125
|
+
## 1. Set up the CLI
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
fangorn init # writes ~/.fangorn/config.json: key, Pinata JWT, gateway
|
|
129
|
+
fangorn wallet # confirm which address will sign
|
|
130
|
+
fangorn set-app my-app # the app every later command uses; --app <name> overrides it once
|
|
40
131
|
```
|
|
41
132
|
|
|
42
133
|
> The config file wins over `ETH_PRIVATE_KEY` in the environment. If `fangorn wallet`
|
|
43
134
|
> shows the wrong address, that's why.
|
|
44
135
|
|
|
45
|
-
##
|
|
136
|
+
## 2. Claim the app
|
|
137
|
+
|
|
138
|
+
First, note the current block. It becomes the card's `fromBlock` (step 9), which is where
|
|
139
|
+
readers start scanning the chain for your app:
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
node -e 'const {createPublicClient,http}=require("viem");const {arbitrumSepolia}=require("viem/chains");
|
|
143
|
+
createPublicClient({chain:arbitrumSepolia,transport:http()}).getBlockNumber().then(String).then(console.log)'
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Then claim the name:
|
|
46
147
|
|
|
47
|
-
|
|
48
|
-
|
|
148
|
+
```sh
|
|
149
|
+
fangorn app info # "unclaimed", and the wallet you expect
|
|
150
|
+
fangorn app claim # first come, first served; permanent
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
With no flags, `claim` uses placeholder terms. Publish real ones later with
|
|
154
|
+
`fangorn app terms <hash> <uri>`; anyone who joined under the old terms has to accept again.
|
|
155
|
+
`--fee <wei>` sets what joining costs other publishers.
|
|
156
|
+
|
|
157
|
+
## 3. Become a publisher in it
|
|
158
|
+
|
|
159
|
+
Owning the app makes you its first publisher. You still need global standing:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
fangorn register # DataRegistry.register(), then joins this app
|
|
163
|
+
fangorn app info # DataRegistry: registered · This app: joined
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Without the join, every push reverts with `NotRegisteredForApp`.
|
|
167
|
+
|
|
168
|
+
## 4. Your data, as a graph
|
|
169
|
+
|
|
170
|
+
A commit is a graph: vertices, each with an `id`, a `tag` (its type) and a `payload` (the
|
|
171
|
+
record), and optional edges between them. Start from rows, `data/rows.json`:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
[
|
|
175
|
+
{ "id": "oak", "name": "Oak", "species": "Quercus robur", "family": "Fagaceae", "region": "Europe",
|
|
176
|
+
"description": "Long-lived deciduous tree with lobed leaves and acorns; hard durable timber …" },
|
|
177
|
+
{ "id": "baobab", "name": "Baobab", "species": "Adansonia digitata", "family": "Malvaceae", "region": "Africa",
|
|
178
|
+
"description": "Massive trunk stores water through the dry season; fruit pulp is rich in vitamin C." }
|
|
179
|
+
]
|
|
180
|
+
```
|
|
49
181
|
|
|
50
182
|
```js
|
|
51
|
-
//
|
|
52
|
-
import {
|
|
183
|
+
// pipeline/graph.mjs — data/rows.json → data/graph.json
|
|
184
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
185
|
+
const rows = JSON.parse(readFileSync("data/rows.json", "utf8"));
|
|
186
|
+
writeFileSync("data/graph.json", JSON.stringify({
|
|
187
|
+
vertices: rows.map((r) => ({ id: r.id, tag: "my-app.tree.v1", payload: r })),
|
|
188
|
+
// edges: [{ rel: "grows_in", from: "oak", to: "europe" }] // between vertex ids, if you have them
|
|
189
|
+
}));
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
What makes records work well:
|
|
193
|
+
|
|
194
|
+
- **A stable id.** The same thing keeps the same id across commits.
|
|
195
|
+
- **Text that says what the record is, in words.** This is what gets embedded, so it's
|
|
196
|
+
what "search by meaning" matches. A title alone is weak; a sentence or a paragraph is good.
|
|
197
|
+
- **Fields worth filtering or counting on**, such as a category, a region, or a date. Agents
|
|
198
|
+
use these with `where` and `count`.
|
|
199
|
+
- **One tag per kind of thing.** Version it (`.v1`) so a later shape can be a new type.
|
|
200
|
+
|
|
201
|
+
## 5. Declare the schema
|
|
202
|
+
|
|
203
|
+
The schema says what your data is. You commit it to a reserved namespace,
|
|
204
|
+
`fangorn.schema`, in your app:
|
|
205
|
+
- **Types:** each is a vertex tagged `fangorn.type.v1`.
|
|
206
|
+
- **Relations:** the relations allowed between types are edges between those vertices.
|
|
207
|
+
|
|
208
|
+
`westmarch-view` (and hosted quickbeam) read it for every record they embed, so it decides:
|
|
209
|
+
- **what gets embedded:** the `text` role, plus title, subtitle and tags;
|
|
210
|
+
- **what readers see:** titles, links, labels;
|
|
211
|
+
- **what agents can do:** filters, counts, and choosing among views by their description.
|
|
212
|
+
|
|
213
|
+
`schema/graph.json`:
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"vertices": [
|
|
218
|
+
{ "id": "tree", "tag": "fangorn.type.v1", "payload": {
|
|
219
|
+
"tag": "my-app.tree.v1",
|
|
220
|
+
"description": "Tree species: what they are, where they grow, and what they are good for.",
|
|
221
|
+
"role_map": { "identity": "id", "title": "name", "subtitle": "species",
|
|
222
|
+
"tags": ["family", "region"], "text": ["description"] },
|
|
223
|
+
"presentation": { "externalUrl": { "my-app.tree.v1": "https://en.wikipedia.org/wiki/{species}" } } } }
|
|
224
|
+
],
|
|
225
|
+
"edges": []
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
```sh
|
|
230
|
+
cd schema && fangorn repo init fangorn.schema \
|
|
231
|
+
&& fangorn commit graph.json -m "schema v1" --replace && fangorn push && cd ..
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`fangorn repo init` tracks one namespace per directory (in `.fangorn/`), which is why the
|
|
235
|
+
schema is committed from its own `schema/` folder.
|
|
236
|
+
|
|
237
|
+
**`role_map`** says which field is what:
|
|
238
|
+
|
|
239
|
+
| role | means | used for |
|
|
240
|
+
|---|---|---|
|
|
241
|
+
| `identity` | the id field | `get`, links, updates |
|
|
242
|
+
| `text` | the field(s) whose words get embedded | search by meaning |
|
|
243
|
+
| `title`, `subtitle` | what a record is called | result lists, and embedded too |
|
|
244
|
+
| `tags` | categories | filters, `count`, and embedded too |
|
|
245
|
+
| `temporal`, `spatial`, `measures`, `relations`, `media` | dates, places, numbers, links to other records, playable media | sorting, facets, previews |
|
|
246
|
+
|
|
247
|
+
**Rules:**
|
|
248
|
+
- **Declared means declared.** A role you leave out stays empty; it isn't guessed.
|
|
249
|
+
- **Undeclared types are still guessed:** a type the schema doesn't mention gets a role
|
|
250
|
+
map inferred from its fields. That works for display and often fails for search: a
|
|
251
|
+
field called `desc` or `nct` isn't recognized, and a `price` can end up as the date.
|
|
252
|
+
Declare every type you publish.
|
|
253
|
+
- **Only the app owner's schema counts.** Any publisher can write a namespace called
|
|
254
|
+
`fangorn.schema`; only the owner's is read.
|
|
255
|
+
- **You can change it at any time** with another commit. A view takes the new role map and
|
|
256
|
+
description on its next `westmarch-view` run. **Records already embedded keep the text they were embedded
|
|
257
|
+
with** until they're re-embedded, so change the `text` role early.
|
|
258
|
+
- **Relations** (edges between type vertices, e.g. `{ "rel": "grows_in", "from": "tree",
|
|
259
|
+
"to": "region" }`) declare which edges the app allows. Nothing enforces them yet; they
|
|
260
|
+
are what publisher graphs will be validated against.
|
|
261
|
+
|
|
262
|
+
## 6. Commit and push the data
|
|
263
|
+
|
|
264
|
+
```sh
|
|
265
|
+
node pipeline/graph.mjs
|
|
266
|
+
fangorn repo init my-app # the data namespace, tracked in ./.fangorn
|
|
267
|
+
fangorn commit data/graph.json -m "first data" --replace # local; builds and uploads the commit
|
|
268
|
+
fangorn push # the on-chain transaction
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
`--replace` makes the file the namespace's whole state, so records you removed are
|
|
272
|
+
removed. Without it, the commit adds to what's already there. `fangorn status` compares
|
|
273
|
+
your local tip with the one on chain.
|
|
274
|
+
|
|
275
|
+
## 7. Publish the view
|
|
276
|
+
|
|
277
|
+
```sh
|
|
278
|
+
npx westmarch-view --app my-app --namespace my-app --out site/view --from-block 311700000
|
|
279
|
+
# my-app: 1 publisher(s) since block 311700000
|
|
280
|
+
# …-my-app: +20 embedded, -0 removed, 20 live
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
It reads the chain and writes files; it needs no key. For every publisher of each
|
|
284
|
+
`--namespace` in the app, it:
|
|
285
|
+
- reads their records;
|
|
286
|
+
- embeds the ones the view doesn't hold yet, with your schema's roles;
|
|
287
|
+
- marks the ones that were removed as deleted;
|
|
288
|
+
- writes a new shard;
|
|
289
|
+
- refits the coverage sketch once the view has doubled.
|
|
290
|
+
|
|
291
|
+
The view's own files are its state, so a second run with nothing new on chain changes
|
|
292
|
+
nothing, and it runs the same on a laptop, in CI, or from an agent. The first run
|
|
293
|
+
downloads the embedding model (131 MB, kept in `~/.cache/fangorn-mcp/models`, shared with
|
|
294
|
+
`fangorn-mcp`). Use `--from-block` with the block you noted in step 2.
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
site/view/cdn/catalog every publisher's domain, with descriptions and coverage
|
|
298
|
+
site/view/cdn/domains/<app>-<publisher>-<ns>/manifest role map, embedder, shards with their sha256, tombstones
|
|
299
|
+
site/view/cdn/domains/<app>-<publisher>-<ns>/shards/shard-NNNN-<sha>.ndjson.gz
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Check it the way a reader will:
|
|
303
|
+
|
|
304
|
+
```sh
|
|
305
|
+
(cd site && python3 -m http.server 8765 &)
|
|
306
|
+
node node_modules/@fangorn-network/westmarch/consume/lint.js http://127.0.0.1:8765/view
|
|
307
|
+
# …-my-app — 20 rows — nothing to fix
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`lint.js` reports three levels:
|
|
311
|
+
- **blocking:** readers can't find you (no coverage, wrong model);
|
|
312
|
+
- **findable, but not readable** (no text role);
|
|
313
|
+
- **readable, but a dead end** (nowhere for a hit to link to).
|
|
314
|
+
|
|
315
|
+
The fix for most findings is in the schema (step 5).
|
|
316
|
+
|
|
317
|
+
A view remembers which embedder made it, and `westmarch-view` refuses to add to a view
|
|
318
|
+
another one built. Vectors from two encoders don't compare. Pass `--rebake` to start
|
|
319
|
+
a view over.
|
|
320
|
+
|
|
321
|
+
## 8. The page
|
|
322
|
+
|
|
323
|
+
A page for people, with the same search exposed to agents in the browser as WebMCP tools.
|
|
324
|
+
It reads the view: shards are checked against their manifests' sha256, the query is
|
|
325
|
+
embedded in the reader's tab, and nothing about the query leaves it.
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
// app/agent.js — the page's tools for agents in a browser. `ctx` holds the loaded rows.
|
|
329
|
+
import { search, getRow } from "@fangorn-network/westmarch/tools";
|
|
53
330
|
|
|
54
331
|
const ok = (o) => ({ content: [{ type: "text", text: JSON.stringify(o) }] });
|
|
55
332
|
|
|
56
333
|
export function registerAgent(ctx) {
|
|
57
334
|
const mc = document.modelContext;
|
|
58
|
-
if (!mc?.registerTool) return
|
|
335
|
+
if (!mc?.registerTool) return; // most browsers have no WebMCP yet
|
|
336
|
+
mc.registerTool({
|
|
337
|
+
name: "search-trees",
|
|
338
|
+
description: "Search tree species by meaning: a question in plain words. Call this first.",
|
|
339
|
+
inputSchema: { type: "object", properties: { query: { type: "string" }, limit: { type: "number" } }, required: ["query"] },
|
|
340
|
+
execute: async ({ query, limit = 10 }) =>
|
|
341
|
+
ok(search(ctx.rows, query, ctx.roles, { qv: await ctx.queryVector(query), limit })),
|
|
342
|
+
});
|
|
59
343
|
mc.registerTool({
|
|
60
|
-
name: "
|
|
61
|
-
description: "
|
|
62
|
-
inputSchema: { type: "object", properties: {
|
|
63
|
-
execute: async ({
|
|
344
|
+
name: "get-tree",
|
|
345
|
+
description: "One tree species in full, by the id search returns.",
|
|
346
|
+
inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
|
|
347
|
+
execute: async ({ id }) => ok(getRow(ctx.rows, id, ctx.roles) ?? { error: `no tree ${id}` }),
|
|
64
348
|
});
|
|
65
|
-
// …more tools
|
|
66
349
|
}
|
|
67
350
|
```
|
|
68
351
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
352
|
+
```js
|
|
353
|
+
// app/main.js
|
|
354
|
+
import { configure, loadShard } from "@fangorn-network/westmarch/shard";
|
|
355
|
+
import { rolesFrom, textOf } from "@fangorn-network/westmarch/roles";
|
|
356
|
+
import { search } from "@fangorn-network/westmarch/tools";
|
|
357
|
+
import { embedQuery } from "@fangorn-network/westmarch/embed";
|
|
358
|
+
import { registerAgent } from "./agent.js";
|
|
359
|
+
|
|
360
|
+
export const VIEW = new URL("view", location.href).href; // step 7
|
|
361
|
+
|
|
362
|
+
const ctx = { rows: [], roles: rolesFrom([]), queryVector: (q) => embedQuery(q).catch(() => null) };
|
|
363
|
+
configure({ onManifests: (ms) => { ctx.roles = rolesFrom(ms); }, rowText: (f) => textOf(f, ctx.roles) });
|
|
364
|
+
ctx.rows = await loadShard(VIEW); // checked against the manifests' sha256
|
|
365
|
+
registerAgent(ctx); // only now: a tool called before its data loads answers wrong, silently
|
|
366
|
+
|
|
367
|
+
// The human side: the same search, as a list.
|
|
368
|
+
const input = document.querySelector("input"), list = document.querySelector("ul");
|
|
369
|
+
input.placeholder = `Search ${ctx.rows.length} trees…`;
|
|
370
|
+
input.oninput = async () => {
|
|
371
|
+
const q = input.value;
|
|
372
|
+
const hits = search(ctx.rows, q, ctx.roles, { qv: await ctx.queryVector(q), limit: 10 });
|
|
373
|
+
if (q !== input.value) return; // a newer keystroke won
|
|
374
|
+
list.replaceChildren(...hits.map((h) => {
|
|
375
|
+
const li = document.createElement("li"), a = document.createElement("a");
|
|
376
|
+
a.textContent = h.title; if (h.url) a.href = h.url;
|
|
377
|
+
li.append(a, ` — ${h.subtitle ?? ""}`);
|
|
378
|
+
return li;
|
|
379
|
+
}));
|
|
380
|
+
};
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
```html
|
|
384
|
+
<!-- app/index.html -->
|
|
385
|
+
<!doctype html>
|
|
386
|
+
<meta charset="utf-8">
|
|
387
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
388
|
+
<title>My App</title>
|
|
389
|
+
<h1>My App</h1>
|
|
390
|
+
<input type="search" autofocus placeholder="Loading…">
|
|
391
|
+
<ul></ul>
|
|
392
|
+
<script type="module" src="./main.js"></script>
|
|
393
|
+
```
|
|
73
394
|
|
|
74
395
|
```js
|
|
75
|
-
|
|
76
|
-
|
|
396
|
+
// app/vite.config.js
|
|
397
|
+
export default {
|
|
398
|
+
base: "./",
|
|
399
|
+
// westmarch's embedder finds its worker by `new URL(…, import.meta.url)`;
|
|
400
|
+
// pre-bundling loses that and search silently drops to word matching.
|
|
401
|
+
optimizeDeps: { exclude: ["@fangorn-network/westmarch"] },
|
|
402
|
+
build: { outDir: "../site", emptyOutDir: false }, // keep site/view
|
|
403
|
+
};
|
|
77
404
|
```
|
|
78
405
|
|
|
79
|
-
|
|
80
|
-
|
|
406
|
+
```sh
|
|
407
|
+
(cd app && npx vite build)
|
|
408
|
+
```
|
|
81
409
|
|
|
82
|
-
|
|
410
|
+
`@fangorn-network/westmarch/tools` also has `describe`, `browse`, `facet` and `neighbors`,
|
|
411
|
+
if the page needs more than search. `watchShard(fn)` tells the page when the view gains
|
|
412
|
+
shards, if it should update without a reload.
|
|
413
|
+
|
|
414
|
+
## 9. The agent card
|
|
83
415
|
|
|
84
416
|
A WebMCP tool only exists inside a loaded tab, so the card is the only machine-readable
|
|
85
|
-
record that the tools exist.
|
|
86
|
-
register function against a recording stub, so the card lists
|
|
87
|
-
registers. No `execute` runs
|
|
417
|
+
record that the app, its tools and its view exist. The tool list isn't written by hand:
|
|
418
|
+
`captureTools` runs your register function against a recording stub, so the card lists
|
|
419
|
+
exactly what the page registers. No `execute` runs.
|
|
88
420
|
|
|
89
421
|
```js
|
|
90
|
-
// pipeline/agent-card.mjs —
|
|
91
|
-
import {
|
|
92
|
-
import { agentCard, captureTools } from "@fangorn/westmarch/agent-card";
|
|
422
|
+
// pipeline/agent-card.mjs — site/ → site/.well-known/agent-card.json + site/_headers
|
|
423
|
+
import { mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
424
|
+
import { agentCard, captureTools } from "@fangorn-network/westmarch/agent-card";
|
|
93
425
|
import { registerAgent } from "../app/agent.js";
|
|
94
426
|
|
|
95
|
-
const
|
|
427
|
+
const SITE = "https://my-app.pages.dev";
|
|
428
|
+
const VIEW = `${SITE}/view`; // step 7; a hosted quickbeam view's URL goes here instead
|
|
429
|
+
|
|
96
430
|
const card = agentCard({
|
|
97
431
|
name: "My App",
|
|
98
|
-
description: "
|
|
99
|
-
url:
|
|
100
|
-
version: "
|
|
101
|
-
tools,
|
|
102
|
-
tags: ["
|
|
432
|
+
description: "Tree species: what they are, where they grow, and what they are good for. Search by meaning.",
|
|
433
|
+
url: `${SITE}/`, // the page that registers the tools
|
|
434
|
+
version: "1",
|
|
435
|
+
tools: await captureTools(() => registerAgent({})),
|
|
436
|
+
tags: ["trees"],
|
|
103
437
|
fangorn: {
|
|
104
|
-
app: "my-app",
|
|
105
|
-
fromBlock:
|
|
106
|
-
namespaces: ["my-app"],
|
|
107
|
-
views: [
|
|
438
|
+
app: "my-app", // the name you claimed
|
|
439
|
+
fromBlock: 311700000, // the block you noted before claiming
|
|
440
|
+
namespaces: ["my-app"], // your data namespace(s)
|
|
441
|
+
views: [VIEW],
|
|
108
442
|
},
|
|
109
443
|
});
|
|
110
|
-
|
|
111
444
|
mkdirSync("site/.well-known", { recursive: true });
|
|
112
445
|
writeFileSync("site/.well-known/agent-card.json", JSON.stringify(card, null, 1));
|
|
113
|
-
// Discovery runs in other sites' tabs: without CORS the browser won't hand over the card.
|
|
114
|
-
writeFileSync("site/_headers", "/.well-known/agent-card.json\n Access-Control-Allow-Origin: *\n");
|
|
115
|
-
```
|
|
116
446
|
|
|
117
|
-
The
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
node -e 'const {createPublicClient,http}=require("viem");const {arbitrumSepolia}=require("viem/chains");
|
|
127
|
-
createPublicClient({chain:arbitrumSepolia,transport:http()}).getBlockNumber().then(String).then(console.log)'
|
|
447
|
+
// The card is read from other origins, so it needs CORS, and so does the view, for
|
|
448
|
+
// agents and pages elsewhere. Bundles and shards are named by their digest, so they
|
|
449
|
+
// never change: tell caches so. (Pages allows one * per rule, hence a rule per domain.)
|
|
450
|
+
const immutable = " Cache-Control: public, max-age=31536000, immutable\n";
|
|
451
|
+
writeFileSync("site/_headers",
|
|
452
|
+
"/.well-known/agent-card.json\n Access-Control-Allow-Origin: *\n"
|
|
453
|
+
+ "/view/*\n Access-Control-Allow-Origin: *\n"
|
|
454
|
+
+ `/assets/*\n${immutable}`
|
|
455
|
+
+ readdirSync("site/view/cdn/domains").map((d) => `/view/cdn/domains/${d}/shards/*\n${immutable}`).join(""));
|
|
128
456
|
```
|
|
129
457
|
|
|
130
|
-
Too early is only slow: readers query logs 1000 blocks per call. Leave it at 0 and a reader
|
|
131
|
-
makes hundreds of thousands of calls.
|
|
132
|
-
|
|
133
|
-
**Hard-code these values once the app is claimed.** A rebuild that drops the extension
|
|
134
|
-
publishes a card that every reader rejects.
|
|
135
|
-
|
|
136
|
-
## 3. Deploy and check the card
|
|
137
|
-
|
|
138
458
|
```sh
|
|
139
|
-
|
|
140
|
-
curl -sD - https://my-app.pages.dev/.well-known/agent-card.json -o /dev/null | grep -iE "^HTTP|content-type|access-control"
|
|
141
|
-
# HTTP/2 200 · content-type: application/json · access-control-allow-origin: *
|
|
459
|
+
node pipeline/agent-card.mjs
|
|
142
460
|
```
|
|
143
461
|
|
|
144
|
-
The
|
|
462
|
+
- **The `fangorn` block** becomes an A2A extension (`https://fangorn.network/a2a/app/v1`).
|
|
463
|
+
It holds the chain, the registry addresses (taken from the SDK, so they can't drift), your
|
|
464
|
+
appId, `fromBlock`, `namespaces` and `views`. `agentCard` validates them the same way
|
|
465
|
+
readers will, so a bad card fails your build, not someone else's discovery.
|
|
466
|
+
- **`views` is what agents search:** `fangorn-mcp` reads it directly, with no browser.
|
|
467
|
+
- **`url` is the page that registers the tools,** not just any page on the site.
|
|
468
|
+
- **`fromBlock`** only affects speed: readers query logs 1000 blocks per call, so an early
|
|
469
|
+
block is slow, and 0 means hundreds of thousands of calls.
|
|
470
|
+
- **Keep these values fixed.** A rebuild that drops the extension or changes `url`
|
|
471
|
+
publishes a card every reader rejects.
|
|
145
472
|
|
|
146
|
-
##
|
|
473
|
+
## 10. Deploy and check
|
|
147
474
|
|
|
148
475
|
```sh
|
|
149
|
-
|
|
150
|
-
|
|
476
|
+
npx wrangler pages deploy site --project-name my-app
|
|
477
|
+
curl -sD - https://my-app.pages.dev/.well-known/agent-card.json -o /dev/null | grep -iE "^HTTP|access-control"
|
|
478
|
+
# HTTP/2 200 · access-control-allow-origin: *
|
|
151
479
|
```
|
|
152
480
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
`--fee <wei>` sets a join fee.
|
|
481
|
+
Open `https://my-app.pages.dev/` and search: that's the app for people. The card must be
|
|
482
|
+
live before step 11, because the CLI fetches it.
|
|
156
483
|
|
|
157
|
-
##
|
|
484
|
+
## 11. Register the agent and bind the card
|
|
158
485
|
|
|
159
486
|
```sh
|
|
160
|
-
fangorn
|
|
161
|
-
# Agent ID: 421614
|
|
487
|
+
fangorn app agent https://my-app.pages.dev/.well-known/agent-card.json
|
|
488
|
+
# Agent ID: 421614:…
|
|
162
489
|
# Card: https://my-app.pages.dev/.well-known/agent-card.json
|
|
163
490
|
# Tx: 0x…
|
|
164
491
|
```
|
|
165
492
|
|
|
166
|
-
This
|
|
493
|
+
This does two things:
|
|
167
494
|
|
|
168
495
|
1. **ERC-8004.** It builds a registration file from the card (name, description, A2A
|
|
169
496
|
endpoint = the card URL, trust = reputation, x402 only if a skill is tagged `x402`),
|
|
@@ -171,34 +498,122 @@ This command does two things:
|
|
|
171
498
|
`0x8004A818BFB912233c491871b3d84c89A494BD9e`. That's the same address as on Ethereum
|
|
172
499
|
and Base Sepolia. [8004scan](https://8004scan.io) indexes it within minutes.
|
|
173
500
|
2. **Fangorn.** It calls `setAppAgentUri(cardUrl)`, which emits `AppAgentChanged`. That log
|
|
174
|
-
is the app directory:
|
|
501
|
+
is the app directory: `list-apps` and `listApps` read it.
|
|
502
|
+
|
|
503
|
+
`--skip-register` does only the second step, e.g. to move an already-registered card to a
|
|
504
|
+
new URL.
|
|
175
505
|
|
|
176
|
-
|
|
177
|
-
|
|
506
|
+
## 12. Use it as an agent would
|
|
507
|
+
|
|
508
|
+
Register `fangorn-mcp` once (see [Using Fangorn apps from an agent](#using-fangorn-apps-from-an-agent)),
|
|
509
|
+
then in any agent:
|
|
510
|
+
|
|
511
|
+
```
|
|
512
|
+
open-app my-app → verified: true, data_tools: true
|
|
513
|
+
my-app__describe → the view's domains, with the schema's description
|
|
514
|
+
my-app__search "trees that survive fire" → cork oak, oak, redwood (ranked by meaning)
|
|
515
|
+
my-app__get "baobab" → the whole record
|
|
516
|
+
```
|
|
178
517
|
|
|
179
|
-
|
|
518
|
+
`open-app` reads your app's binding from the registry, fetches the card, and checks that
|
|
519
|
+
the binding points back at exactly that URL. Only then does it add the tools.
|
|
180
520
|
|
|
181
|
-
|
|
521
|
+
## 13. Update it
|
|
522
|
+
|
|
523
|
+
New or changed data is a commit, then the view, then a deploy:
|
|
182
524
|
|
|
183
525
|
```sh
|
|
184
|
-
fangorn
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
fangorn --app my-app push
|
|
526
|
+
node pipeline/graph.mjs && fangorn commit data/graph.json -m "…" --replace && fangorn push
|
|
527
|
+
npx westmarch-view --app my-app --namespace my-app --out site/view --from-block 311700000
|
|
528
|
+
node pipeline/agent-card.mjs && npx wrangler pages deploy site --project-name my-app
|
|
188
529
|
```
|
|
189
530
|
|
|
190
|
-
|
|
191
|
-
|
|
531
|
+
Only what changed is embedded and uploaded. The page and agents see it on their next
|
|
532
|
+
load, since the view URL, the card and the on-chain binding all stay the same. Run
|
|
533
|
+
`fangorn app agent` again only if the card moves. Anything that can run those three lines
|
|
534
|
+
can keep an app current: a cron job, a CI workflow, or an agent that just published.
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
## Using Fangorn apps from an agent
|
|
539
|
+
|
|
540
|
+
`fangorn-mcp` is one MCP server for every Fangorn app: a new app needs no new
|
|
541
|
+
registration. You can install it as a single file (Linux x64/arm64): no node, no install,
|
|
542
|
+
and search by meaning included.
|
|
192
543
|
|
|
193
|
-
|
|
544
|
+
```sh
|
|
545
|
+
curl -fLo fangorn-mcp https://github.com/fangorn-network/westmarch/releases/latest/download/fangorn-mcp-linux-x64
|
|
546
|
+
chmod +x fangorn-mcp
|
|
547
|
+
claude mcp add fangorn -- "$PWD/fangorn-mcp"
|
|
548
|
+
```
|
|
194
549
|
|
|
195
|
-
|
|
550
|
+
Or through npm, wherever node is:
|
|
551
|
+
|
|
552
|
+
```sh
|
|
553
|
+
claude mcp add fangorn -- npx -y -p @fangorn-network/westmarch -p @huggingface/transformers fangorn-mcp
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
Without `-p @huggingface/transformers`, the install is ~500 MB lighter and `search` ranks by
|
|
557
|
+
words, not meaning. For any MCP client:
|
|
558
|
+
|
|
559
|
+
```json
|
|
560
|
+
{ "mcpServers": { "fangorn": { "command": "/path/to/fangorn-mcp" } } }
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
`bun build-bin.js` in westmarch builds the file (bun ≥ 1.2).
|
|
564
|
+
|
|
565
|
+
It starts with three tools:
|
|
566
|
+
- **`list-apps`** reads the apps off the chain and keeps the ones whose cards verify.
|
|
567
|
+
- **`open-app <name>`** reads that app's binding from the registry (one call), verifies its
|
|
568
|
+
card, and adds the app's tools as `<name>__<tool>`.
|
|
569
|
+
- **`call-app-tool`** reaches the same tools, for clients that don't refresh their tool list.
|
|
570
|
+
|
|
571
|
+
**Two kinds of tools.**
|
|
572
|
+
- **Data tools:** an app whose card names `views` gets these at once, with no browser:
|
|
573
|
+
`describe`, `search`, `get`, `similar`, `count`, `browse`. westmarch runs them over the
|
|
574
|
+
app's shards, checked against their manifests' sha256. `search` reads the 3 views whose
|
|
575
|
+
coverage sketch best matches the query and names the next candidates.
|
|
576
|
+
- **Page tools:** `open-app` with `page: true` also opens `card.url` in a browser for the
|
|
577
|
+
page's own WebMCP tools. An app with no views gets only these.
|
|
578
|
+
|
|
579
|
+
**How fast** (Kingsfoil: 23 views, 60,760 trials):
|
|
580
|
+
|
|
581
|
+
| | time |
|
|
582
|
+
|---|---|
|
|
583
|
+
| `open-app` | 0.4–2 s |
|
|
584
|
+
| `describe` | under 5 ms |
|
|
585
|
+
| first `search`, caches warm | 0.4–1.8 s |
|
|
586
|
+
| later searches | ~0.2–0.5 s |
|
|
587
|
+
| first `search` from an empty machine (single file) | ~3.5 s, by words while the model downloads |
|
|
588
|
+
| page tools (browser) | 5–15 s to open, ~2 GB of memory |
|
|
589
|
+
|
|
590
|
+
On a new machine, the embedding model (131 MB, kept in `~/.cache/fangorn-mcp/models`)
|
|
591
|
+
downloads in the background. Until it lands, `search` ranks by words and says so in
|
|
592
|
+
`ranked_by`; then it switches to meaning. Shards are downloaded once and kept by content
|
|
593
|
+
hash.
|
|
594
|
+
|
|
595
|
+
**Where the browser comes from (page tools only).** Anything that speaks the Chrome DevTools
|
|
596
|
+
Protocol and has WebMCP will do: a headless Chromium service, a hosted browser, or the local
|
|
597
|
+
Chrome.
|
|
598
|
+
|
|
599
|
+
| setting | browser |
|
|
600
|
+
|---|---|
|
|
601
|
+
| `FANGORN_MCP_CDP=http://host:9222` (or `--cdp`) | a running browser's DevTools address |
|
|
602
|
+
| `FANGORN_MCP_CDP=ws://host:9222/devtools/browser/…` | a browser WebSocket endpoint, which is what hosted services hand out |
|
|
603
|
+
| neither | the local Chrome 150+ (`CHROME=/path` if it isn't `google-chrome`), headless (`--headed` to watch) |
|
|
604
|
+
|
|
605
|
+
A remote browser is never closed; only the tabs the server opened are. A local Chrome is
|
|
606
|
+
shared by every session on the machine and closes when the last one exits. Its profile is
|
|
607
|
+
`~/.cache/westmarch-mcp/`. `--from-block <n>` points the server at another deployment.
|
|
608
|
+
|
|
609
|
+
## Discovering apps in code
|
|
610
|
+
|
|
611
|
+
Every route ends in `discoverApp(cardUrl)`, which accepts a card only if:
|
|
196
612
|
|
|
197
613
|
- the card carries the Fangorn extension for **this** chain and **this** AppRegistry, and
|
|
198
614
|
- `appAgentUri(card.appId)` on chain is **exactly** the card URL.
|
|
199
615
|
|
|
200
616
|
The registry and the index are where you look. The on-chain binding is what you trust.
|
|
201
|
-
|
|
202
617
|
`example/discover.mjs` runs all three routes:
|
|
203
618
|
|
|
204
619
|
```sh
|
|
@@ -207,13 +622,7 @@ node example/discover.mjs chain 311637349 # every app bound since this
|
|
|
207
622
|
node example/discover.mjs search Kingsfoil # the public ERC-8004 index
|
|
208
623
|
```
|
|
209
624
|
|
|
210
|
-
|
|
211
|
-
Kingsfoil https://kingsfoil.pages.dev/.well-known/agent-card.json
|
|
212
|
-
app 0x3069…c8ca data from block 311671082 namespaces kingsfoil
|
|
213
|
-
open https://kingsfoil.pages.dev — WebMCP tools: list-areas, search-trials, get-trial, …
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**From a card URL** (someone handed it to you):
|
|
625
|
+
**From a card URL:**
|
|
217
626
|
|
|
218
627
|
```js
|
|
219
628
|
import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
|
|
@@ -226,17 +635,13 @@ const { card, appId, fromBlock, namespaces } = await fangorn.discoverApp(cardUrl
|
|
|
226
635
|
**From the chain** (every Fangorn app; no index, no server):
|
|
227
636
|
|
|
228
637
|
```js
|
|
229
|
-
import { listApps } from "@fangorn/westmarch/apps";
|
|
638
|
+
import { listApps } from "@fangorn-network/westmarch/apps";
|
|
230
639
|
const { apps, rejected } = await listApps(fangorn, { fromBlock: 311637349n });
|
|
231
640
|
// apps: [{ name, appId, card, url, views, namespaces, fromBlock }]
|
|
232
641
|
// rejected: [{ card, why }]: unreachable or not bound, reported rather than dropped
|
|
233
642
|
```
|
|
234
643
|
|
|
235
|
-
|
|
236
|
-
so an agent can rank every app's corpora against a question without downloading a shard.
|
|
237
|
-
In the example page, `?fromBlock=311637349` does the same thing in a browser.
|
|
238
|
-
|
|
239
|
-
**From ERC-8004** (general-purpose agents that know nothing about Fangorn):
|
|
644
|
+
**From ERC-8004** (for general-purpose agents that know nothing about Fangorn):
|
|
240
645
|
|
|
241
646
|
```js
|
|
242
647
|
const api = "https://8004scan.io/api/v1/agents";
|
|
@@ -245,57 +650,7 @@ const detail = await (await fetch(`${api}/421614/${items[0].token_id}`)).json();
|
|
|
245
650
|
const found = await fangorn.discoverApp(detail.services.a2a.endpoint);
|
|
246
651
|
```
|
|
247
652
|
|
|
248
|
-
|
|
249
|
-
registration file's `ipfs://` URI, and its `A2A` endpoint is the card.
|
|
250
|
-
|
|
251
|
-
### Use it
|
|
252
|
-
|
|
253
|
-
- **An agent:** open `card.url` in Chrome 150+ with `--enable-features=WebMCP` (headless
|
|
254
|
-
works) and call the tools the card lists as `webmcp` skills. Queries run in that tab, and
|
|
255
|
-
nothing reaches a server. WebMCP is not a network MCP server: the tools exist only inside
|
|
256
|
-
a loaded tab, so an agent outside the browser (Claude Code, a script) needs something
|
|
257
|
-
that drives the tab for it. `card.url` must be the page that registers the tools, not
|
|
258
|
-
just the site's root. `fangorn-mcp` is that driver, for every app at once. Register it
|
|
259
|
-
once:
|
|
260
|
-
|
|
261
|
-
```sh
|
|
262
|
-
claude mcp add fangorn -- npx -y -p @fangorn/westmarch fangorn-mcp
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
or, for any MCP client:
|
|
266
|
-
|
|
267
|
-
```json
|
|
268
|
-
{ "mcpServers": { "fangorn": {
|
|
269
|
-
"command": "npx", "args": ["-y", "-p", "@fangorn/westmarch", "fangorn-mcp"],
|
|
270
|
-
"env": { "FANGORN_MCP_CDP": "ws://your-browser:9222" } } } }
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
Drop `env` to use the local Chrome.
|
|
274
|
-
|
|
275
|
-
It starts with three tools. `list-apps` reads the apps off the chain and keeps the ones
|
|
276
|
-
whose cards verify. `open-app kingsfoil` verifies that app's card, opens `card.url` in a
|
|
277
|
-
tab of one shared Chrome with WebMCP on, and adds the page's tools as
|
|
278
|
-
`kingsfoil__search-trials` and so on. `call-app-tool` reaches the same tools for clients
|
|
279
|
-
that don't refresh their tool list. A new app needs no new registration: it shows up in
|
|
280
|
-
`list-apps` once its card is bound on chain.
|
|
281
|
-
|
|
282
|
-
**Where the browser comes from.** Anything that speaks the Chrome DevTools Protocol and
|
|
283
|
-
has WebMCP will do: a headless Chromium service, a hosted browser, or the local Chrome.
|
|
284
|
-
|
|
285
|
-
| setting | browser |
|
|
286
|
-
|---|---|
|
|
287
|
-
| `FANGORN_MCP_CDP=http://host:9222` (or `--cdp`) | a running browser's DevTools address |
|
|
288
|
-
| `FANGORN_MCP_CDP=ws://host:9222/devtools/browser/…` | a browser WebSocket endpoint, which is what hosted services hand out |
|
|
289
|
-
| neither | the local Chrome 150+ (`CHROME=/path` if it isn't `google-chrome`), headless (`--headed` to watch) |
|
|
290
|
-
|
|
291
|
-
A remote browser is never closed. Only the tabs the server opened are. A local Chrome is
|
|
292
|
-
shared by every session on the machine and closes when the last one exits. Its profile
|
|
293
|
-
(`~/.cache/westmarch-mcp/`) keeps page downloads such as an embedding model.
|
|
294
|
-
`--from-block <n>` points the server at another deployment.
|
|
295
|
-
|
|
296
|
-
- **Without a browser:** the views are plain HTTP (`<view>/cdn/catalog`, then the shards it
|
|
297
|
-
names). Point `westmarch/consume/shard.js` at `views[i]`.
|
|
298
|
-
- **The committed data itself:**
|
|
653
|
+
**The committed data itself:**
|
|
299
654
|
|
|
300
655
|
```js
|
|
301
656
|
fangorn.setAppId(appId);
|
|
@@ -312,27 +667,40 @@ const { contents } = await fangorn.readNamespace(timelines[0].owner, namespaces[
|
|
|
312
667
|
wasn't changed after binding. The card is live HTTP, not content-addressed, and the
|
|
313
668
|
binding is to the URL. That's deliberate: the card is mostly endpoints, which change, and
|
|
314
669
|
pinning each version would cost a transaction for nothing. The data's integrity comes
|
|
315
|
-
from the commits, not from the card.
|
|
670
|
+
from the commits and the shard digests, not from the card.
|
|
316
671
|
|
|
317
672
|
## Gotchas
|
|
318
673
|
|
|
319
674
|
| symptom | cause |
|
|
320
675
|
|---|---|
|
|
676
|
+
| push reverts `NotRegisteredForApp` | registered globally but not joined; `fangorn register` does both |
|
|
321
677
|
| `not bound to app … on-chain agent_uri is …` | URLs must match exactly. A trailing slash, `http` vs `https`, or a different path counts as a different card. |
|
|
322
|
-
| card rejected after a rebuild | the build dropped the `fangorn` block or changed `fromBlock`/`url`;
|
|
678
|
+
| card rejected after a rebuild | the build dropped the `fangorn` block or changed `fromBlock`/`url`; keep them fixed |
|
|
323
679
|
| discovery works in Node, fails in a browser | no `Access-Control-Allow-Origin` on the card |
|
|
324
680
|
| `listApps` takes forever | `fromBlock` is too early; the scan is 1000 blocks per RPC call |
|
|
681
|
+
| `app agent`: "ERC-8004 registration pins the registration file to IPFS" | no Pinata JWT in `fangorn init` |
|
|
682
|
+
| `app agent` signs as the wrong wallet | `~/.fangorn/config.json` beats `ETH_PRIVATE_KEY` |
|
|
683
|
+
| search on the page matches words, never meaning | the bundler pre-bundled westmarch; `optimizeDeps.exclude` it |
|
|
684
|
+
| an agent's first call returns empty, later calls work | the tools registered before their data loaded (step 8) |
|
|
685
|
+
| an agent opens the page and finds no tools | `card.url` is not the page that registers them |
|
|
686
|
+
| `search` ignores what records say, or titles are ids | the type isn't declared in the schema, so its roles were guessed; declare it (step 5) |
|
|
687
|
+
| a schema change didn't change search results | records keep the text they were embedded with; only newly embedded records use the new `text` role |
|
|
688
|
+
| the view is empty after a push | `westmarch-view` wasn't rerun, `--from-block` is after your commits, or the push hasn't landed (`fangorn status`) |
|
|
689
|
+
| `westmarch-view`: "vectors from two encoders are not comparable" | the view was built by another embedder (e.g. quickbeam); `--rebake`, or keep publishing it with that tool |
|
|
690
|
+
| `westmarch-view` runs for minutes before doing anything | `--from-block` is far too early; the log scan is 1000 blocks per call |
|
|
691
|
+
| lint: "nowhere to go" | no `presentation.externalUrl` in the schema, so a hit links nowhere |
|
|
692
|
+
| `fangorn-mcp`: "this browser has no WebMCP" | page tools only: the browser lacks `document.modelContext`; it needs Chrome 150+ with `--enable-features=WebMCP` |
|
|
693
|
+
| `fangorn-mcp`: "no browser: cannot launch google-chrome" | page tools only: no local Chrome; set `FANGORN_MCP_CDP` |
|
|
325
694
|
| a log scan misses a transaction you just sent | fixed in the SDK (uncached head block); upgrade to ≥ 2026.9.22-dev |
|
|
326
695
|
| IPFS reads return "switching to a service worker gateway" | ipfs.io stopped serving raw content; use a Pinata gateway |
|
|
327
|
-
| `app agent` signs as the wrong wallet | `~/.fangorn/config.json` beats `ETH_PRIVATE_KEY` |
|
|
328
|
-
| an agent opens the page and finds no tools | `card.url` is the site root, but the tools register on another page |
|
|
329
|
-
| an agent's first call returns empty, later calls work | the tools registered before their data loaded (step 1) |
|
|
330
|
-
| `fangorn-mcp`: "this browser has no WebMCP" | the browser at `FANGORN_MCP_CDP` (or the local Chrome) lacks `document.modelContext`; it needs Chrome 150+ with `--enable-features=WebMCP`, or a build with it on |
|
|
331
|
-
| `fangorn-mcp`: "no browser: cannot launch google-chrome" | no local Chrome; set `FANGORN_MCP_CDP` |
|
|
332
696
|
| the page isn't listed as a "Web" service on 8004scan | agent0-sdk has no web endpoint type; agents find the page through the card's `url` |
|
|
333
697
|
|
|
334
698
|
## Reference: Kingsfoil
|
|
335
699
|
|
|
700
|
+
Kingsfoil has 60,760 clinical trials in 23 views. It predates the schema and quickbeam
|
|
701
|
+
path: it embeds and bakes its own views (`kingsfoil/pipeline/bake.mjs`) and serves them
|
|
702
|
+
from its own site. That works, but every update is a manual rebake and redeploy.
|
|
703
|
+
|
|
336
704
|
| | |
|
|
337
705
|
|---|---|
|
|
338
706
|
| site | https://kingsfoil.pages.dev |
|