Files
webstudio/packages/cli/src/response-headers.ts
T
Oleg Isonen be74d8d698 fix: Validate response headers and expose MCP rule edits (#6444)
Header rules previously accepted `null` values, which silently turned a
rule into a header-removal instruction even though the settings UI only
offers adding a string value or deleting a rule. Require a nonempty
string throughout the SDK, Builder, CLI generator, and API contract.

Expose configured rules to MCP through `list-response-headers`,
`set-response-header`, and `delete-response-header`. Setting a rule adds
or replaces the header for the same route and case-insensitive name; `/`
and `/*` remain distinct. The Builder UI and MCP operations now share
the same rule-key, edit, and Zod validation logic. The generated JSON
Schema advertises the header-name pattern and nonempty value, while
server-side Zod validation enforces route syntax, forbidden headers,
duplicates, and total size. The generic `update-project-settings`
operation still supports replacing the whole list.

Validation: SDK, project-build runtime and MCP, CLI command and prebuild
tests; SDK, Builder, project-build, CLI, and protocol typechecks; lint,
package boundaries, generated API and docs checks. Local fixture sync
against the development API is blocked by differing bundle versions; PR
CI tests fixtures against its deployed Builder host.
2026-09-25 23:37:07 +02:00

16 lines
530 B
TypeScript

import { customResponseHeaders } from "@webstudio-is/sdk/schema";
import type { ProjectSettings } from "@webstudio-is/project-build";
export const generateResponseHeadersModule = (settings?: ProjectSettings) => {
const configured = customResponseHeaders.parse(
settings?.meta.customHeaders ?? []
);
return `// Generated response header configuration for hosting adapters.
export const customHeaders: Array<{ route?: string; name: string; value: string }> = ${JSON.stringify(
configured,
null,
2
)};
`;
};