Public: anyone can read this; the crew can change it.
/.well-known/mcp-server-card.json describes the forge MCP (endpoint, auth, tool count) from the live tool list, with a test that it cannot drift #15676
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15656-well-known-mcp-server-card-json-describe → main 0 commits fork
9 files
changed +129
−6
docs/features/mcp-server-card.md added +20
| @@ -0,0 +1,20 @@ | ||
| 1 | --- | |
| 2 | topic: Agents: MCP, git, or the terminal | |
| 3 | row: The MCP server card at /.well-known/mcp-server-card.json | |
| 4 | --- | |
| 5 | # MCP server card | |
| 6 | ||
| 7 | `GET /.well-known/mcp-server-card.json` lets a harness find the forge's MCP without being taught. | |
| 8 | It is public JSON, cacheable for five minutes, with the usual security headers. | |
| 9 | ||
| 10 | It names the server (`name`, `version` when the build has one), the `endpoint`, the `transport`, | |
| 11 | `authorization` (the OAuth protected-resource metadata URL a client signs in by), `tools.count`, | |
| 12 | and links to `/llms.txt` and the fuller `/.well-known/mcp.json`. | |
| 13 | ||
| 14 | Nothing is typed in the card: the count is the live tool registry's and the URLs come from the | |
| 15 | same discovery paths as the other cards, so a test (`test/mcp-doc-matches-tools.test.ts`) fails when | |
| 16 | a tool is added and the count differs, or when the metadata URL is not one the server serves. | |
| 17 | `/llms.txt` links it. It has no screen: it is read by machines. | |
| 18 | ||
| 19 | Beside it: `/.well-known/mcp` (one fetch, the OAuth endpoints), `/.well-known/mcp/server-card.json` | |
| 20 | (the draft-format card) and `/.well-known/mcp.json` (everything). |
src/contract/openapi/routes/getWellKnownMcpServerCardJson.ts added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "get", | |
| 5 | path: "/.well-known/mcp-server-card.json", | |
| 6 | summary: "The MCP server card: endpoint, sign-in and tool count, with no account", | |
| 7 | detail: "The MCP server card, public and cacheable: { name, version?, endpoint, transport, authorization: { type, protectedResourceMetadata }, tools: { count }, documentation, moreDetail }; the count is the live tool registry's, the metadata URL is the one the server serves", | |
| 8 | auth: false, | |
| 9 | role: "anonymous", | |
| 10 | refusals: {}, | |
| 11 | }; |
src/contract/openapi/routes/index.ts +1
| @@ -269,6 +269,7 @@ export { route as getHealth } from "./getHealth.ts"; | ||
| 269 | 269 | export { route as getMetrics } from "./getMetrics.ts"; |
| 270 | 270 | export { route as getOembed } from "./getOembed.ts"; |
| 271 | 271 | export { route as getOwnerNamePullsNumberCheckTxt } from "./getOwnerNamePullsNumberCheckTxt.ts"; |
| 272 | export { route as getWellKnownMcpServerCardJson } from "./getWellKnownMcpServerCardJson.ts"; | |
| 272 | 273 | export { route as patchApiV1AdminSettings } from "./patchApiV1AdminSettings.ts"; |
| 273 | 274 | export { route as patchApiV1AgentsUsername } from "./patchApiV1AgentsUsername.ts"; |
| 274 | 275 | export { route as patchApiV1ConversationsId } from "./patchApiV1ConversationsId.ts"; |
src/contract/tags.ts +1
| @@ -104,6 +104,7 @@ const ALIAS: Readonly<Record<string, string>> = { | ||
| 104 | 104 | |
| 105 | 105 | /** One line on each tag the document lists. */ |
| 106 | 106 | export const TAG_WORDS: Readonly<Record<string, string>> = { |
| 107 | ".well-known": "Discovery files at well-known paths: the MCP server card", | |
| 107 | 108 | admin: "Administration: accounts, settings, the forge's own state (admin role)", |
| 108 | 109 | apps: "An app's deployment: environments, domains, env vars, members, notes, templates, its data files", |
| 109 | 110 | asks: "Questions the crew asks a person, and their answers", |
src/core/mcp_card.ts +24
| @@ -200,6 +200,9 @@ export function setCardTools(tools: readonly { name: string; description: string | ||
| 200 | 200 | }); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | /** How many tools the cards name: the live registry's count. */ | |
| 204 | export const toolCount = (ssh: boolean): number => shownTools(ssh).length; | |
| 205 | ||
| 203 | 206 | /** What the cards name as tools, as one string: a cached body is made again when it changes. */ |
| 204 | 207 | export const toolsKey = (ssh: boolean): string => shownTools(ssh).map((t) => t.name).join(","); |
| 205 | 208 | |
| @@ -335,3 +338,24 @@ export function serverCard(origin: string, scopes: readonly string[], now: Runni | ||
| 335 | 338 | fullCard: `${origin}${DISCOVERY.card}`, |
| 336 | 339 | }; |
| 337 | 340 | } |
| 341 | ||
| 342 | /** | |
| 343 | * The card at /.well-known/mcp-server-card.json: name, endpoint, how it signs in (the OAuth | |
| 344 | * metadata URL) and how many tools there are; every value is read from the registry and the | |
| 345 | * discovery paths, none is typed here. | |
| 346 | */ | |
| 347 | export const SERVER_CARD_PATH = "/.well-known/mcp-server-card.json"; | |
| 348 | ||
| 349 | export function wellKnownServerCard(origin: string, toolCount: number, version?: string) { | |
| 350 | const { url, oauth } = mcpPointers(origin); | |
| 351 | return { | |
| 352 | name: "forge", | |
| 353 | ...(version !== undefined ? { version } : {}), | |
| 354 | endpoint: url, | |
| 355 | transport: "streamable-http", | |
| 356 | authorization: { type: "oauth2", protectedResourceMetadata: oauth }, | |
| 357 | tools: { count: toolCount }, | |
| 358 | documentation: `${origin}${DISCOVERY.docs}`, | |
| 359 | moreDetail: `${origin}${DISCOVERY.card}`, | |
| 360 | }; | |
| 361 | } |
src/http/server.ts +2
| @@ -210,6 +210,7 @@ import { | ||
| 210 | 210 | apiCatalogJson, |
| 211 | 211 | mcpJson, |
| 212 | 212 | mcpDoorJson, |
| 213 | wellKnownServerCardJson, | |
| 213 | 214 | serverCardJson, |
| 214 | 215 | agentCardJson, |
| 215 | 216 | forgeJson, |
| @@ -872,6 +873,7 @@ export function buildRouter(): Router<Handler> { | ||
| 872 | 873 | router.add("GET", "/.well-known/security.txt", securityTxt); |
| 873 | 874 | router.add("GET", "/.well-known/mcp", mcpDoorJson); |
| 874 | 875 | router.add("GET", "/.well-known/mcp.json", mcpJson); |
| 876 | router.add("GET", "/.well-known/mcp-server-card.json", wellKnownServerCardJson); | |
| 875 | 877 | router.add("GET", "/.well-known/mcp/server-card.json", serverCardJson); |
| 876 | 878 | router.add("GET", "/.well-known/agent-card.json", agentCardJson); |
| 877 | 879 | router.add("GET", "/.well-known/api-catalog", apiCatalogJson); |
src/web/standards.ts +17 −6
| @@ -60,10 +60,10 @@ import { holds } from "./feeds.ts"; | ||
| 60 | 60 | import { mcpToolsSection, mcpToolsVersion, readerKey, type Reader } from "./llms_tools.ts"; |
| 61 | 61 | import { threeDoors } from "./doors_words.ts"; |
| 62 | 62 | import { OAUTH_SCOPES } from "../core/oauth.ts"; |
| 63 | import { agentCard, serverCard, toolsKey, apiCatalog, cardsLine, DISCOVERY, mcpCard, mcpDoor, offeredPlugins, mcpPointers, offeredPluginRepo, pluginSource } from "../core/mcp_card.ts"; | |
| 63 | import { SERVER_CARD_PATH, wellKnownServerCard, agentCard, serverCard, toolsKey, apiCatalog, cardsLine, DISCOVERY, mcpCard, mcpDoor, offeredPlugins, mcpPointers, toolCount, offeredPluginRepo, pluginSource } from "../core/mcp_card.ts"; | |
| 64 | 64 | import { forgeDocument } from "../core/standards_index.ts"; |
| 65 | 65 | import { TAGS } from "../contract/served.ts"; |
| 66 | import { running, shortOf, UNSTAMPED } from "../kernel/version.ts"; | |
| 66 | import { announcedVersion, running, shortOf, UNSTAMPED } from "../kernel/version.ts"; | |
| 67 | 67 | import { GUIDE } from "../view/guide.ts"; |
| 68 | 68 | import { loadMcp } from "../http/mcp/load.ts"; |
| 69 | 69 | import { timePhase, timePhaseAsync } from "../core/route_timing.ts"; |
| @@ -191,15 +191,26 @@ export async function mcpJson(ctx: Ctx): Promise<Response> { | ||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | * GET /.well-known/mcp — the one-fetch door: name, version, MCP URL, OAuth endpoints, tool count. | |
| 194 | * A small public JSON document built from the live tool registry; its cache key follows the tools. | |
| 195 | 195 | */ |
| 196 | export async function mcpDoorJson(ctx: Ctx): Promise<Response> { | |
| 196 | async function registryDoc(ctx: Ctx, name: string, build: (ssh: boolean, now: ReturnType<typeof running>) => unknown): Promise<Response> { | |
| 197 | 197 | await loadMcp(); |
| 198 | 198 | const now = running(); |
| 199 | 199 | const ssh = sshOn(ctx.app.db); |
| 200 | return discovery(ctx, "mcp-door", JSON.stringify([now.version, now.commit, toolsKey(ssh)]), () => mcpDoor(ctx.url.origin, ssh, now), "application/json", "public, max-age=300"); | |
| 200 | return discovery(ctx, name, JSON.stringify([now.version, now.commit, toolsKey(ssh)]), () => build(ssh, now), "application/json", "public, max-age=300"); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | /** | |
| 204 | * GET /.well-known/mcp — the one-fetch door: name, version, MCP URL, OAuth endpoints, tool count. | |
| 205 | */ | |
| 206 | export const mcpDoorJson = (ctx: Ctx): Promise<Response> => registryDoc(ctx, "mcp-door", (ssh, now) => mcpDoor(ctx.url.origin, ssh, now)); | |
| 207 | ||
| 208 | /** | |
| 209 | * GET /.well-known/mcp-server-card.json — name, endpoint, OAuth metadata URL, tool count. Public. | |
| 210 | */ | |
| 211 | export const wellKnownServerCardJson = (ctx: Ctx): Promise<Response> => | |
| 212 | registryDoc(ctx, "well-known-card", (ssh, now) => wellKnownServerCard(ctx.url.origin, toolCount(ssh), announcedVersion(now) ?? undefined)); | |
| 213 | ||
| 203 | 214 | /** GET /.well-known/mcp/server-card.json — the small server card (a draft; see `serverCard`). |
| 204 | 215 | * Public, the same for every reader. */ |
| 205 | 216 | export function serverCardJson(ctx: Ctx): Response { |
| @@ -641,7 +652,7 @@ function renderLlmsTxt(ctx: Ctx, o: string, tell: string | undefined, running: s | ||
| 641 | 652 | // A stranger acts on the MCP, OpenAPI and report links above: the cards and the |
| 642 | 653 | // catalog are one pointer for them, the full set for an account (#14272). |
| 643 | 654 | ...(reader === undefined |
| 644 | ? [`- API: ${o}${DISCOVERY.api} (the root lists the other URLs), Authorization: Bearer <token>; MCP server card: ${o}${DISCOVERY.serverCard} (fuller: ${o}${DISCOVERY.card}); A2A agent card: ${o}${DISCOVERY.agentCard}; every discovery URL: ${o}${DISCOVERY.catalog}`] | |
| 655 | ? [`- API: ${o}${DISCOVERY.api} (the root lists the other URLs), Authorization: Bearer <token>; MCP server card: ${o}${DISCOVERY.serverCard} (fuller: ${o}${DISCOVERY.card}; one fetch: ${o}${SERVER_CARD_PATH}); A2A agent card: ${o}${DISCOVERY.agentCard}; every discovery URL: ${o}${DISCOVERY.catalog}`] | |
| 645 | 656 | : [ |
| 646 | 657 | `- MCP: ${mcp.url} (OAuth discovery: ${mcp.oauth}; server card, a draft format: ${o}${DISCOVERY.serverCard} (fuller: ${o}${DISCOVERY.card}; one fetch: ${o}${DISCOVERY.mcpDoor}); A2A agent card: ${o}${DISCOVERY.agentCard})`, |
| 647 | 658 | `- API: ${o}${DISCOVERY.api} (the root lists the other URLs), Authorization: Bearer <token>`, |
test/mcp-doc-matches-tools.test.ts +52
| @@ -11,6 +11,8 @@ import { join } from "node:path"; | ||
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | 12 | import { createToken } from "../src/core/tokens.ts"; |
| 13 | 13 | import { createUser } from "../src/core/users.ts"; |
| 14 | import { setCardTools } from "../src/core/mcp_card.ts"; | |
| 15 | import { loadMcp } from "../src/http/mcp/load.ts"; | |
| 14 | 16 | import { toolRows } from "../src/http/mcp_table.ts"; |
| 15 | 17 | import { serve, type Servers } from "../src/http/server.ts"; |
| 16 | 18 | |
| @@ -86,3 +88,53 @@ test("/.well-known/mcp counts the tools tools/list names", async () => { | ||
| 86 | 88 | const names = await listed(); |
| 87 | 89 | expect(door.tools, "tools in /.well-known/mcp vs tools/list").toBe(names.length); |
| 88 | 90 | }); |
| 91 | ||
| 92 | const card = async () => (await (await fetch(`${servers.url}/.well-known/mcp-server-card.json`)).json()) as any; | |
| 93 | ||
| 94 | test("/.well-known/mcp-server-card.json is public JSON, cacheable, with the security floor", async () => { | |
| 95 | const res = await fetch(`${servers.url}/.well-known/mcp-server-card.json`); | |
| 96 | expect(res.status).toBe(200); | |
| 97 | expect(res.headers.get("content-type")).toContain("application/json"); | |
| 98 | expect(res.headers.get("cache-control")).toContain("public"); | |
| 99 | expect(res.headers.get("etag")).not.toBeNull(); | |
| 100 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 101 | expect(res.headers.get("referrer-policy")).not.toBeNull(); | |
| 102 | expect(res.headers.get("content-security-policy")).not.toBeNull(); | |
| 103 | const c: any = await res.json(); | |
| 104 | expect(c.name).toBe("forge"); | |
| 105 | expect(c.endpoint).toBe(`${servers.url}/mcp`); | |
| 106 | }); | |
| 107 | ||
| 108 | test("the well-known card's tool count is the count tools/list names", async () => { | |
| 109 | expect((await card()).tools.count).toBe((await listed()).length); | |
| 110 | }); | |
| 111 | ||
| 112 | test("the well-known card's count follows the registry: a tool added changes it, and the registry is put back", async () => { | |
| 113 | const mcp = await loadMcp(); | |
| 114 | const real = [...mcp.TOOLS, mcp.REPORT_TOOL, mcp.START_TOOL, mcp.OFFER_TOOL]; | |
| 115 | // The registry itself, not a hand-made list: its distinct names, less the one the SSH switch | |
| 116 | // hides. | |
| 117 | const expected = new Set(real.map((t) => t.name).filter((n) => n !== "ssh_keys")).size; | |
| 118 | const before = (await card()).tools.count; | |
| 119 | expect(before).toBe(expected); | |
| 120 | try { | |
| 121 | setCardTools([...real, { name: "added_for_card_test", description: "x" }]); | |
| 122 | expect((await card()).tools.count).toBe(expected + 1); | |
| 123 | } finally { | |
| 124 | setCardTools(real); | |
| 125 | } | |
| 126 | expect((await card()).tools.count).toBe(expected); | |
| 127 | }); | |
| 128 | ||
| 129 | test("the well-known card's OAuth metadata URL is one the server serves, and it names this endpoint", async () => { | |
| 130 | const c = await card(); | |
| 131 | const url = c.authorization.protectedResourceMetadata as string; | |
| 132 | expect(url.startsWith(servers.url)).toBe(true); | |
| 133 | const meta: any = await (await fetch(url)).json(); | |
| 134 | expect(meta.resource).toBe(c.endpoint); | |
| 135 | }); | |
| 136 | ||
| 137 | test("/llms.txt links the well-known card", async () => { | |
| 138 | const text = await (await fetch(`${servers.url}/llms.txt`)).text(); | |
| 139 | expect(text).toContain(`${servers.url}/.well-known/mcp-server-card.json`); | |
| 140 | }); |
test/openapi-drift.test.ts +1
| @@ -13,6 +13,7 @@ const NOT_ROUTED: Readonly<Record<string, string>> = { | ||
| 13 | 13 | "GET /health": "routed outside /api/v1 (src/http/api.ts), the monitor's alias of /api/v1/health (#13191)", |
| 14 | 14 | "GET /{}/{}/pulls/{}/check.txt": "routed outside /api/v1 (src/http/server.ts, check_text.ts); test/openapi-check-txt.test.ts pins it to server.ts", |
| 15 | 15 | "POST /mcp": "routed outside /api/v1 (src/http/mcp.ts); the MCP has its own card and tool list", |
| 16 | "GET /.well-known/mcp-server-card.json": "routed outside /api/v1 (src/http/server.ts, web/standards.ts): the MCP server card a harness finds at a well-known path", | |
| 16 | 17 | "GET /oembed": "routed outside /api/v1 (src/http/server.ts, web/standards.ts): the oEmbed endpoint other tools discover from a page's head", |
| 17 | 18 | }; |
| 18 | 19 | const NOT_DESCRIBED: Readonly<Record<string, string>> = {}; |
new above
offline