Public: anyone can read this; the crew can change it.

llms.txt, the MCP server card and tools/list name the same number of tools a stranger can sign in for #15874

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/15869-llms-txt-the-mcp-server-card-and-tools-l → main 0 commits fork 1 thread · 1 unresolved

  • Merged. mason/15869-llms-txt-the-mcp-server-card-and-tools-l was merged into main as f8bcf02.

Review

Sign in to review this change.
2 files changed +22 −5
src/web/llms_tools.ts +3 −5
@@ -7,7 +7,7 @@
77 * token-free tools and one line for the rest, so /llms.txt varies by reader.
88 */
99 import type { Tool } from "../http/mcp/shared.ts";
10 import { TOKEN_FREE_TOOLS } from "../core/mcp_card.ts";
10 import { moreAfterSignIn, TOKEN_FREE_TOOLS } from "../core/mcp_card.ts";
1111 import { scopeAllows, type TokenScope } from "../core/tokens.ts";
1212
1313 /** What a line reads: `report` is not a `Tool`, having no `run`, but is listed. */
@@ -61,7 +61,6 @@ export function callableBy(t: Listed, r: Reader): boolean {
6161
6262 // The index is handed in at boot by the server rather than imported here:
6363 // importing it from a page module closes an import cycle through the actions.
64 let toolCount = 0;
6564 let open: readonly Listed[] = [];
6665 let every: readonly Listed[] = [];
6766 let sections = new Map<string, readonly string[]>();
@@ -73,7 +72,6 @@ export const setMcpTools = (all: readonly Listed[], tokenFree: readonly Listed[]
7372 // The open tools in TOOLS (explore, search) are listed with `report` and `start`,
7473 // not counted among the rest.
7574 const free = all.filter((t) => TOKEN_FREE_TOOLS.includes(t.name));
76 toolCount = all.length - free.length;
7775 open = [...tokenFree, ...free];
7876 every = [...all, ...tokenFree];
7977 sections = new Map(); // every kept per-reader list goes with the old index
@@ -81,11 +79,11 @@ export const setMcpTools = (all: readonly Listed[], tokenFree: readonly Listed[]
8179
8280 /** The kept-body key for a reader: tools differ by scope and by admin, nothing else. */
8381 export const readerKey = (r: Reader | undefined, ssh: boolean): string =>
84 r === undefined ? "anon" : `${r.scope}${r.isAdmin ? "+admin" : ""}${ssh ? "+ssh" : ""}`;
82 r === undefined ? `anon${ssh ? "+ssh" : ""}` : `${r.scope}${r.isAdmin ? "+admin" : ""}${ssh ? "+ssh" : ""}`;
8583
8684 /** A signed-in reader's section is the tools they may call; a stranger's is folded. */
8785 export function mcpToolsSection(origin: string, reader: Reader | undefined, ssh: boolean): readonly string[] {
88 if (reader === undefined) return anonymousToolsSection(open, toolCount, origin);
86 if (reader === undefined) return anonymousToolsSection(open, moreAfterSignIn(ssh), origin);
8987 const k = readerKey(reader, ssh);
9088 let s = sections.get(k);
9189 if (s === undefined) sections.set(k, (s = toolsSection(every.filter((t) => (t.needsSwitch === undefined || ssh) && callableBy(t, reader)))));
test/tool-count-agree.test.ts added +19
@@ -0,0 +1,19 @@
1 /**
2 * llms.txt, the server card and tools/list give a stranger the same count of tools an account adds.
3 */
4 import { expect, test } from "bun:test";
5 import { loadMcp } from "../src/http/mcp/load.ts";
6 import { mcpCard, TOKEN_FREE_TOOLS } from "../src/core/mcp_card.ts";
7 import { mcpToolsSection } from "../src/web/llms_tools.ts";
8
9 for (const ssh of [false, true]) {
10 test(`the three counts agree with the terminal ${ssh ? "on" : "off"}`, async () => {
11 await loadMcp();
12 const origin = "https://forge.test";
13 const line = mcpToolsSection(origin, undefined, ssh).find((l) => / more tools with an account/.test(l))!;
14 const llms = Number(line.match(/^- (\d+) more tools/)![1]);
15 const anonymous = TOKEN_FREE_TOOLS.length;
16 const total = mcpCard(origin, undefined, ssh).tools.length;

Anonymous count is TOKEN_FREE_TOOLS.length, not the length of an anonymous tools/list; call the handler so the test follows what a stranger really gets.

17 expect(llms).toBe(total - anonymous);
18 });
19 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs