Merge branch 'v2/main' into v2/fix/2067-proxy-undici

One conflict, in `clients/tui/__tests__/App.test.tsx`: both sides added an
`opts` capture to the test harness's `FakeClient` for different fields —
`defaultMetadata` on v2/main (#1910), `environment.fetch` here (#2067) — so the
resolution is the union of the two, keeping both rationales and both tests.

Everything else auto-merged. `npm run ci` passes on the result.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-23 23:34:07 -04:00
commit 531cf84e60

View file

@ -42,6 +42,7 @@ import {
} from "../../types.js";
import type {
InspectorServerSettings,
RequestMetadata,
MCPConfig,
MCPServerConfig,
StdioServerConfig,
@ -1220,6 +1221,20 @@ export function createRemoteApp(
// credentials are intentionally lost on first read (hard cutover per
// #1358 decision 4). Users re-enter via the form or hand-edit into the
// flat shape.
// The *container* `_meta` requires — a plain JSON object.
//
// Value-level validity is deliberately not checked here. Values are
// arbitrary JSON (#1910), and the one class that survives `JSON.parse` yet
// cannot be sent — a non-finite number, from a literal like `1e400` in a
// hand-edited catalog — is filtered **per key** by
// `normalizeStoredMetadata`, which every read routes through. Rejecting the
// whole field here instead would cost a user every other key they had
// configured, for one bad value.
//
// Note the wire cannot carry the bad case at all: a client's own
// `JSON.stringify` turns `Infinity` into `null` before the request is sent.
const isJsonObject = (v: unknown): v is RequestMetadata =>
v !== null && typeof v === "object" && !Array.isArray(v);
const isStringRecord = (v: unknown): v is Record<string, string> => {
if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
for (const val of Object.values(v as Record<string, unknown>)) {
@ -1332,10 +1347,18 @@ export function createRemoteApp(
);
delete valObj.headers;
}
if ("metadata" in valObj && !isKvArray(valObj.metadata)) {
// A JSON object post-#1910; the pre-#1910 `{ key, value }[]` pair array
// is still accepted so an existing file keeps working (it is normalized
// by `normalizeStoredMetadata` on the way into the settings shape, and
// rewritten as an object on the next save).
if (
"metadata" in valObj &&
!isJsonObject(valObj.metadata) &&
!isKvArray(valObj.metadata)
) {
logWarn(
{ route: "/api/servers", id, droppedKey: "metadata" },
"Dropping malformed `metadata` field — expected `Array<{ key: string, value: string }>`.",
"Dropping malformed `metadata` field — expected a JSON object.",
);
delete valObj.metadata;
}
@ -1564,10 +1587,14 @@ export function createRemoteApp(
error: "settings.headers must be an array of { key, value }",
};
}
if (!isKvArray(obj.metadata)) {
// `_meta` takes any JSON, so metadata crosses the wire as a plain JSON
// object rather than the `{ key, value }` rows headers/env still use
// (#1910). Only the container is checked — the values are arbitrary JSON
// by design, and anything that survived `c.req.json()` already is.
if (!isJsonObject(obj.metadata)) {
return {
ok: false,
error: "settings.metadata must be an array of { key, value }",
error: "settings.metadata must be a JSON object",
};
}
// env is optional on the wire (older clients / non-stdio servers won't send
@ -1743,7 +1770,7 @@ export function createRemoteApp(
// Absent → empty list, matching the read side. The write-through drops
// empty-key rows and clears `config.env` when the list is empty.
env: isKvArray(obj.env) ? obj.env : [],
metadata: obj.metadata as { key: string; value: string }[],
metadata: obj.metadata as RequestMetadata,
connectionTimeout: obj.connectionTimeout as number,
requestTimeout: obj.requestTimeout as number,
// Absent → product default, matching the read side