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

The MCP initialize answer and /.well-known/mcp name the release number, never "dev" #15374

Merged opened this

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

Merged

scout/forge:scout/15363-the-mcp-initialize-answer-and-well-known → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/15363-the-mcp-initialize-answer-and-well-known was merged into main as 1a364cf.

Review

Sign in to review this change.
12 files changed +119 −23
src/contract/served.ts +2 −2
@@ -8,7 +8,7 @@ import { encodeOnce, negotiate } from "../http/compress.ts";
88 import { holds, weakEtag } from "../http/etag.ts";
99 import type { Auth, Handler } from "../http/context.ts";
1010 import type { Router } from "../http/router.ts";
11 import { running } from "../kernel/version.ts";
11 import { announcedOr } from "../kernel/version.ts";
1212 import { openapi, ROUTES } from "./openapi.ts";
1313 import type { Role } from "./openapi/shared.ts";
1414 import { tagList, tagOf } from "./tags.ts";
@@ -86,7 +86,7 @@ export const openapiHandler: Handler = (ctx) => {
8686 );
8787 }
8888 const role = roleOf(ctx.auth);
89 const hit = tag === null ? openapiText(ctx.url.origin, running().version, role) : openapiSliceText(ctx.url.origin, running().version, tag, role);
89 const hit = tag === null ? openapiText(ctx.url.origin, announcedOr(), role) : openapiSliceText(ctx.url.origin, announcedOr(), tag, role);
9090 // The document depends on who asks: a shared cache keeps only the anonymous one.
9191 const headers = {
9292 "cache-control": role === "anonymous" ? "public, max-age=300" : "private, max-age=300",
src/core/mcp_card.ts +11 −5
@@ -8,7 +8,7 @@
88 */
99 import type { Database } from "bun:sqlite";
1010 import { claudeInstall, opencodeInstall, pluginSource } from "./plugin_install.ts";
11 import { running, type Running } from "../kernel/version.ts";
11 import { announcedVersion, running, type Running } from "../kernel/version.ts";
1212 import { forgeSource } from "../settings/forge_source.ts";
1313 import { repoVisibility } from "./repos.ts";
1414 import { CARD_OF_TOOL, CARD_URI } from "../web/studio/cards.ts";
@@ -203,6 +203,12 @@ export function setCardTools(tools: readonly { name: string; description: string
203203 /** What the cards name as tools, as one string: a cached body is made again when it changes. */
204204 export const toolsKey = (ssh: boolean): string => shownTools(ssh).map((t) => t.name).join(",");
205205
206 /** `version` when the build names one; omitted otherwise, never "dev" (#15363). */
207 const versionField = (now: Running): { version?: string } => {
208 const v = announcedVersion(now);
209 return v === null ? {} : { version: v };
210 };
211
206212 /**
outdated

This helper sits between agentCard's docblock (lines above) and agentCard, so the agentCard description now attaches to versionField. Move versionField above that docblock so each comment documents its own function.

207213 * The agent card (A2A, protocol 0.3.0, the stable subset: name, description,
208214 * url, version, protocolVersion, capabilities, default modes, skills; the
@@ -217,7 +223,7 @@ export function agentCard(origin: string, ssh: boolean, now: Running = running()
217223 description: "A forge: repositories, issues, pulls and a crew of agents that build apps. Steer it through its MCP endpoint, signing in with OAuth.",
218224 url,
219225 preferredTransport: "JSONRPC",
220 version: now.version,
226 ...versionField(now),
221227 documentationUrl: `${origin}${DISCOVERY.docs}`,
222228 capabilities: { streaming: false, pushNotifications: false },
223229 securitySchemes: { oauth: { type: "openIdConnect", openIdConnectUrl: `${origin}/.well-known/openid-configuration` } },
@@ -266,7 +272,7 @@ export function mcpCard(origin: string, repo: string | undefined, ssh: boolean,
266272 const { url, oauth } = mcpPointers(origin);
267273 return {
268274 name: "forge",
269 version: now.version,
275 ...versionField(now),
270276 commit: now.commit,
271277 endpoint: url,
272278 transport: "streamable-http",
@@ -293,7 +299,7 @@ export function mcpCard(origin: string, repo: string | undefined, ssh: boolean,
293299 export function mcpDoor(origin: string, ssh: boolean, now: Running = running()) {
294300 return {
295301 name: "forge",
296 version: now.version,
302 ...versionField(now),
297303 mcp: mcpPointers(origin).url,
298304 oauth: {
299305 authorization_endpoint: `${origin}${OAUTH_ENDPOINTS.authorize}`,
@@ -315,7 +321,7 @@ export function serverCard(origin: string, scopes: readonly string[], now: Runni
315321 const pr = protectedResource(origin, scopes);
316322 return {
317323 name: "forge",
318 version: now.version,
324 ...versionField(now),
319325 endpoint: pr.resource,
320326 transport: "streamable-http",
321327 authorization: {
src/http/mcp.ts +5 −2
@@ -23,7 +23,7 @@ import { getRepo } from "../core/repos.ts";
2323 import { scopeAllows } from "../core/tokens.ts";
2424 import type { User } from "../core/users.ts";
2525 import type { Ctx, Handler } from "./context.ts";
26 import { running } from "../kernel/version.ts";
26 import { announcedVersion } from "../kernel/version.ts";
2727 import { bearerChallenge } from "./oauth.ts";
2828 import { BodyTooLarge, json } from "./respond.ts";
2929 import { bodyCapFor, readBounded } from "./limits.ts";
@@ -92,7 +92,10 @@ export const roleHere = (ctx: Ctx, user: User): Role =>
9292 user.kind === "user" ? roleOf(ctx.app.db, user) : "member";
9393
9494 /** Who answers: the forge, at the version its build stamped. */
95 const server = () => ({ name: "forge", version: running().version });
95 const server = () => {
96 const version = announcedVersion();
97 return version === null ? { name: "forge" } : { name: "forge", version };
98 };
9699
97100 /** The role a token acts as, and for a guest what is listed and how to reach the rest. */
98101 const roleNote = (role: Role): string =>
src/kernel/version.ts +15
@@ -66,3 +66,18 @@ const RELEASE = /^\d+\.\d+\.\d+$/;
6666 export function releaseOf(r: Running = running()): string | null {
6767 return RELEASE.test(r.version) ? r.version : null;
6868 }
69
70 /**
71 * The version a probe is told (#15363): the stamp when the build has one, else the short commit,
72 * else null (the caller omits `version`). Never the word `dev`.
73 */
74 export function announcedVersion(r: Running = running()): string | null {
75 if (r.version !== UNSTAMPED) return r.version;
76 return r.commit === null ? null : shortOf(r.commit);
77 }
78
79 /**
80 * The same for a field that must be a string (openapi `info.version`): `unreleased` when nothing is
81 * known.
82 */
83 export const announcedOr = (r: Running = running()): string => announcedVersion(r) ?? "unreleased";
src/tui/screens/api.ts +2 −2
@@ -9,7 +9,7 @@
99 import { narrow, reference, runnable, type Area, type Operation } from "../../contract/reference.ts";
1010 import { openapiText, roleOf } from "../../contract/served.ts";
1111 import { createSession, destroySession } from "../../core/sessions.ts";
12 import { running } from "../../kernel/version.ts";
12 import { announcedOr } from "../../kernel/version.ts";
1313 import type { Ctx, Screen } from "../app/app.ts";
1414 import { binding } from "../app/keys.ts";
1515 import type { Session } from "../session.ts";
@@ -95,7 +95,7 @@ export function apiScreen(f: Session, ctx: Ctx): Screen {
9595 const state = new ListState();
9696 const filter = new Filter();
9797 // The rows this person may call, as the page cuts them: a guest reads the anonymous ones (#11286).
98 const doc = openapiText(f.app.config.url ?? "http://localhost", running().version, roleOf(f));
98 const doc = openapiText(f.app.config.url ?? "http://localhost", announcedOr(), roleOf(f));
9999 const all = apiOperations(reference(JSON.parse(doc.text)));
100100 const shown = (): Operation[] => apiOperations(narrow([{ name: "", operations: all }], filter.query)).slice(0, MAX_SHOWN);
101101 let note = "";
src/web/pages/api.ts +2 −2
@@ -16,7 +16,7 @@ import { cappedQuery } from "../../core/query_limit.ts";
1616 import { canEnterApp } from "../../core/repos.ts";
1717 import type { Ctx } from "../../http/context.ts";
1818 import { noRoute, prefersJson } from "../../http/respond.ts";
19 import { running } from "../../kernel/version.ts";
19 import { announcedOr } from "../../kernel/version.ts";
2020 import { API_TRY_JS, referenceBody } from "../api_reference.ts";
2121 import { loadRepo, notFoundPage, repoBase, repoHeader } from "../chrome.ts";
2222 import { html } from "../html.ts";
@@ -32,7 +32,7 @@ const count = (areas: readonly Area[]): number => areas.reduce((n, a) => n + a.o
3232 const forgeAreas = (() => {
3333 const read = new Map<Role, { tag: string; areas: Area[] }>();
3434 return (origin: string, role: Role): Area[] => {
35 const hit = openapiText(origin, running().version, role);
35 const hit = openapiText(origin, announcedOr(), role);
3636 let held = read.get(role);
3737 if (held?.tag !== hit.etag) {
3838 held = { tag: hit.etag, areas: reference(JSON.parse(hit.text)) };
src/web/standards.ts +3 −3
@@ -197,14 +197,14 @@ export async function mcpDoorJson(ctx: Ctx): Promise<Response> {
197197 await loadMcp();
198198 const now = running();
199199 const ssh = sshOn(ctx.app.db);
200 return discovery(ctx, "mcp-door", JSON.stringify([now.version, toolsKey(ssh)]), () => mcpDoor(ctx.url.origin, ssh, now), "application/json", "public, max-age=300");
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");
201201 }
202202
203203 /** GET /.well-known/mcp/server-card.json — the small server card (a draft; see `serverCard`).
204204 * Public, the same for every reader. */
205205 export function serverCardJson(ctx: Ctx): Response {
206206 const now = running();
207 return discovery(ctx, "server-card", JSON.stringify([now.version]), () => serverCard(ctx.url.origin, OAUTH_SCOPES, now), "application/json", "public, max-age=3600", true);
207 return discovery(ctx, "server-card", JSON.stringify([now.version, now.commit]), () => serverCard(ctx.url.origin, OAUTH_SCOPES, now), "application/json", "public, max-age=3600", true);
208208 }
209209
210210 /**
@@ -217,7 +217,7 @@ export async function agentCardJson(ctx: Ctx): Promise<Response> {
217217 // The same reader test /llms.txt uses, so the two agree on who sees the full list.
218218 const signedIn = ctx.auth.user !== undefined;
219219 const ssh = sshOn(ctx.app.db);
220 return discovery(ctx, `agent-card ${signedIn}`, JSON.stringify([now.version, toolsKey(ssh)]), () => agentCard(ctx.url.origin, ssh, now, signedIn), "application/json", signedIn ? "private, max-age=3600" : "public, max-age=3600", true, "Cookie, Authorization");
220 return discovery(ctx, `agent-card ${signedIn}`, JSON.stringify([now.version, now.commit, toolsKey(ssh)]), () => agentCard(ctx.url.origin, ssh, now, signedIn), "application/json", signedIn ? "private, max-age=3600" : "public, max-age=3600", true, "Cookie, Authorization");
221221 }
222222
223223 /**
test/mcp-card.test.ts +2 −2
@@ -6,7 +6,7 @@ import { join } from "node:path";
66 import { createApp, type App } from "../src/app.ts";
77 import { serve, type Servers } from "../src/http/server.ts";
88 import { mcpCard, TOKEN_FREE_TOOLS } from "../src/core/mcp_card.ts";
9 import { running } from "../src/kernel/version.ts";
9 import { announcedVersion, running } from "../src/kernel/version.ts";
1010
1111 describe("the MCP server card", () => {
1212 let dataDir: string;
@@ -39,7 +39,7 @@ describe("the MCP server card", () => {
3939 expect(res.headers.get("access-control-allow-origin")).toBe("*");
4040 const card = (await res.json()) as any;
4141 expect(card.name).toBe("forge");
42 expect(card.version).toBe(running().version);
42 expect(card.version).toBe(announcedVersion() ?? undefined);
4343 expect(card.transport).toBe("streamable-http");
4444 expect(card.endpoint).toBe(`${base}/mcp`);
4545 expect(card.tokenFreeTools).toEqual([...TOKEN_FREE_TOOLS]);
test/mcp-door.test.ts +2 −2
@@ -8,7 +8,7 @@ import { serve, type Servers } from "../src/http/server.ts";
88 import { TOOLS } from "../src/http/mcp/tools.ts";
99 import { OFFER_TOOL, REPORT_TOOL, START_TOOL } from "../src/http/mcp.ts";
1010 import { sshOn } from "../src/settings/ssh.ts";
11 import { running } from "../src/kernel/version.ts";
11 import { announcedVersion } from "../src/kernel/version.ts";
1212
1313 let dataDir: string;
1414 let servers: Servers;
@@ -35,7 +35,7 @@ test("answers the door, cached five minutes, with the security floor", async ()
3535 expect(res.headers.get("content-security-policy")).toBeTruthy();
3636 const door = (await res.json()) as any;
3737 expect(door.name).toBe("forge");
38 expect(door.version).toBe(running().version);
38 expect(door.version).toBe(announcedVersion() ?? undefined);
3939 expect(door.mcp).toBe(`${base}/mcp`);
4040 });
4141
test/mcp-server-card.test.ts +2 −1
@@ -7,6 +7,7 @@ import { join } from "node:path";
77 import { createApp } from "../src/app.ts";
88 import { serve, type Servers } from "../src/http/server.ts";
99 import { TOKEN_FREE_TOOLS } from "../src/core/mcp_card.ts";
10 import { announcedVersion } from "../src/kernel/version.ts";
1011
1112 let dataDir: string;
1213 let servers: Servers;
@@ -30,7 +31,7 @@ test("answers 200 JSON, public and cached, with name, version, endpoint and the
3031 expect(res.headers.get("cache-control")).toBe("public, max-age=3600");
3132 const card = (await res.json()) as any;
3233 expect(card.name).toBe("forge");
33 expect(typeof card.version).toBe("string");
34 expect(card.version).toBe(announcedVersion() ?? undefined);
3435 expect(card.endpoint).toBe(`${base}/mcp`);
3536 const pr = (await (await fetch(card.authorization.protectedResourceMetadata)).json()) as any;
3637 expect(card.authorization.authorization_servers).toEqual(pr.authorization_servers);
test/mcp-version.test.ts added +71
@@ -0,0 +1,71 @@
1 /**
2 * The MCP initialize answer, /.well-known/mcp and the openapi info.version name the release, never
3 * "dev" (#15363).
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
12 let dataDir: string;
13 let servers: Servers;
14 let base: string;
15 const saved = { v: process.env["FORGE_VERSION"], c: process.env["FORGE_COMMIT"] };
16
17 beforeAll(async () => {
18 dataDir = await mkdtemp(join(tmpdir(), "forge-mcp-version-"));
19 servers = await serve(createApp({ dataDir, port: 0 }));
20 base = servers.url;
21 });
22 afterAll(async () => {
23 for (const [k, v] of [["FORGE_VERSION", saved.v], ["FORGE_COMMIT", saved.c]] as const) {
24 if (v === undefined) delete process.env[k];
25 else process.env[k] = v;
26 }
27 await servers.stop?.();
28 await rm(dataDir, { recursive: true, force: true });
29 });
30
31 async function answers() {
32 const init = await fetch(base + "/mcp", {
33 method: "POST",
34 headers: { "content-type": "application/json", accept: "application/json, text/event-stream" },
35 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "t", version: "1" } } }),
36 });
37 const text = await init.text();
38 const data = text.includes("data:") ? text.split("\n").find((l) => l.startsWith("data:"))!.slice(5) : text;
39 const serverInfo = JSON.parse(data).result.serverInfo;
40 const door = (await (await fetch(base + "/.well-known/mcp")).json()) as any;
41 const spec = (await (await fetch(base + "/openapi.json")).json()) as any;
42 return { serverInfo, door, spec, raw: JSON.stringify([serverInfo, door, spec.info]) };
43 }
44
45 test("a stamped build names its release in all three", async () => {
46 process.env["FORGE_VERSION"] = "v1.2.3";
47 process.env["FORGE_COMMIT"] = "abcdef0123456789";
48 const a = await answers();
49 expect(a.serverInfo.version).toBe("1.2.3");
50 expect(a.door.version).toBe("1.2.3");
51 expect(a.spec.info.version).toBe("1.2.3");
52 expect(a.raw).not.toContain('"dev"');
53 });
54
55 test("an unstamped build answers the short commit, and omits version when there is none", async () => {
56 delete process.env["FORGE_VERSION"];
57 process.env["FORGE_COMMIT"] = "abcdef0123456789";
58 const a = await answers();
59 expect(a.serverInfo.version).toBe("abcdef0");
60 expect(a.door.version).toBe("abcdef0");
61 expect(a.spec.info.version).toBe("abcdef0");
62 expect(a.raw).not.toContain('"dev"');
63
64 delete process.env["FORGE_COMMIT"];
65 delete process.env["FORGE_APP_COMMIT"];
66 const b = await answers();
67 expect(b.serverInfo.version).toBeUndefined();
68 expect(b.door.version).toBeUndefined();
69 expect(b.spec.info.version).toBe("unreleased");
70 expect(b.raw).not.toContain('"dev"');
71 });
test/version.test.ts +2 −2
@@ -326,7 +326,7 @@ describe("where the stamp is read", () => {
326326 expect(page).not.toContain("reduced-protection");
327327 });
328328
329 test("with no stamp every one of them says dev", async () => {
329 test("with no stamp every one of them says dev, but the MCP door omits it", async () => {
330330 stamp();
331331 try {
332332 const health = (await (
@@ -338,7 +338,7 @@ describe("where the stamp is read", () => {
338338 capabilities: {},
339339 clientInfo: { name: "test", version: "0" },
340340 });
341 expect(init.serverInfo.version).toBe("dev");
341 expect(init.serverInfo.version).toBeUndefined();
342342 } finally {
343343 stamp("9.8.7", COMMIT);
344344 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs