commit 3f9c12eeffbf3cd7d8101b67856b977fb67fdcf8
parent 3071a6b51f8ef3bf5bc9115930304d214415aee9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 10:43:21 -0500
mcp: x_trending_accounts -- a library's accounts, read only; no tool organises a library or publishes a topic
One GET of the editor's listing with accounts=1 (topic and limit pass
through). The privacy sweep allows that key and no judge-view key, and
now also refuses any MCP source that names the organise or publish
routes, their bodies or the publish record.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
5 files changed, 131 insertions(+), 2 deletions(-)
diff --git a/mcp/src/protocol.test.ts b/mcp/src/protocol.test.ts
@@ -52,6 +52,7 @@ const EXPECTED_TOOLS = [
"x_search_leads",
"x_trending_topics",
"x_trending_posts",
+ "x_trending_accounts",
"generation_policy",
"generate",
"list_sources",
diff --git a/mcp/src/server.ts b/mcp/src/server.ts
@@ -100,7 +100,7 @@ import {
type ToolAnswer,
} from "./archivalTools";
import { X_SEARCH_TOOLS, xSearchLeadsTool } from "./xSearchLeads";
-import { X_TRENDING_TOOLS, xTrendingPostsTool, xTrendingTopicsTool } from "./xTrending";
+import { X_TRENDING_TOOLS, xTrendingAccountsTool, xTrendingPostsTool, xTrendingTopicsTool } from "./xTrending";
import {
GENERATION_TOOLS,
generateTool,
@@ -1357,6 +1357,8 @@ export function createServer(
return fromAnswer(await xTrendingTopicsTool(args, fetchClipDeps));
case "x_trending_posts":
return fromAnswer(await xTrendingPostsTool(args, fetchClipDeps));
+ case "x_trending_accounts":
+ return fromAnswer(await xTrendingAccountsTool(args, fetchClipDeps));
case "notes":
return fromAnswer(await notesTool(args, fetchClipDeps));
case "generation_policy":
diff --git a/mcp/src/xTrending.test.ts b/mcp/src/xTrending.test.ts
@@ -163,3 +163,43 @@ test("the tools say a topic's watch, and a post's thread, capture, gone-from-the
" judged keep by operator (its thread) (2026-11-18 09:00 UTC)",
]);
});
+
+// Lane x-trending-publish: the library's accounts.
+test("x_trending_accounts: one GET with accounts=1; handle, posts, kept, topics and who archives it", async () => {
+ const ACCOUNTS = {
+ ok: true,
+ slug: "trending",
+ accounts: [
+ { handle: "teapot_news", key: "teapot_news", name: "Teapot News", posts: 3, kept: 2, keptByOperator: 1, topics: ["kettle-festival", "cups"], last: "2026-11-16T12:00:00.000Z" },
+ { handle: "saucer_fan", key: "saucer_fan", posts: 1, kept: 0, keptByOperator: 0, topics: ["cups"], last: "2026-11-16T13:00:00.000Z", archivedAs: ["saucer_fan-x"] },
+ ],
+ total: 4,
+ posts: 6,
+ more: 2,
+ };
+ const { deps, sent } = fakeEditor(() => ({ status: 200, body: ACCOUNTS }), env);
+ const client = await connectWith(deps);
+ const res = await client.callTool({ name: "x_trending_accounts", arguments: { channel: "trending", topic: "cups", limit: 2 } });
+ assert.ok(!isError(res));
+ assert.equal(sent.length, 1);
+ assert.equal(sent[0].method, "GET");
+ assert.equal(new URL(sent[0].url).pathname, "/api/ops/trending");
+ assert.deepEqual([...new URL(sent[0].url).searchParams.entries()], [["slug", "trending"], ["accounts", "1"], ["topic", "cups"], ["limit", "2"]]);
+ const text = body(res);
+ assert.match(text, /^X trending library trending, topic cups: 4 accounts over 6 posts \(2 listed, 2 more\)\./);
+ assert.match(text, /- @teapot_news \(Teapot News\): 3 posts, 2 kept \(1 by the operator\); topics: kettle-festival, cups; newest 2026-11-16 12:00/);
+ assert.match(text, /- @saucer_fan: 1 post; topics: cups; newest 2026-11-16 13:00; already archived as saucer_fan-x/);
+ assert.match(text, /From a library it asks X nothing/);
+
+ assert.match(textOf(await client.callTool({ name: "x_trending_accounts", arguments: { channel: "" } })), /channel is required/);
+ assert.match(textOf(await client.callTool({ name: "x_trending_accounts", arguments: { channel: "trending", limit: 501 } })), /limit is a whole number, 1–500/);
+ assert.match(textOf(await client.callTool({ name: "x_trending_accounts", arguments: { channel: "trending", topic: " " } })), /topic is a topic's id/);
+ assert.equal(sent.length, 1, "a refused ask sends nothing");
+});
+
+test("the MCP has a tool to read a library's accounts and none to organise or publish", async () => {
+ const { deps } = fakeEditor(() => ({ status: 200, body: {} }), env);
+ const client = await connectWith(deps);
+ const names = (await client.listTools()).tools.map((t) => t.name).filter((n) => /trending/.test(n));
+ assert.deepEqual(names.sort(), ["x_trending_accounts", "x_trending_posts", "x_trending_topics"]);
+});
diff --git a/mcp/src/xTrending.ts b/mcp/src/xTrending.ts
@@ -146,6 +146,65 @@ export async function xTrendingPostsTool(args: Record<string, unknown>, deps: Ed
return { text: renderXTrendingPosts(channel, a.body as ListingBody, topic) };
}
+// ─── x_trending_accounts (lane x-trending-publish, slice 4) ───
+//
+// THE LIBRARY'S ACCOUNTS, like an X search channel's leads: who wrote the
+// posts it holds (GET /api/ops/trending?slug=&accounts=1[&topic=][&limit=]).
+// Read only. Organising a library's topics and publishing one are asks of the
+// editor (`pnpm ops`), and a publish is the operator's: this server has no
+// tool for either.
+
+type AccountRow = { handle: string; name?: string; posts: number; kept: number; keptByOperator?: number; topics?: string[]; last?: string; archivedAs?: string[] };
+type AccountsBody = { accounts?: AccountRow[]; total?: number; posts?: number; more?: number };
+
+export const X_TRENDING_ACCOUNTS_MAX = 500;
+
+export function renderXTrendingAccounts(slug: string, body: AccountsBody, topic?: string): string {
+ const rows = body.accounts ?? [];
+ const where = topic ? `${slug}, topic ${topic}` : slug;
+ const lines = [`X trending library ${where}: ${body.total ?? rows.length} account${(body.total ?? rows.length) === 1 ? "" : "s"} over ${body.posts ?? 0} post${body.posts === 1 ? "" : "s"}${body.more ? ` (${rows.length} listed, ${body.more} more)` : ""}.`];
+ if (rows.length === 0) lines.push("No account yet: read a trending page into the library first (`pnpm ops read-x-trending`).");
+ for (const a of rows) {
+ const kept = a.kept ? `, ${a.kept} kept${a.keptByOperator !== undefined && a.keptByOperator !== a.kept ? ` (${a.keptByOperator} by the operator)` : ""}` : "";
+ lines.push(
+ `- @${a.handle}${a.name ? ` (${a.name})` : ""}: ${a.posts} post${a.posts === 1 ? "" : "s"}${kept}` +
+ `${a.topics?.length ? `; topics: ${a.topics.join(", ")}` : ""}` +
+ `${a.last ? `; newest ${day(a.last)}` : ""}` +
+ `${a.archivedAs?.length ? `; already archived as ${a.archivedAs.join(", ")}` : ""}`,
+ );
+ }
+ lines.push(
+ "",
+ "Archiving an account as its own X channel (<handle>-x, on no site) is the operator's or an agent's ask of the editor: " +
+ "`pnpm ops x-search-lead --json '{\"slug\":\"<library>\",\"handle\":\"<handle>\",\"action\":\"archive\",\"dryRun\":true}'`. From a library it asks X nothing: the first fetch is a separate step.",
+ );
+ return lines.join("\n");
+}
+
+export async function xTrendingAccountsTool(args: Record<string, unknown>, deps: EditorDeps): Promise<ToolAnswer> {
+ const channel = slugOf("x_trending_accounts", args);
+ if (typeof channel !== "string") return channel;
+ const q = new URLSearchParams({ slug: channel, accounts: "1" });
+ let topic: string | undefined;
+ if (args.topic !== undefined) {
+ if (typeof args.topic !== "string" || !args.topic.trim()) {
+ return { text: "x_trending_accounts: topic is a topic's id (x_trending_topics lists them)", isError: true };
+ }
+ topic = args.topic.trim();
+ q.set("topic", topic);
+ }
+ if (args.limit !== undefined) {
+ const n = Number(args.limit);
+ if (!Number.isInteger(n) || n < 1 || n > X_TRENDING_ACCOUNTS_MAX) {
+ return { text: `x_trending_accounts: limit is a whole number, 1–${X_TRENDING_ACCOUNTS_MAX}`, isError: true };
+ }
+ q.set("limit", String(n));
+ }
+ const a = await editorGet(deps, `/api/ops/trending?${q.toString()}`);
+ if (a.kind !== "ok") return { text: describeEditorFailure("x_trending_accounts", a), isError: true };
+ return { text: renderXTrendingAccounts(channel, a.body as AccountsBody, topic) };
+}
+
export const X_TRENDING_TOOLS = [
{
name: "x_trending_topics",
@@ -191,4 +250,24 @@ export const X_TRENDING_TOOLS = [
additionalProperties: false,
},
},
+ {
+ name: "x_trending_accounts",
+ description:
+ "The ACCOUNTS of an X TRENDING LIBRARY (or of one of its topics), like an X search channel's " +
+ "leads: each account's handle and name, how many of the library's posts it wrote, how many of " +
+ "them are kept, the topics they are in, and the X channels that already archive it — most " +
+ "posts first. For deciding which account deserves an archive of its own (`pnpm ops " +
+ "x-search-lead`, action \"archive\": <handle>-x on no site). PRIVATE material, like the " +
+ "library's posts. Read only. Needs ARCHILYZER_EDITOR_URL and WORKER_TOKEN.",
+ inputSchema: {
+ type: "object",
+ properties: {
+ channel: { type: "string", description: "The X trending library's slug (the editor's)." },
+ topic: { type: "string", description: "A topic's id (from x_trending_topics): only its posts' accounts." },
+ limit: { type: "number", description: `Accounts to list (default 100, at most ${X_TRENDING_ACCOUNTS_MAX}).` },
+ },
+ required: ["channel"],
+ additionalProperties: false,
+ },
+ },
] as const;
diff --git a/mcp/src/xTrendingPrivacy.test.ts b/mcp/src/xTrendingPrivacy.test.ts
@@ -177,7 +177,9 @@ test("every read-only corpus tool over the composed site: the account's post, ne
// THE MCP BUILDS ITS QUERY WITH `new URLSearchParams({…})` AND `.set("…")`, so
// that is what is read: every key given to either, in a source that asks the
// listing, is one of the three.
-const LISTING_KEYS = new Set(["slug", "topic", "limit"]);
+// `accounts` (lane x-trending-publish): the library's accounts, a read like
+// the other two. Still never a judge view's key.
+const LISTING_KEYS = new Set(["slug", "topic", "limit", "accounts"]);
function queryKeys(text: string): string[] {
const keys: string[] = [];
@@ -203,6 +205,11 @@ test("posts-library: no MCP source asks the listing for the judge view's fields,
let asking = 0;
for (const name of sources) {
const text = readFileSync(path.join(here, name), "utf8");
+ // Lane x-trending-publish: nor a way to organise a library or publish a
+ // topic — those are asks of the editor, and a publish is the operator's.
+ for (const word of ["/api/ops/organise-trending", "/api/ops/publish-trending", "publishXTrending", "organiseXTrending", "mergeXTrendingTopics", "published.json"]) {
+ assert.ok(!text.includes(word), `mcp/src/${name} names ${word}`);
+ }
for (const word of ["purge-trending", "purgeXTrending", "removeXTrendingPostCapture", "/api/library", "judge-trending\"", "watch-trending\""]) {
assert.ok(!text.includes(word), `mcp/src/${name} names ${word}`);
}