Skip to content

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.

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" };
},
};
  • origins holds {team}, a config field of type label: one part of a host name, such as acme. 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 of team would change the origin, so inseam refuses it: the person connects the host again.
  • auth says 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 sets Authorization itself.
  • entryOf builds every entry, for list and for stat, so they agree. path is the note’s permanent id, and mime is the service’s own type, because the paths have no extension.
  • stat returns null for a path it cannot parse, and a 404 is null, not an error.
  • read returns the service’s response as it is: the note’s own JSON.
  • convert turns that JSON into Markdown. Its conversion is for this host only. The index takes the Markdown; read still gives the JSON, and read … as "text/markdown" gives the Markdown.

Ask the person for the team address (never for the token), then:

Terminal window
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_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.

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.