Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(mcp): support trusted browser probes

Rahman73257773af86
diff --git a/.env.example b/.env.example
index a4d5982b..cc39a04e 100644
--- a/.env.example
+++ b/.env.example
@@ -306,6 +306,11 @@ OS_SESSION_SECRET=
# Where clients/codes/tokens live. Default ~/.mso/mcp.json (0600). Only sha256 of
# each code and token is ever written.
# OS_MCP_STORE=/home/you/.mso/mcp.json
+# Optional comma-separated browser origins allowed to call the PUBLIC MCP origin
+# with CORS. ChatGPT web origins are built in; server-to-server MCP clients omit
+# Origin and need no entry. Exact origins only; this never weakens loopback/DNS-
+# rebinding protection. Example: https://claude.example,https://cursor.example
+# OS_MCP_BROWSER_ORIGINS=
# Persistent semantic skill/recipe memory. The default is ~/.mso/skill-memory.json
# (0600). Embeddings are deterministic and local — no API key, model download or
# network call is required.
diff --git a/CLAUDE.md b/CLAUDE.md
index 0519b392..5c1e8bdd 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -348,7 +348,7 @@ the real runtime and working analogue before changing a tool or skill contract.
it AND `tools/call` re-checks it — a client can call a name it was never shown.
- **Tool names are an MSO public API contract.** Keep global names MSO-owned and generic.
Project-owned MCP names are data behind `project_mcp_tools` / `project_mcp_call`; never copy them into the global catalog.
- <!-- mcp-toolset: server=1.7.1 version=2026.09.03.4 tools=72 read=34 write=24 exec=14 -->
+ <!-- mcp-toolset: server=1.7.2 version=2026.09.03.4 tools=72 read=34 write=24 exec=14 -->
The full MSO transport exposes **73 tools**: **72 model/operator tools** (34 read, 24 write, 14 exec) plus app-only `workflow_status`.
ChatGPT receives a deliberately smaller static profile; hidden full-catalog names are rejected at call time, not merely omitted from `tools/list`.
- Store is `~/.mso/mcp.json`, **sha256 only**, same atomic-write + fail-loud-on-corrupt
diff --git a/app/.well-known/oauth-authorization-server/route.ts b/app/.well-known/oauth-authorization-server/route.ts
index 018f4942..33f4210d 100644
--- a/app/.well-known/oauth-authorization-server/route.ts
+++ b/app/.well-known/oauth-authorization-server/route.ts
@@ -7,6 +7,17 @@ import { mcpEnabled } from "@/lib/mcp/scope";
// uses a user-defined client and never touches /oauth/register.
export const runtime = "nodejs";
+const PUBLIC_CORS = {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Methods": "GET, OPTIONS",
+ "Access-Control-Allow-Headers": "Content-Type, Authorization",
+ "Access-Control-Max-Age": "86400",
+};
+
+export async function OPTIONS() {
+ return new Response(null, { status: 204, headers: PUBLIC_CORS });
+}
+
export async function GET(req: Request) {
if (!mcpEnabled()) return new Response("Not Found", { status: 404 });
const origin = publicOrigin(req);
@@ -23,6 +34,6 @@ export async function GET(req: Request) {
scopes_supported: ["read", "write", "exec", "offline_access"],
authorization_response_iss_parameter_supported: true,
},
- { headers: { "cache-control": "public, max-age=3600" } },
+ { headers: { ...PUBLIC_CORS, "cache-control": "public, max-age=3600" } },
);
}
diff --git a/app/.well-known/oauth-protected-resource/route.ts b/app/.well-known/oauth-protected-resource/route.ts
index a3315f49..68f017d9 100644
--- a/app/.well-known/oauth-protected-resource/route.ts
+++ b/app/.well-known/oauth-protected-resource/route.ts
@@ -7,6 +7,17 @@ import { mcpEnabled } from "@/lib/mcp/scope";
// what produces "MCP server does not implement OAuth" with no further detail.
export const runtime = "nodejs";
+const PUBLIC_CORS = {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Methods": "GET, OPTIONS",
+ "Access-Control-Allow-Headers": "Content-Type, Authorization",
+ "Access-Control-Max-Age": "86400",
+};
+
+export async function OPTIONS() {
+ return new Response(null, { status: 204, headers: PUBLIC_CORS });
+}
+
export async function GET(req: Request) {
if (!mcpEnabled()) return new Response("Not Found", { status: 404 });
const origin = publicOrigin(req);
@@ -17,6 +28,6 @@ export async function GET(req: Request) {
scopes_supported: ["read", "write", "exec", "offline_access"],
bearer_methods_supported: ["header"],
},
- { headers: { "cache-control": "public, max-age=3600" } },
+ { headers: { ...PUBLIC_CORS, "cache-control": "public, max-age=3600" } },
);
}
diff --git a/app/mcp/route.test.ts b/app/mcp/route.test.ts
index 41b155b4..6e0278e4 100644
--- a/app/mcp/route.test.ts
+++ b/app/mcp/route.test.ts
@@ -9,6 +9,7 @@ const mocks = vi.hoisted(() => ({
rateLimited: vi.fn(() => false),
rateLimitedUntrusted: vi.fn(() => false),
mcpRequestOriginAllowed: vi.fn(() => true),
+ mcpCorsHeaders: vi.fn(() => ({ "Access-Control-Allow-Origin": "https://chatgpt.com", Vary: "Origin" })),
findOrCreateAgentSessionForConversation: vi.fn(),
}));
@@ -35,6 +36,7 @@ vi.mock("@/lib/mcp/origin", () => ({
publicOrigin: () => "https://mso.example.test",
clientIp: () => "127.0.0.1",
mcpRequestOriginAllowed: mocks.mcpRequestOriginAllowed,
+ mcpCorsHeaders: mocks.mcpCorsHeaders,
}));
vi.mock("@/lib/host", () => ({
rateLimited: mocks.rateLimited,
@@ -70,10 +72,19 @@ describe("/mcp request boundary", () => {
mocks.rateLimited.mockClear().mockReturnValue(false);
mocks.rateLimitedUntrusted.mockClear().mockReturnValue(false);
mocks.mcpRequestOriginAllowed.mockClear().mockReturnValue(true);
+ mocks.mcpCorsHeaders.mockClear().mockReturnValue({ "Access-Control-Allow-Origin": "https://chatgpt.com", Vary: "Origin" });
mocks.findOrCreateAgentSessionForConversation.mockReset().mockResolvedValue({ id: "20260901_100000_aabbccdd", source: "mcp" });
});
afterEach(() => vi.unstubAllEnvs());
+ it("answers trusted browser preflight with the MCP authorization headers", async () => {
+ const { OPTIONS } = await import("./route");
+ const res = await OPTIONS(new Request("https://mso.example.test/mcp", { method: "OPTIONS", headers: { origin: "https://chatgpt.com" } }));
+ expect(res.status).toBe(204);
+ expect(res.headers.get("access-control-allow-origin")).toBe("https://chatgpt.com");
+ expect(mocks.mcpRequestOriginAllowed).toHaveBeenCalledOnce();
+ });
+
it("rejects a browser Origin that fails the Streamable HTTP boundary before auth", async () => {
mocks.mcpRequestOriginAllowed.mockReturnValueOnce(false);
const getReader = vi.fn(() => { throw new Error("body must not be read"); });
diff --git a/app/mcp/route.ts b/app/mcp/route.ts
index e2a8f455..a947b864 100644
--- a/app/mcp/route.ts
+++ b/app/mcp/route.ts
@@ -1,7 +1,7 @@
import { dispatch, isNotification, rpcError, UNAUTHORIZED, RATE_LIMITED, type RpcRequest } from "@/lib/mcp/dispatch";
import { getClient, validateToken, touchToken } from "@/lib/mcp/store";
import { clampScope, mcpEnabled } from "@/lib/mcp/scope";
-import { publicOrigin, clientIp, mcpRequestOriginAllowed } from "@/lib/mcp/origin";
+import { publicOrigin, clientIp, mcpCorsHeaders, mcpRequestOriginAllowed } from "@/lib/mcp/origin";
import { rateLimited, rateLimitedUntrusted } from "@/lib/host";
import { TOOLS } from "@/lib/mcp/tools";
import { toolsetInfo } from "@/lib/mcp/toolset";
@@ -19,6 +19,8 @@ const PREAUTH_PER_MIN = 240;
export const MAX_MCP_BODY_BYTES = 2 * 1024 * 1024;
class BodyTooLarge extends Error {}
+const responseHeaders = (req: Request, headers: Record<string, string> = {}) => ({ ...mcpCorsHeaders(req), ...headers });
+
async function parseBoundedJson(req: Request): Promise<unknown> {
const rawLength = req.headers.get("content-length");
if (rawLength) {
@@ -44,11 +46,11 @@ async function parseBoundedJson(req: Request): Promise<unknown> {
export async function POST(req: Request) {
const origin = publicOrigin(req);
const challenge = `Bearer realm="mso", resource_metadata="${origin}/.well-known/oauth-protected-resource"`;
- const unauthorized = (msg: string) => Response.json(rpcError(null, UNAUTHORIZED, msg), { status: 401, headers: { "WWW-Authenticate": challenge } });
+ const unauthorized = (msg: string) => Response.json(rpcError(null, UNAUTHORIZED, msg), { status: 401, headers: responseHeaders(req, { "WWW-Authenticate": challenge }) });
if (!mcpEnabled()) return new Response("Not Found", { status: 404 });
if (!mcpRequestOriginAllowed(req)) return Response.json({ error: "forbidden_origin" }, { status: 403, headers: { "Cache-Control": "no-store" } });
if (rateLimitedUntrusted(`mcp:ip:${clientIp(req)}`, PREAUTH_PER_MIN, 60_000)) {
- return Response.json(rpcError(null, RATE_LIMITED, "rate limited"), { status: 429, headers: { "Retry-After": "60" } });
+ return Response.json(rpcError(null, RATE_LIMITED, "rate limited"), { status: 429, headers: responseHeaders(req, { "Retry-After": "60" }) });
}
const bearer = (req.headers.get("authorization") ?? "").replace(/^Bearer\s+/i, "").trim();
@@ -57,23 +59,23 @@ export async function POST(req: Request) {
if (!token) return unauthorized("invalid, revoked or expired MCP token");
const effectiveScope = clampScope(token.scope);
if (rateLimited(`mcp:tok:${token.hash}`, CALLS_PER_MIN, 60_000)) {
- return Response.json(rpcError(null, RATE_LIMITED, "rate limited — retry in 60s"), { status: 429, headers: { "Retry-After": "60" } });
+ return Response.json(rpcError(null, RATE_LIMITED, "rate limited — retry in 60s"), { status: 429, headers: responseHeaders(req, { "Retry-After": "60" }) });
}
if (rateLimited(`mcp:day:${token.hash}`, CALLS_PER_DAY, 86_400_000)) {
- return Response.json(rpcError(null, RATE_LIMITED, "daily call limit reached for this token"), { status: 429, headers: { "Retry-After": "3600" } });
+ return Response.json(rpcError(null, RATE_LIMITED, "daily call limit reached for this token"), { status: 429, headers: responseHeaders(req, { "Retry-After": "3600" }) });
}
let body: unknown;
try { body = await parseBoundedJson(req); }
catch (error) {
- if (error instanceof BodyTooLarge) return Response.json({ jsonrpc: "2.0", id: null, error: { code: -32600, message: "request body too large" } }, { status: 413, headers: { "Cache-Control": "no-store" } });
- return Response.json({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "parse error" } }, { status: 400 });
+ if (error instanceof BodyTooLarge) return Response.json({ jsonrpc: "2.0", id: null, error: { code: -32600, message: "request body too large" } }, { status: 413, headers: responseHeaders(req, { "Cache-Control": "no-store" }) });
+ return Response.json({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "parse error" } }, { status: 400, headers: responseHeaders(req) });
}
const rpc = body as RpcRequest;
const protocolHeader = (req.headers.get("mcp-protocol-version") ?? "").trim();
if (rpc.method !== "initialize" && protocolHeader && !supportedMcpProtocol(protocolHeader)) {
- return Response.json({ jsonrpc: "2.0", id: rpc.id ?? null, error: { code: -32600, message: "unsupported MCP-Protocol-Version" } }, { status: 400, headers: { "Cache-Control": "no-store" } });
+ return Response.json({ jsonrpc: "2.0", id: rpc.id ?? null, error: { code: -32600, message: "unsupported MCP-Protocol-Version" } }, { status: 400, headers: responseHeaders(req, { "Cache-Control": "no-store" }) });
}
const principal = token.clientId ? `mcp-client:${token.clientId}` : `mcp-token:${token.hash}`;
const expectedResource = `${origin}/mcp`;
@@ -82,7 +84,7 @@ export async function POST(req: Request) {
const toolProfile = token.profile ?? client?.profile ?? detectMcpToolProfile({ clientId: token.clientId, name: client?.name, redirectUris: client?.redirectUris });
const resolved = await resolveMcpSession(req, rpc, principal, token.label);
if ("response" in resolved) return resolved.response;
- const headers = mcpSessionHeaders(resolved.responseSessionId);
+ const headers = responseHeaders(req, mcpSessionHeaders(resolved.responseSessionId));
if (isNotification(body)) return new Response(null, { status: 202, headers });
void touchToken(token.hash).catch(() => {});
@@ -99,7 +101,7 @@ export async function GET(req: Request) {
// one for its bounded request/response model, so the standards-compliant answer
// is 405 rather than a JSON diagnostics document masquerading as SSE.
if ((req.headers.get("accept") ?? "").toLowerCase().includes("text/event-stream")) {
- return new Response(null, { status: 405, headers: { Allow: "POST", "Cache-Control": "no-store" } });
+ return new Response(null, { status: 405, headers: responseHeaders(req, { Allow: "POST", "Cache-Control": "no-store" }) });
}
const full = toolsetInfo(TOOLS, undefined, "full");
const chatgptTools = visibleToolsForProfile(TOOLS, "exec", "chatgpt");
@@ -107,7 +109,13 @@ export async function GET(req: Request) {
name: "mso MCP", transport: "streamable-http", auth: "OAuth 2.1 + PKCE + resource binding",
sessions: "ChatGPT conversations bind through hashed _meta[openai/session]; Mcp-Session-Id is legacy transport compatibility only",
authorization_servers: [publicOrigin(req)], toolset: full, chatgptToolset: toolsetInfo(chatgptTools, "exec", "chatgpt"),
- }, { headers: { "Cache-Control": "no-store" } });
+ }, { headers: responseHeaders(req, { "Cache-Control": "no-store" }) });
+}
+
+export async function OPTIONS(req: Request) {
+ if (!mcpEnabled()) return new Response("Not Found", { status: 404 });
+ if (!mcpRequestOriginAllowed(req)) return Response.json({ error: "forbidden_origin" }, { status: 403, headers: { "Cache-Control": "no-store" } });
+ return new Response(null, { status: 204, headers: responseHeaders(req, { Allow: "POST, GET, OPTIONS" }) });
}
export async function DELETE() {
diff --git a/app/oauth/register/route.ts b/app/oauth/register/route.ts
index bb139e07..a032c33a 100644
--- a/app/oauth/register/route.ts
+++ b/app/oauth/register/route.ts
@@ -10,13 +10,24 @@ import { rateLimitedUntrusted } from "@/lib/host";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
+const DCR_CORS = {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
+ "Access-Control-Allow-Headers": "Content-Type",
+ "Access-Control-Max-Age": "86400",
+};
+
const bad = (error: string, description: string, status = 400) =>
- Response.json({ error, error_description: description }, { status, headers: { "Cache-Control": "no-store" } });
+ Response.json({ error, error_description: description }, { status, headers: { ...DCR_CORS, "Cache-Control": "no-store" } });
+
+export async function OPTIONS() {
+ return new Response(null, { status: 204, headers: DCR_CORS });
+}
export async function POST(req: Request) {
if (!mcpEnabled()) return new Response("Not Found", { status: 404 });
if (rateLimitedUntrusted(`mcp:dcr:${clientIp(req)}`, 10, 3_600_000)) {
- return Response.json({ error: "rate_limited" }, { status: 429, headers: { "Retry-After": "3600" } });
+ return Response.json({ error: "rate_limited" }, { status: 429, headers: { ...DCR_CORS, "Retry-After": "3600" } });
}
let body: { redirect_uris?: unknown; client_name?: unknown };
@@ -47,6 +58,6 @@ export async function POST(req: Request) {
grant_types: ["authorization_code", "refresh_token"],
response_types: ["code"],
},
- { status: 201, headers: { "Cache-Control": "no-store" } },
+ { status: 201, headers: { ...DCR_CORS, "Cache-Control": "no-store" } },
);
}
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 414c1984..f3b8609a 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -160,7 +160,7 @@ park a visible Approve/Deny card. The complete semantic contract is
**MCP** is for external clients such as ChatGPT, Claude.ai and Cursor. Its catalog lives in
`lib/mcp/`; access is controlled by the OAuth token scope rather than Alfa approval cards.
-<!-- mcp-toolset: server=1.7.1 version=2026.09.03.4 tools=72 read=34 write=24 exec=14 -->
+<!-- mcp-toolset: server=1.7.2 version=2026.09.03.4 tools=72 read=34 write=24 exec=14 -->
The full transport exposes **73 tools**: **72 model/operator tools** (34 read, 24 write, 14 exec) plus app-only `workflow_status`. ChatGPT gets a compact client profile rather than the full set. Project function/MCP names remain data behind `project_capabilities`, `project_function_call`, `project_mcp_tools`, and `project_mcp_call`; they never rewrite the global tool prefix. `GET /mcp` reports both full and ChatGPT signatures.
See `docs/MCP.md` for protocol/security internals, `docs/A2A.md` for peer-agent delegation, and `docs/CHATGPT-PLUGIN.md` for the
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 9b664a85..6ee1f33f 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -12,6 +12,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `mcp` support trusted browser probes
- `oauth` issue distinct dynamic client ids
- `mcp` make read pipeline schema portable
diff --git a/docs/CHATGPT-PLUGIN.md b/docs/CHATGPT-PLUGIN.md
index 0865f346..789c282d 100644
--- a/docs/CHATGPT-PLUGIN.md
+++ b/docs/CHATGPT-PLUGIN.md
@@ -4,9 +4,11 @@
>
> ChatGPT's Developer Mode/App UI can change independently of MSO. Use the current OpenAI MCP/App documentation for exact menu labels, and use MSO Settings → MCP / `GET /mcp` for the live server/profile signatures.
-<!-- mcp-chatgpt-profile: server=1.7.1 version=2026.09.03.4 tools=28 read=14 write=8 exec=6 app-only=1 total=29 -->
+<!-- mcp-chatgpt-profile: server=1.7.2 version=2026.09.03.4 tools=28 read=14 write=8 exec=6 app-only=1 total=29 -->
-MSO server **1.7.1**, toolset **2026.09.03.4** exposes a full generic catalog for MCP clients, but a registered ChatGPT client receives only **29 transport tools**: **28 model/operator tools** (14 read, 8 write, 6 exec) plus app-only `workflow_status`.
+MSO server **1.7.2**, toolset **2026.09.03.4** exposes a full generic catalog for MCP clients, but a registered ChatGPT client receives only **29 transport tools**: **28 model/operator tools** (14 read, 8 write, 6 exec) plus app-only `workflow_status`.
+
+Browser-hosted MCP probes from ChatGPT are allowed only when they target the configured public `OS_PUBLIC_ORIGIN`; arbitrary origins and ChatGPT-origin requests aimed at loopback remain denied. Additional trusted browser hosts can be added explicitly with comma-separated `OS_MCP_BROWSER_ORIGINS`. Public OAuth discovery and DCR responses carry CORS metadata; authenticated `/mcp` echoes only an approved exact origin.
The compact descriptor regression currently measures **31,908 JSON bytes** for all 29 ChatGPT tool definitions (roughly 8k tokens at a 4-byte/token estimate), with the largest individual descriptor **2,507 bytes**. CI keeps the profile below 40 KiB and each descriptor below 8 KiB. Bytes are the deterministic contract; token estimates vary by tokenizer.
diff --git a/docs/MCP.md b/docs/MCP.md
index 5a2aaa82..c944e17f 100644
--- a/docs/MCP.md
+++ b/docs/MCP.md
@@ -116,9 +116,9 @@ The catalog has a stable server version plus a schema-derived toolset signature.
Settings → MCP shows the current version/hash/count and stores a browser-local acknowledgement when the operator marks ChatGPT refreshed. A later signature change becomes an explicit stale-snapshot warning. This does not mutate ChatGPT remotely; it makes the required refresh visible instead of relying on memory.
-<!-- mcp-toolset: server=1.7.1 version=2026.09.03.4 tools=72 read=34 write=24 exec=14 -->
+<!-- mcp-toolset: server=1.7.2 version=2026.09.03.4 tools=72 read=34 write=24 exec=14 -->
-Current full transport catalog: **73 tools**, server `1.7.1` / toolset `2026.09.03.4`.
+Current full transport catalog: **73 tools**, server `1.7.2` / toolset `2026.09.03.4`.
The model/operator catalog is **72 tools** (34 read, 24 write, 14 exec); `workflow_status` is the one app-only MCP Apps bridge. ChatGPT receives a smaller client profile rather than this full set; see [`CHATGPT-PLUGIN.md`](./CHATGPT-PLUGIN.md).
`agent_memory_search` is the typed-memory retrieval surface. It resolves semantic/episodic/procedural claims at an optional point in time, returns confidence/provenance and competing effective claims, and can expose superseded/retracted history when explicitly requested. `agent_memory_remember` remains the write surface and now accepts typed metadata; raw ChatGPT conversation ids are never stored as provenance.
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index a61775d1..a480f11c 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -4,6 +4,7 @@ Running log of what shipped each phase. Newest at top.
## 2026-09-03 — OAuth DCR registration identity fix
+- **2026-09-03 — Browser MCP install compatibility:** comparison with the working CareerPack MCP showed that ChatGPT completed DCR + OAuth for MSO but the post-auth browser probe differed: CareerPack serves CORS preflight/metadata while MSO rejected `Origin: https://chatgpt.com` and returned OPTIONS without usable CORS headers. MCP server `1.7.2` now permits the exact ChatGPT browser origins only against the configured public MSO origin, keeps arbitrary/loopback-origin requests denied, adds explicit `/mcp` preflight headers, and adds public CORS to OAuth discovery/DCR. Toolset stays `2026.09.03.4` because no tool descriptor changed.
- **Fresh app means fresh OAuth client:** `POST /oauth/register` now mints a distinct RFC 7591 client id for every registration. Redirect URIs are client metadata, not identity; two ChatGPT dev apps sharing the same `chatgpt.com` callback no longer collapse onto an August-era client record.
- **Safe bounded store:** registration pruning removes only old client records that are not referenced by a live authorization code, access token, or refresh grant. Existing connectors/tokens remain valid. The DCR response now also reports `client_id_issued_at`.
- **Why this matters:** real ChatGPT testing showed a supposedly new app at 10:55 UTC receiving the historical `probe-chatgpt` client id solely because its redirect set matched. That defeated the purpose of a clean Scan Tools registration and could retain stale app identity server-side. MCP server patch version is 1.7.1; toolset remains 2026.09.03.4 because the advertised tool catalog did not change.
diff --git a/docs/TESTING-HANDOFF.md b/docs/TESTING-HANDOFF.md
index feb8295c..3db3cafc 100644
--- a/docs/TESTING-HANDOFF.md
+++ b/docs/TESTING-HANDOFF.md
@@ -4,7 +4,7 @@ Update this file at the end of every manual or automated test session. Keep it f
## Current status
-The current release target is **MSO CLI 1.12.0**, MCP server `1.7.1`, toolset `2026.09.03.4`; use `mso --version` plus `/api/health` for the exact Git build because documentation-only release commits also advance that identity. The v1.10/v1.11 findings and the v1.12 sectioned-terminal/recoverable-error work below are resolved and retained as historical test evidence. Do not re-open a resolved finding from prose alone: reproduce it against the current build first. There is no known 1.12 release blocker in this handoff.
+The current release target is **MSO CLI 1.12.0**, MCP server `1.7.2`, toolset `2026.09.03.4`; use `mso --version` plus `/api/health` for the exact Git build because documentation-only release commits also advance that identity. The v1.10/v1.11 findings and the v1.12 sectioned-terminal/recoverable-error work below are resolved and retained as historical test evidence. Do not re-open a resolved finding from prose alone: reproduce it against the current build first. There is no known 1.12 release blocker in this handoff.
Current verified behavior:
- MCP 1.7 release candidate: ChatGPT is fail-closed to a 29-tool compact MSO-only profile (~31.8 KiB descriptor JSON / ~8k rough tokens), full MSO remains 73 transport tools, and project-specific MCP names stay dynamic behind `project_mcp_tools` / `project_mcp_call`. OAuth resource binding + rotating refresh credentials, Streamable HTTP protocol handling, and legacy registered ChatGPT-client profile detection have focused regression coverage. Deterministic security gates (Trivy/OSV/Gitleaks/Semgrep/ShellCheck) pass; Codex Security AI scanning is explicitly incomplete because executor/cost guards stopped it, with 0 findings in the targeted partial reports.
@@ -29,7 +29,7 @@ Current verified behavior:
```text
You are taking over MSO testing work in /home/rahman/projects/mso.
-Read docs/TESTING-HANDOFF.md first. Current verified source baseline: CLI 1.12.0, MCP server 1.7.1, toolset 2026.09.03.4; resolve the exact live Git build from `mso --version`/`/api/health`. Preserve existing work and do not re-open resolved v1.10-v1.12 findings unless you can reproduce them against the current build.
+Read docs/TESTING-HANDOFF.md first. Current verified source baseline: CLI 1.12.0, MCP server 1.7.2, toolset 2026.09.03.4; resolve the exact live Git build from `mso --version`/`/api/health`. Preserve existing work and do not re-open resolved v1.10-v1.12 findings unless you can reproduce them against the current build.
For a new issue: record the exact reproduction, distinguish durable state from live receiver/process state, avoid duplicate write/exec retries when outcome is uncertain, add the smallest focused regression, run typecheck plus the relevant contract tests, then update this handoff with factual results.
```
diff --git a/lib/mcp/dispatch.test.ts b/lib/mcp/dispatch.test.ts
index 5a49ee54..eabdb266 100644
--- a/lib/mcp/dispatch.test.ts
+++ b/lib/mcp/dispatch.test.ts
@@ -46,7 +46,7 @@ describe("protocol", () => {
it("publishes server and toolset metadata so action drift is visible", async () => {
const r = await dispatch({ id: 1, method: "initialize" }, "exec");
const result = r.result as { serverInfo: { version: string }; _meta: { toolset: { toolCount: number; hash: string } } };
- expect(result.serverInfo.version).toBe("1.7.1");
+ expect(result.serverInfo.version).toBe("1.7.2");
expect(result._meta.toolset.toolCount).toBe(TOOLS.length);
expect(result._meta.toolset.hash).toMatch(/^[a-f0-9]{16}$/);
});
diff --git a/lib/mcp/origin.test.ts b/lib/mcp/origin.test.ts
index d88b977c..0acc57c7 100644
--- a/lib/mcp/origin.test.ts
+++ b/lib/mcp/origin.test.ts
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
-import { mcpRequestOriginAllowed, publicOrigin } from "./origin";
+import { mcpCorsHeaders, mcpRequestOriginAllowed, publicOrigin } from "./origin";
function req(url: string, headers: Record<string, string> = {}) {
return new Request(url, { headers });
@@ -23,6 +23,26 @@ describe("MCP public origin boundary", () => {
expect(mcpRequestOriginAllowed(req("https://mso.example.test/mcp", { origin: "https://mso.example.test", host: "mso.example.test" }))).toBe(true);
});
+ it("allows ChatGPT browser requests only against the configured public MCP origin", () => {
+ vi.stubEnv("OS_PUBLIC_ORIGIN", "https://mso.example.test");
+ const publicReq = req("https://mso.example.test/mcp", { origin: "https://chatgpt.com", host: "mso.example.test" });
+ expect(mcpRequestOriginAllowed(publicReq)).toBe(true);
+ expect(mcpCorsHeaders(publicReq)).toMatchObject({
+ "Access-Control-Allow-Origin": "https://chatgpt.com",
+ "Access-Control-Allow-Headers": expect.stringContaining("Authorization"),
+ Vary: "Origin",
+ });
+ const loopbackReq = req("http://127.0.0.1:4005/mcp", { origin: "https://chatgpt.com", host: "127.0.0.1:4005" });
+ expect(mcpRequestOriginAllowed(loopbackReq)).toBe(false);
+ });
+
+ it("supports exact operator-added browser origins without accepting suffix spoofing", () => {
+ vi.stubEnv("OS_PUBLIC_ORIGIN", "https://mso.example.test");
+ vi.stubEnv("OS_MCP_BROWSER_ORIGINS", "https://claude.example, https://cursor.example/path");
+ expect(mcpRequestOriginAllowed(req("https://mso.example.test/mcp", { origin: "https://claude.example", host: "mso.example.test" }))).toBe(true);
+ expect(mcpRequestOriginAllowed(req("https://mso.example.test/mcp", { origin: "https://evil.claude.example", host: "mso.example.test" }))).toBe(false);
+ });
+
it("keeps the Settings self-probe working on a loopback cockpit", () => {
vi.stubEnv("OS_PUBLIC_ORIGIN", "https://mso.example.test");
expect(mcpRequestOriginAllowed(req("http://127.0.0.1:4005/mcp", { origin: "http://127.0.0.1:4005", host: "127.0.0.1:4005" }))).toBe(true);
diff --git a/lib/mcp/origin.ts b/lib/mcp/origin.ts
index 02e5c462..64fd9801 100644
--- a/lib/mcp/origin.ts
+++ b/lib/mcp/origin.ts
@@ -21,6 +21,21 @@ function isLoopbackHostname(hostname: string): boolean {
return host === "localhost" || host === "::1" || host.startsWith("127.");
}
+const DEFAULT_MCP_BROWSER_ORIGINS = new Set([
+ "https://chatgpt.com",
+ "https://chat.openai.com",
+]);
+
+function configuredBrowserOrigins(): Set<string> {
+ const out = new Set(DEFAULT_MCP_BROWSER_ORIGINS);
+ for (const raw of (process.env.OS_MCP_BROWSER_ORIGINS ?? "").split(",")) {
+ const value = raw.trim();
+ if (!value) continue;
+ try { out.add(new URL(value).origin); } catch { /* ignore malformed operator entries */ }
+ }
+ return out;
+}
+
function requestHeaderOrigin(req: Request): string | null {
const url = new URL(req.url);
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0].trim() || url.protocol.replace(":", "");
@@ -54,6 +69,10 @@ export function mcpRequestOriginAllowed(req: Request): boolean {
if (explicit && supplied.origin === explicit) return true;
const requestOrigin = requestHeaderOrigin(req);
+ if (explicit && requestOrigin === explicit && configuredBrowserOrigins().has(supplied.origin)) {
+ const target = new URL(explicit);
+ if (!isLoopbackHostname(target.hostname)) return true;
+ }
if (requestOrigin) {
const target = new URL(requestOrigin);
if (isLoopbackHostname(target.hostname) && supplied.origin === requestOrigin) return true;
@@ -64,6 +83,22 @@ export function mcpRequestOriginAllowed(req: Request): boolean {
return false;
}
+
+export function mcpCorsHeaders(req: Request): Record<string, string> {
+ const raw = req.headers.get("origin");
+ if (!raw || !mcpRequestOriginAllowed(req)) return {};
+ let origin: string;
+ try { origin = new URL(raw).origin; } catch { return {}; }
+ return {
+ "Access-Control-Allow-Origin": origin,
+ "Access-Control-Allow-Methods": "POST, GET, OPTIONS",
+ "Access-Control-Allow-Headers": "Content-Type, Authorization, Mcp-Session-Id, MCP-Protocol-Version",
+ "Access-Control-Expose-Headers": "Mcp-Session-Id, WWW-Authenticate",
+ "Access-Control-Max-Age": "86400",
+ Vary: "Origin",
+ };
+}
+
export function publicOrigin(req: Request): string {
const explicit = process.env.OS_PUBLIC_ORIGIN?.trim();
if (explicit) {
diff --git a/lib/mcp/toolset.ts b/lib/mcp/toolset.ts
index d8f2c705..6617d5c2 100644
--- a/lib/mcp/toolset.ts
+++ b/lib/mcp/toolset.ts
@@ -3,7 +3,7 @@ import type { Scope } from "./scope";
import type { McpTool } from "./tool-kit";
import { toolDescriptor, type McpToolProfile } from "./tool-contract";
-export const MCP_SERVER_VERSION = "1.7.1";
+export const MCP_SERVER_VERSION = "1.7.2";
export const MCP_TOOLSET_VERSION = "2026.09.03.4";
export const MCP_TOOLSET_CHANGED_AT = "2026-09-03T10:23:00Z";