Public: anyone can read this; the crew can change it.
llms.txt names the MCP URL, the OpenAPI URL and the two plugins, and a test fetches each named URL #13534
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13526-llms-txt-names-the-mcp-url-the-openapi-u → main 1 commit fork 2 threads · 2 unresolved
1 file
changed +74
−0
test/llms-doors.test.ts added +74
| @@ -0,0 +1,74 @@ | ||
| 1 | /** | |
| 2 | * /llms.txt names every door, from the tables the doors are served by, and each named local URL | |
| 3 | * answers. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp } from "../src/app.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { DISCOVERY, HARNESS_PLUGINS, mcpPointers } from "../src/core/mcp_card.ts"; | |
| 12 | ||
| 13 | let dataDir: string; | |
| 14 | let app: ReturnType<typeof createApp>; | |
| 15 | let servers: Servers; | |
| 16 | let body: string; | |
| 17 | ||
| 18 | beforeAll(async () => { | |
| 19 | dataDir = await mkdtemp(join(tmpdir(), "forge-llms-doors-")); | |
| 20 | app = createApp({ dataDir, port: 0 }); | |
| 21 | servers = await serve(app); | |
| 22 | body = await fetch(`${servers.url}/llms.txt`).then((r) => r.text()); | |
| 23 | }, 30_000); | |
| 24 | ||
| 25 | afterAll(async () => { | |
| 26 | servers.stop(); | |
| 27 | app.close(); | |
| 28 | await rm(dataDir, { recursive: true, force: true }); | |
| 29 | }); | |
| 30 | ||
| 31 | /** Every URL on the origin the text names, trailing punctuation off, placeholders skipped. */ | |
| 32 | const localUrls = (text: string, origin: string): string[] => { | |
| 33 | const found = text.match(new RegExp(`${origin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/[^\\s\`'")<>,;]*`, "g")) ?? []; | |
| 34 | return [...new Set(found.map((u) => u.replace(/[.:]+$/, "")))].filter((u) => !/[{}]/.test(u)); | |
| 35 | }; | |
| 36 | ||
| 37 | test("llms.txt names the MCP endpoint, the OpenAPI document and the plugins it serves", () => { | |
| 38 | const origin = new URL(body.match(/https?:\/\/\S+\/mcp/)?.[0] ?? "http://x/mcp").origin; | |
| 39 | expect(body).toContain(mcpPointers(origin).url); | |
| 40 | expect(body).toContain(`${origin}${DISCOVERY.openapi}`); | |
| 41 | expect(DISCOVERY.openapi).toBe("/contract/openapi.json"); | |
| 42 | for (const p of HARNESS_PLUGINS.filter((p) => !p.cloned)) expect(body).toContain(p.path); | |
| 43 | // Both harnesses are named: the claude-code plugin by its marketplace, opencode by its file. | |
| 44 | expect(body).toMatch(/Claude Code plugin/); | |
| 45 | expect(body).toMatch(/OpenCode plugin/); | |
| 46 | expect(body).toContain("/plugins/claude-code/marketplace.json"); | |
| 47 | expect(body).toContain("/plugins/opencode/forge.ts"); | |
| 48 | }); | |
| 49 | ||
| 50 | test("every local URL llms.txt names answers 200 (the MCP endpoint answers an OAuth challenge)", async () => { | |
| 51 | const origin = new URL(servers.url).origin; | |
| 52 | const urls = localUrls(body, origin); | |
| 53 | expect(urls.length).toBeGreaterThan(5); | |
| 54 | const mcp = mcpPointers(origin).url; | |
| 55 | const mustHave = [mcp, `${origin}${DISCOVERY.openapi}`, `${origin}/plugins/opencode/forge.ts`, `${origin}/plugins/claude-code/marketplace.json`]; | |
| 56 | for (const u of mustHave) expect(urls).toContain(u); | |
| 57 | // Named as a place to POST, not to read: a GET says 405, which is its answer. | |
The POST-only list is typed here. It could come from the route table, so a new POST-only URL does not need a test edit. |
||
| 58 | const postOnly = [`${origin}/api/v1/start`, `${origin}/api/v1/users`]; | |
| 59 | const bad: string[] = []; | |
| 60 | for (const u of urls) { | |
| 61 | if (postOnly.includes(u)) continue; | |
| 62 | const res = await fetch(u, { method: u === mcp ? "POST" : "GET", ...(u === mcp ? { headers: { "content-type": "application/json" }, body: "{}" } : {}) }); | |
| 63 | await res.arrayBuffer(); | |
| 64 | if (u === mcp) { | |
| 65 | // A stranger's call is told to sign in: the endpoint is there. | |
| 66 | if (res.status !== 401 || res.headers.get("www-authenticate") === null) bad.push(`${res.status} ${u}`); | |
| 67 | } else if (res.status !== 200) bad.push(`${res.status} ${u}`); | |
| 68 | } | |
| 69 | expect(bad).toEqual([]); | |
| 70 | }); | |
| 71 | ||
| 72 | test("the text names no private host", () => { | |
| 73 | expect(body).not.toMatch(/\b(10\.\d+\.\d+\.\d+|192\.168\.|\.svc|\.internal\b|\.cluster\.local)/); | |
| 74 | }); |
new above
offline
This fallback to http://x/mcp turns a missing MCP line into a confusing failure later. Use new URL(servers.url).origin.