Write a host plugin
A host plugin connects a service to your network. This one connects a team’s notes on a made-up service, Acme Notes,
where each team has its own address: https://{team}.acmenotes.example. Its notes come as JSON blocks, so the same
file also converts them to Markdown: the notes become searchable, and read still gives the service’s own JSON.
The person’s side, approving and installing, is in connect a cloud account.
The plugin
Section titled “The plugin”const base = (config) => "https://" + config.team + ".acmenotes.example";
const entryOf = (n) => ({ path: "notes/" + n.id, mtime: new Date(n.updated_at).toISOString(), etag: String(n.revision), mime: "application/vnd.acme.note+json", title: n.title, extra: { author: n.author ?? null },});
const get = async (url) => { const res = await fetch(url, { headers: { accept: "application/json" } }); if (res.status === 404) return null; if (!res.ok) throw new Error("GET " + url + " answered " + res.status); return res;};
const idOf = (path) => /^notes\/([A-Za-z0-9_-]{1,64})$/.exec(path)?.[1] ?? null;
export default { manifest: { contract: 3, name: "acme-notes", title: "Acme Notes", description: "Lists and reads a team's notes on Acme Notes, and makes them searchable as Markdown.", origins: ["https://{team}.acmenotes.example"], auth: { type: "static", fields: [{ name: "token", label: "API token", help: "Acme Notes → Settings → API → Read-only token" }], present: [{ in: "header", origin: "https://{team}.acmenotes.example", name: "Authorization", value: "Bearer {token}" }], instructions: "Create a read-only API token in Acme Notes under Settings → API.", }, config: [{ name: "team", label: "Team address", type: "label", required: true, help: "the first part of your team's address", example: "acme" }], host: { listing: "free" }, convert: [{ from: "application/vnd.acme.note+json", to: "text/markdown" }], },
host: { async list({ cursor, limit, config }) { const url = base(config) + "/api/notes?limit=" + limit + (cursor ? "&after=" + encodeURIComponent(cursor) : ""); const page = await (await get(url)).json(); return { entries: page.notes.map(entryOf), ...(page.next ? { cursor: String(page.next) } : {}) }; }, async stat({ path, config }) { const id = idOf(path); if (!id) return null; const res = await get(base(config) + "/api/notes/" + encodeURIComponent(id)); return res ? entryOf(await res.json()) : null; }, async read({ path, config }) { const id = idOf(path); const res = id ? await get(base(config) + "/api/notes/" + encodeURIComponent(id) + "/body") : null; if (!res) throw new Error("no such note: " + path); return res; }, },
convert({ text }) { const note = JSON.parse(text); if (!note || !Array.isArray(note.blocks)) throw new Error("not an Acme note"); const lines = note.blocks.map((b) => (b.type === "heading" ? "## " + String(b.text ?? "") : String(b.text ?? ""))); const title = typeof note.title === "string" ? note.title : undefined; return { title, text: (title ? "# " + title + "\n\n" : "") + lines.join("\n\n") + "\n" }; },};What each part does
Section titled “What each part does”originsholds{team}, a config field of typelabel: one part of a host name, such asacme. inseam fills it in from the person’s setting. The person approves the result,https://acme.acmenotes.example, and the plugin reaches nothing else. A later change ofteamwould change the origin, so inseam refuses it: the person connects the host again.authsays the person types a token on the approval page, and inseam sends it as a bearer token to that one origin. The code never sees it, and never setsAuthorizationitself.entryOfbuilds every entry, forlistand forstat, so they agree.pathis the note’s permanent id, andmimeis the service’s own type, because the paths have no extension.statreturnsnullfor a path it cannot parse, and a 404 isnull, not an error.readreturns the service’s response as it is: the note’s own JSON.convertturns that JSON into Markdown. Its conversion is for this host only. The index takes the Markdown;readstill gives the JSON, andread … as "text/markdown"gives the Markdown.
Submit it
Section titled “Submit it”Ask the person for the team address (never for the token), then:
mcp trial_plugin "$(jq -n --rawfile code acme-notes.js '{ name: "Acme Notes (acme)", code: $code, config: { team: "acme" }, examples: [{ text: "{\"title\":\"Launch\",\"blocks\":[{\"type\":\"heading\",\"text\":\"Goals\"},{\"type\":\"para\",\"text\":\"Ship on Friday.\"}]}", expect: { contains: ["## Goals", "Ship on Friday."], title: "Launch" } }]}')"The answer is a trial in awaiting-approval, with the page the person opens in next.open. After they approve,
trial_status shows two sets of checks: the host’s (list, list-next-page, list-stable, stat, stat-missing,
read, egress, against the real service) and the converter’s (examples, corpus, deterministic,
no-network, budget, metadata).
Review it
Section titled “Review it”review_plugin {trialId} returns a checklist of both slots. Answer each check with line numbers. Add tests for the
converter and, for the host, paths that stat must survive:
{ "paths": [ { "path": "notes/../admin", "why": "a dot segment does not parse and returns null" }, { "path": "notes/a%2Fb", "why": "an encoded slash does not parse and returns null" }, { "path": "notes/missing-note", "why": "a 404 is null, not an error" } ], "tests": [ { "text": "{\"blocks\":[]}", "why": "a note with no title and no blocks gives an empty body" }, { "text": "{\"title\":\"T\",\"blocks\":[{\"type\":\"heading\"}]}", "why": "a heading with no text keeps its mark" }, { "text": "[]", "why": "an array is not a note and is refused" } ] }Then install_plugin {trialId}, and the person selects Install and start indexing. The host is crawled every
hour, and its notes are searchable as Markdown.
Publish it
Section titled “Publish it”The manifest holds no team and no token: only {team}. So the same file serves every team. An owner publishes it
from Plugins in the app; another network installs it with its own team address and token.