Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/host-check-each-listener.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"@procedures/client": minor
"@procedures/server": minor
"@procedures/mark": minor
"@procedures/lib": minor
"@procedures/mcp-server": minor
---

**Breaking change:** each listener examines the `Host` header. By default, only `localhost`, `127.0.0.1`, `[::1]` and IP addresses pass. Give each other name with `--allowed-host` or `allowedHosts`.

The browser checks examine the `Host` header on each listener. Before, they examined it only on a loopback address. A server on a LAN address (`0.0.0.0`) accepted each host name.

A request must name one of these hosts in its `Host` header:

- A loopback name: `localhost`, `127.0.0.1` or `[::1]`.
- An IP address, for example `192.168.1.20` or `[fe80::1]`.
- A name of `browser.allowedHosts` of the host policy, with any letter case.

A request with another name gets `FORBIDDEN` (403) with the reason `host-header-not-allowed`. A request without a `Host` header gets it too. The message of the refusal names `allowedHosts` and `--allowed-host`. `browser.allowedHosts: "*"` turns the check off.

The server command and `mark --server` get the option `--allowed-host <names>`. Repeat the option, or separate the names with commas. `@procedures/server` exports `parseAllowedHosts`.

Migration steps:

- A server that a LAN, a proxy or a container network reaches by a name: give the name in `browser.allowedHosts` of `hostPolicy()`. Or start the server with `--allowed-host <name>`.
- An MCP face on HTTP that clients reach by a name: give the name in `http.allowedHosts` of the face, or in `browser.allowedHosts` of the policy.
- A server that clients reach by `localhost` or by an IP address: no change.
7 changes: 7 additions & 0 deletions packages/client-lib/src/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export const CLI_GLOBAL_FLAGS: readonly CliGlobalFlag[] = [
{ long: "server", takesValue: false, mode: true, description: "Start the CLI server" },
{ long: "port", takesValue: true, serverOption: true, description: "The port of the CLI server (with --server)" },
{ long: "host", takesValue: true, serverOption: true, description: "The host of the CLI server (with --server)" },
{
long: "allowed-host",
takesValue: true,
serverOption: true,
repeatable: true,
description: "A name that a request can give in its Host header, besides localhost and the IP addresses (with --server)",
},
{
long: "probe-port",
takesValue: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/client-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

Strict calls are the safe default of an MCP host. A procedure of code without `metadata.calls` can use only the tools of the host in its nested calls. Thus a tool cannot reach a procedure that the host does not expose. A procedure with `metadata.calls` can also use the procedures that it declares.

To turn strict calls off, give `policy: { strictCalls: false }`. Turn them off only for a host whose tools you trust with each procedure of the registry.

Check warning on line 97 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "use" or "start", not "calls". This applies when the verb means to start a function.

## The faces

Expand All @@ -115,10 +115,10 @@

The Streamable HTTP face checks each request before the request reaches the MCP SDK. The face has no token check of its own.

- The browser checks come first, with `guardMcpRequest`. A request on a loopback address must name a loopback host, or a host of `allowedHosts` (the default is `browser.allowedHosts` of the policy), in its `Host` header. Thus DNS rebinding cannot reach the tools. An `Origin` header must name the server or a permitted origin (the default is `browser.allowedOrigins` of the policy).
- The browser checks come first, with `guardMcpRequest`. Each request must name a loopback host, an IP address or a host of `allowedHosts` (the default is `browser.allowedHosts` of the policy) in its `Host` header, on each listener. Thus DNS rebinding cannot reach the tools. An `Origin` header must name the server or a permitted origin (the default is `browser.allowedOrigins` of the policy).
- Then the admission of the server checks the credentials. With a token, each request sends `Authorization: Bearer <token>`. The scheme has any case, for example `bearer` (RFC 7235). The check is `tokenMatches` of the core: its time does not tell the token. A refused request gets 401 with a `WWW-Authenticate` header.
- The token of a host is the token of its policy. A `token` of the HTTP face of `createMcpHost` becomes the token of the policy, and two different tokens stop the host with an error. `McpServerTransport` refuses a token in its HTTP options: give the token to the server. Refer to [Deprecated token options](#deprecated-token-options).
- `guardMcpRequest` refuses a `token` option. The first call with it throws a `TypeError` that names the migration. Each later call with it gives a refusal with the status 500, without an error. Thus each request stays refused, and the log gets one error.

Check warning on line 121 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "use" or "start", not "call". This applies when the verb means to start a function.
- Only an `initialize` request starts a session. Thus a stray POST makes no MCP server. The body of each request has a limit of 4 MiB (`maxBodyBytes`).
- The face keeps at most 256 sessions by default (`maxSessions`, CLI-51). A new session above the limit closes the session that was idle longest: no task in progress and no open response (a call or a GET stream). When each session is busy, the new session gets 503 with a `Retry-After` header. A client that sends to a closed session gets 404, and a client of the MCP specification then sends a new `initialize`.
- Each live client of the MCP SDK keeps its GET stream open. Thus the limit does not close the session of a live client, and 256 is much more than the clients of one host. To serve more clients, give a larger `maxSessions`. `maxSessions: Infinity` turns the limit off.
Expand All @@ -133,7 +133,7 @@
| `faces.http.token` of `createMcpHost()` | It becomes the token of the policy. A different token in the policy throws an error. | `policy.token` |
| `httpOptions.token` of `McpServerTransport` | `start()` throws an error. | `new ProcedureServer({ token })` |
| `token` of `mcpFace()` | A token that is not the token of the policy throws an error. | `hostPolicy({ token })` |
| `token` of `guardMcpRequest` | The option is removed. The first call with it throws a `TypeError`, and each later call with it gets a refusal with the status 500. The function does only the browser checks. | The token check of the server, and `admission()` of the server for each request |

Check warning on line 136 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "use" or "start", not "call". This applies when the verb means to start a function.

## A host under the runner

Expand Down Expand Up @@ -245,7 +245,7 @@

## Tasks

A long call can run as an MCP task (MCP 2025-11-25). The client gets a task at once, polls its status, gets the result later, and can cancel the task. Two parts turn it on:

Check warning on line 248 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "start", "starts" or "operates", not "run".

- The procedure declares it in its metadata: `taskSupport: "optional"` (a task or a normal call) or `taskSupport: "required"` (only a task).
- The host has a task store: the option `tasks`.
Expand All @@ -266,14 +266,14 @@
- A progress of the procedure becomes the status message of its task, for example `2 of 5 done`. The message holds only the counts, so no text of the work leaves its envelopes. A client that sent a progress token also gets the progress notifications.
- A cancel of the task (`tasks/cancel`) aborts `ctx.signal` of the procedure. The close of a session cancels its tasks, and the stop of the host cancels each task.
- Each task belongs to its session. A request of another session does not find it. A task without a session (stdio, an SDK transport) is visible only to the requests without a session. Such a request does not find the tasks of the HTTP sessions.
- The store runs at most `maxRunning` tasks at one time (8 by default). A task holds its place until its procedure returns, also after a cancel. A task above the limit starts, and then fails at once. Thus the client gets a task, and the result of the task gives the reason. A full store is different: refer to `maxStored` below.

Check warning on line 269 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "gives", not "returns". For a function, write "This function gives ...".

Check warning on line 269 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "start", "starts" or "operates", not "runs".
- The time to keep a task (`ttl`) starts when the task ends. The store does not remove a task whose procedure still runs.
- The store keeps at most 100 tasks for one session, and at most 1000 tasks for all the sessions together (`maxStored`, CLI-51). A new task removes the oldest task of its own session that ended. The store can be full, and the session can have no task that ended. Then the request of the new task gets the error `-32600`, and the store keeps nothing of it. Thus a client cannot remove the results of another session. `maxStored: Infinity` turns the total limit off.
- The fair share (CLI-69) keeps one client from the whole store. The store keeps the last `reserve` slots (100 of 1000 by default) for the clients below their share. The rules follow this list.
- The function `shareKey` gives the client of a task. The default `mcpTaskShareKey` gives the principal of the request, else the session. The token of the host is the same for each caller, so it does not identify a client.
- The timers of the store use its `clock`. A test gives a fake clock.
- The call of a task cannot ask the person: the procedure gets no `ctx.elicit`.
- A normal call of an optional tool runs in the request, with the progress and the cancel of the request. A normal call of a tool with `taskSupport: "required"`, or a task for a tool without task support, gets the error `-32601`.

Check warning on line 276 in packages/client-mcp/README.md

View workflow job for this annotation

GitHub Actions / Repository checks (catalogs, imports, packages, lifecycle, coverage)

Write "start", "starts" or "operates", not "runs".
- To share one store with other parts, give `tasks: { store: new McpTaskStore({ maxRunning: 4 }) }`. The host closes only a store that it made.

The fair share applies these rules to a new task of a client:
Expand Down
2 changes: 1 addition & 1 deletion packages/client-mcp/src/face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface McpFaceOptions extends Omit<McpServerTransportOptions, "transpo
* function. The default is `browser.allowedOrigins` of the policy.
*/
readonly allowedOrigins?: BrowserGuardOptions["allowedOrigins"];
/** The host names that a request on a loopback address can name. The default is `browser.allowedHosts` of the policy. */
/** The host names that a request can name, besides the loopback names and the IP addresses. The default is `browser.allowedHosts` of the policy. */
readonly allowedHosts?: readonly string[] | "*" | undefined;
/** The most sessions at one time (CLI-35). The default is 256 (CLI-51). `Infinity` turns the limit off. */
readonly maxSessions?: number | undefined;
Expand Down
6 changes: 3 additions & 3 deletions packages/client-mcp/src/transport/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* The `handle` of the face calls `guardMcpRequest` before a request reaches the MCP SDK. The face
* mounts on more than one kind of listener, so the listener adds no second check for its path.
*
* - The checks of a web browser (`checkBrowserRequest` of the core): a request on a loopback
* address names a loopback host or an allowed host (DNS rebinding), and an `Origin` header names
* - The checks of a web browser (`checkBrowserRequest` of the core): each request names a loopback
* host, an IP address or an allowed host (DNS rebinding), and an `Origin` header names
* the server or a permitted origin. A request with cookies needs a named origin (CSRF).
* - The credentials are not checked here (CLI-2b). After the browser checks, the face gives each
* request to the admission of its server (`admission()` of the handler): the request hook, the
Expand Down Expand Up @@ -54,7 +54,7 @@ export const MCP_HTTP_LIMITS: {
export interface McpRequestGuardOptions {
/** The browser origins that can call the face, besides its own origin. */
readonly allowedOrigins?: BrowserGuardOptions["allowedOrigins"];
/** The host names that a request on a loopback address can name, besides the loopback names. */
/** The host names that a request can name, besides the loopback names and the IP addresses. */
readonly allowedHosts?: BrowserGuardOptions["allowedHosts"];
/** True when the server trusts cookies for the request: then only a named origin can call (CSRF). */
readonly ambient?: boolean | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/client-mcp/src/transport/one-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface Counts {
function countedBrowser(counts: Counts): BrowserGuardOptions {
const allowedHosts = new Proxy(["app.test"], {
get(target, key, receiver) {
if (key === "includes") counts.hosts++;
if (key === "includes" || key === "some") counts.hosts++;
return Reflect.get(target, key, receiver) as unknown;
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/client-mcp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export interface HttpTransportOptions {
*/
allowedOrigins?: BrowserGuardOptions["allowedOrigins"];
/**
* The host names that a request on a loopback address can name in its `Host` header, besides
* the loopback names (`browser.allowedHosts` of the host policy). `"*"` turns the check off.
* The host names that a request can name in its `Host` header, besides the loopback names and
* the IP addresses (`browser.allowedHosts` of the host policy). `"*"` turns the check off.
*/
allowedHosts?: readonly string[] | "*" | undefined;
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/client-server/src/host/one-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface Counts {
function countedBrowser(counts: Counts): BrowserGuardOptions {
const allowedHosts = new Proxy(["app.test"], {
get(target, key, receiver) {
if (key === "includes") counts.hosts++;
if (key === "includes" || key === "some") counts.hosts++;
return Reflect.get(target, key, receiver) as unknown;
},
});
Expand Down
55 changes: 52 additions & 3 deletions packages/client/src/server/browser-guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ProcedureServer } from "./procedure-server.js";
import { ProcedureRegistry } from "../procedures/registry.js";
import { defineProcedure } from "../procedures/define.js";
import { outputSchema } from "../procedures/core/schemas.js";
import { checkBrowserRequest, isLoopbackAddress, type BrowserGuardOptions } from "./browser-guard.js";
import { checkBrowserRequest, isLoopbackAddress, type BrowserGuardOptions, type GuardResult } from "./browser-guard.js";

let cleanups: Array<() => Promise<void>> = [];
afterEach(async () => {
Expand Down Expand Up @@ -227,10 +227,59 @@ describe("checkBrowserRequest", () => {
expect(isLoopbackAddress("192.168.1.5")).toBe(false);
});

it("checks the host only on a loopback address", () => {
// A request on a socket with this local address
const on = (localAddress: string, headers: Record<string, string>, options: BrowserGuardOptions = {}) =>
checkBrowserRequest({ method: "POST", headers: { "content-type": "application/json", "content-length": "2", ...headers }, socket: { localAddress } }, options, true);
const reasonOf = (result: GuardResult) => (result.ok ? "ok" : result.reason);

it("checks the host on a loopback address", () => {
expect(check({ host: "evil.example" }).ok).toBe(false);
expect(check({ host: "evil.example" }, { allowedHosts: ["evil.example"] }).ok).toBe(true);
expect(checkBrowserRequest({ method: "POST", headers: { host: "my-server.lan" }, socket: { localAddress: "192.168.1.5" } }, {}, true).ok).toBe(true);
});

it("checks the host on a LAN address too: a DNS rebinding page is not the origin of the server", () => {
// The page http://evil.example:3000 after its name resolves to the LAN address of the host
const rebound = { host: "evil.example:3000", origin: "http://evil.example:3000" };
expect(reasonOf(on("192.168.1.20", rebound))).toBe("host-header-not-allowed");
expect(reasonOf(on("::ffff:192.168.1.20", rebound))).toBe("host-header-not-allowed");
expect(reasonOf(on("fe80::1", rebound))).toBe("host-header-not-allowed");
expect(reasonOf(on("192.168.1.5", { host: "my-server.lan" }))).toBe("host-header-not-allowed");
// A request with no Host header names no permitted host
expect(reasonOf(on("192.168.1.20", {}))).toBe("host-header-not-allowed");
});

it("accepts the loopback names and the IP addresses on each listener", () => {
for (const local of ["127.0.0.1", "::1", "192.168.1.20", "::ffff:192.168.1.20", "172.17.0.2"]) {
for (const host of ["localhost:3000", "127.0.0.1:3000", "[::1]:3000", "LOCALHOST", "192.168.1.20:3000", "10.0.0.7", "[fe80::1]:3000", "[::ffff:c0a8:114]"]) {
expect(reasonOf(on(local, { host })), `${host} on ${local}`).toBe("ok");
}
}
// The page of an IP address is the origin of the server at that address
expect(reasonOf(on("192.168.1.20", { host: "192.168.1.20:3000", origin: "http://192.168.1.20:3000" }))).toBe("ok");
});

it("refuses a name that only looks like an IP address", () => {
for (const host of ["1.2.3.4.evil.example", "256.1.1.1", "1.2.3", "1.2.3.4.5", "0x7f.0.0.1", "[evil.example]", "[]", "[:]x", "127.0.0.1.nip.io"]) {
expect(reasonOf(on("192.168.1.20", { host })), host).toBe("host-header-not-allowed");
}
});

it("accepts a name of allowedHosts on each listener, in any case, and each name with '*'", () => {
const options: BrowserGuardOptions = { allowedHosts: ["My-Server.lan"] };
expect(reasonOf(on("192.168.1.5", { host: "my-server.lan:3000" }, options))).toBe("ok");
expect(reasonOf(on("192.168.1.5", { host: "MY-SERVER.LAN" }, options))).toBe("ok");
expect(reasonOf(on("127.0.0.1", { host: "my-server.lan" }, options))).toBe("ok");
expect(reasonOf(on("192.168.1.5", { host: "other.lan" }, options))).toBe("host-header-not-allowed");
expect(reasonOf(on("192.168.1.5", { host: "other.lan" }, { allowedHosts: "*" }))).toBe("ok");
});

it("names allowedHosts and --allowed-host in the refusal of a name", () => {
const refused = on("192.168.1.5", { host: "My-Server.lan:3000" });
expect(refused.ok === false && refused.message).toBe(
'Forbidden: the host "my-server.lan" is not allowed. To permit it, add it to allowedHosts of the host policy, or start the server with --allowed-host my-server.lan'
);
const noHost = on("192.168.1.5", {});
expect(noHost.ok === false && noHost.message).toBe("Forbidden: the request has no Host header");
});

it("refuses the origin 'null' (a sandboxed frame or a file) unless every origin is allowed", () => {
Expand Down
48 changes: 39 additions & 9 deletions packages/client/src/server/browser-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* ran any procedure, and the WebSocket server accepted a connection from any page
* (cross-site WebSocket hijacking). The checks here are on by default in both transports:
*
* - A connection that arrives on a loopback address must name a loopback host in its `Host`
* header. A DNS rebinding attack sends the name of the attacker's site.
* - Each request must name a permitted host in its `Host` header: a loopback name, an IP address,
* or a name of `allowedHosts`. A DNS rebinding attack sends the name of the attacker's site.
* The check is on each listener, also on a LAN address (`0.0.0.0`).
* - A browser request (an `Origin` header) must come from the server's own origin, or from an
* origin in `allowedOrigins`.
* - A request that the browser marks `Sec-Fetch-Site: cross-site` or `same-site` and that has
Expand All @@ -33,9 +34,10 @@ export interface BrowserGuardOptions {
*/
allowedOrigins?: readonly string[] | "*" | ((origin: string) => boolean) | undefined;
/**
* The host names that a request on a loopback address can name in its `Host` header,
* besides the loopback names. `"*"` turns the check off.
* @default [] (only `localhost`, `127.0.0.1` and `[::1]`)
* The host names that a request can name in its `Host` header, besides the loopback names and
* the IP addresses. The check is on each listener. A server that a LAN or a proxy reaches by a
* name lists that name here. `"*"` turns the check off.
* @default [] (only `localhost`, `127.0.0.1`, `[::1]` and the IP addresses)
*/
allowedHosts?: readonly string[] | "*" | undefined;
/**
Expand Down Expand Up @@ -95,6 +97,26 @@ export function isLoopbackHost(host: string): boolean {
return LOOPBACK_NAMES.has(host.toLowerCase());
}

/**
* True for a host name that is an IP address: four decimal numbers from 0 to 255 (`192.168.1.20`),
* or an IPv6 address in brackets (`[fe80::1]`). A browser writes an IP address of a URL in these
* forms in the `Host` header. A DNS rebinding attack needs a name, not an IP address.
*/
function isIpAddressHost(name: string): boolean {
if (name.startsWith("[")) {
// The URL parser accepts only a valid IPv6 address in brackets
if (!/^\[[0-9a-f:.]+\]$/.test(name)) return false;
try {
return new URL(`http://${name}/`).hostname.startsWith("[");
} catch {
return false;
}
}
// path-check: the four numbers of an IPv4 address, not the parts of a path
const parts = name.split(".");
return parts.length === 4 && parts.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255);
}

/** True for a local socket address on the loopback interface (IPv4, IPv6, or IPv4 in IPv6). */
export function isLoopbackAddress(address: string | undefined): boolean {
if (!address) return false;
Expand Down Expand Up @@ -187,11 +209,19 @@ export function checkBrowserRequest(
): GuardResult {
const { headers } = req;

// DNS rebinding: a request on a loopback address must name a loopback host
if (options.allowedHosts !== "*" && isLoopbackAddress(req.socket?.localAddress)) {
// DNS rebinding: each request names a loopback host, an IP address or a permitted name, on each
// listener. The check of the origin below compares the origin with this Host header.
if (options.allowedHosts !== "*") {
const name = hostNameOf(headers.host);
if (!LOOPBACK_NAMES.has(name) && !(options.allowedHosts ?? []).includes(name)) {
return refusal("host-header-not-allowed", `Forbidden: the host "${name}" is not allowed`);
const allowed = options.allowedHosts ?? [];
if (!LOOPBACK_NAMES.has(name) && !isIpAddressHost(name) && !allowed.some((host) => host.toLowerCase() === name)) {
// The refusal names the two settings that permit a name, so an operator finds the change
return refusal(
"host-header-not-allowed",
name === ""
? "Forbidden: the request has no Host header"
: `Forbidden: the host "${name}" is not allowed. To permit it, add it to allowedHosts of the host policy, or start the server with --allowed-host ${name}`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/documentation/WIRE-PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ A `FORBIDDEN` error tells its reason in the metadata key `reason`. The HTTP body
| `partition-not-allowed` | The collection procedures | The partition resolver of the collection refuses the partition of the call (CLI-17). |
| `write-not-allowed` | The collection procedures | The guard of the collection (`admission.guard`) refuses a write. The storage does not change (CLI-41). |
| `origin-not-allowed` | The browser checks | The `Origin` of the request is not the origin of the server or a permitted origin. A cross-site request without a permitted origin gets it too. |
| `host-header-not-allowed` | The browser checks | A request on a loopback address names a `Host` that is not permitted (DNS rebinding). |
| `host-header-not-allowed` | The browser checks | The `Host` of the request is not a loopback name, an IP address or a permitted name (DNS rebinding). The check is on each listener. |
| `method-not-allowed` | The browser checks of HTTP | The HTTP method is `GET` or `HEAD`, and the option `allowGet` is off. |
| `media-type-not-allowed` | The browser checks of HTTP | The request body is not JSON. |

Expand Down
4 changes: 2 additions & 2 deletions packages/mark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ The package provides a `mark` binary for command-line usage.
mark [global options] <path...> [positional...] [--options]
mark serve [--procedures pkgs] [--port N] [--token T | --no-token] [--expose patterns] [--events topics] [--fs-root folder] [--probe-port N]
mark mcp [--bundles list] [--tool-timeout ms] [--read-only] [--http port] [--max-sessions n] [--fs-root folder] [--debug]
mark --server [--port N] [--host H] [--transport http|websocket|both] [--events topics] [--probe-port N] [--idle-timeout ms]
mark --server [--port N] [--host H] [--allowed-host names] [--transport http|websocket|both] [--events topics] [--probe-port N] [--idle-timeout ms]
mark -i
mark --fs-root <folder> <command | --server | -i | serve | mcp>
```
Expand Down Expand Up @@ -249,7 +249,7 @@ A flag before the command path is a global flag. After the path, a flag is the c
| `--local` | | Run the command in this process, not on the CLI server |
| `--json <json>` | | Execute raw procedure reference |
| `--fs-root <folder>` | | Keep each path of each procedure in the folder, also in the nested calls, and refuse the procedures that it cannot confine. Give it before the command. |
| `--server` | | Start the CLI server (with `--port`, `--host`, `--transport`, `--events`) |
| `--server` | | Start the CLI server (with `--port`, `--host`, `--allowed-host`, `--transport`, `--events`) |
| `--interactive` | `-i` | Start the REPL |

#### Exit Codes and Failures
Expand Down
8 changes: 8 additions & 0 deletions packages/mark/src/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ describe("global flags and procedure flags (CLI-7)", () => {
expect(parseLeadingGlobals(["--fs-root"]).errors).toEqual(["--fs-root needs a value"]);
});

it("collects a repeated --allowed-host of --server", () => {
expect(parseLeadingGlobals(["--server", "--host", "0.0.0.0", "--allowed-host", "box.lan", "--allowed-host=api.lan"]).globals).toEqual({
server: true,
host: "0.0.0.0",
"allowed-host": "box.lan,api.lan",
});
});

it("reports a flag that neither the procedure nor the globals have", () => {
expect(parse(["fs", "exists", "x", "--bogus"]).errors).toEqual(["Unknown option for mark fs exists: --bogus"]);
expect(parse(["docker", "exec", "-iz", "box", "sh"]).errors).toEqual(["Unknown option -z in -iz"]);
Expand Down
1 change: 1 addition & 0 deletions packages/mark/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type GlobalName =
| "server"
| "port"
| "host"
| "allowed-host"
| "transport"
| "events"
| "probe-port"
Expand Down
Loading
Loading