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
28 changes: 25 additions & 3 deletions docs/AUTOMATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,33 @@ change them.
| `grants` | none | The granted operations: `check`, `build`, `test`, `preview`, `inspect`, `interact` (click/fill), `call`, and the setup grants `init`, `create`, `install`, `restore`, `embed`. None leaves only session discovery. |
| `callbacks` | none | The application callbacks `call` may invoke, by exact name (see below). |
| `mcpPort` | 0 | The port of the listener; 0 lets the OS choose. A chosen port is never replaced: when it is taken the activation throws a `std::system_error` that names the address, the port and the cause. |
| `mcpToken` | absent | An application-supplied Bearer token, retained across launches if the application supplies the same value. Absent selects a fresh random token per session. Use a long random secret outside the project. |
| `disableMcpAuthentication` | false | Explicitly allow local clients without a Bearer token. Cannot be combined with `mcpToken`. |
| `directory` | a new directory named after the session in the discovery directory | A new private directory outside the project for `mcp.json`. |
| `discovery` | the per-user sessions directory | Where the record goes (tests use their own). |
| `timeout` | 120 s | The native deadline of one operation. |
| `startupTimeout` | 120 s | How long the window may take to claim the session. |
| `closeGrace` | 5 s | How long a revoked window may take to close before `onUnresponsive`. |
| `onUnresponsive` | ends the process with status 72 | What to do with a window that did not close. |

For a client configured once, set `mcpPort` to a fixed nonzero port and supply the same `mcpToken` on every launch, for example from a private environment variable read by the application. Copy the URL and Authorization header from the first `mcp.json` into the client's **user** configuration, outside the project. Start the application before connecting; retry after starting it if the connection is refused. Rotate the token by changing the application-supplied value and updating the client. A second instance can use the default options; a second listener on the chosen port fails explicitly.

```cpp
const char* token = std::getenv("MY_APP_MCP_TOKEN");
if (!token || !*token)
throw std::runtime_error("Set MY_APP_MCP_TOKEN to a private random token");
auto automation = webfront::automation::enableAutomation(
app, {.grants = {"check", "build"}, .mcpPort = 19002, .mcpToken = std::string{token}});
```

The application includes `<cstdlib>`, `<stdexcept>` and `<string>` for this example; MSVC reports `std::getenv` as deprecated (C4996), so use `_dupenv_s` or define `_CRT_SECURE_NO_WARNINGS` there. A configured token must be 32–1024 visible ASCII characters without spaces; length alone does not guarantee randomness. To opt in to an unauthenticated listener instead, use `.disableMcpAuthentication = true` and omit `mcpToken`; its client configuration has no Authorization header. In that mode any Authorization header, including an incorrect Bearer, is ignored.

The startup banner warns when authentication is disabled. It appears on stderr and, once the window connects, in the developer terminal. With `announce = false` there is no stderr warning; the terminal still receives the banner when it connects, and `automation->banner()` still returns it.

These options are for trusted development environments. A different local user can occupy the fixed port while the application is stopped and receive a durable Bearer sent by the client, then reuse it when the application starts. Without authentication, any local process that reaches the listener can exercise its grants. A fake server can also send misleading responses. Loopback, strict Host, Origin and Sec-Fetch checks remain enabled in both modes; they do not authenticate the server to the client.

After a crash or forced termination, the private `mcp.json` can remain on disk with the durable token. Session discovery prunes known files in default session directories when it detects a dead process, but cleanup can be delayed or fail; an explicitly supplied `directory` is not pruned by discovery. Inspect and remove stale private files as needed, and rotate a token if it may have been exposed.

All executable operations are denied unless granted. The setup grants write the manifest, the lock, the cache, a new starter
directory or the generated provider header; grant them only for a project whose registry you trust. `install` and `restore`
use the registry already configured by the owner, the manifest or the default; the operation cannot choose another one.
Expand Down Expand Up @@ -116,9 +136,11 @@ operation of `webfront.start`, not one MCP tool per callback, so the tool list s
served with TLS, whatever the application's own address and TLS listener. `mcpPort` chooses a port; a chosen port is never
replaced: when it is taken the activation throws a `std::system_error` that names the address, the port and the cause.
Each instance has its own URL, so several applications run side by side and the agent picks one by its URL.
- **Token.** Every request carries `Authorization: Bearer <token>`, a 256-bit value from the OS, compared in constant time
before the body is parsed; otherwise 401 with `WWW-Authenticate: Bearer` (no OAuth server is announced). The token lives as
long as the session: closing it, a deadline or a lost window closes the listener and removes the file.
- **Token.** By default every request carries `Authorization: Bearer <token>`, a 256-bit value from the OS. Before parsing the
body, the listener compares equal-length tokens in constant time and rejects a length mismatch immediately; a failed check gets
401 with `WWW-Authenticate: Bearer` (no OAuth server is announced). The token lives as
long as the session by default: closing it, a deadline or a lost window closes the listener and removes the file. A supplied
`mcpToken` remains valid across launches until the application changes it; authentication can be explicitly disabled.
- **Client configuration.** `mcp.json` (mode 0600 in a 0700 directory on POSIX, owner-only ACL on Windows) holds the URL and
the header, ready for a client that takes a configuration file (`claude --mcp-config PATH/mcp.json`). The token appears in
no page, URL, command line, log, banner or discovery record. Never copy it into the project, its `.mcp.json` included: the
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ these entries stays in the GitHub releases and the Git history.
- The CEF profile is now `cef_cache/<executable>`, not `cef_cache`: an application starts with an empty profile (localStorage, cookies); to keep the data, move the old contents of `cef_cache` into `cef_cache/<executable>` once (#617, `docs/HOST_INTEGRATION.md`).

### Added
- Configure a stable MCP port and application-supplied Bearer token, or explicitly disable authentication for trusted development (#637, ADR-026, `docs/AUTOMATION.md`).
- Connect an MCP client to the application itself: `enableAutomation(app, {.grants = {...}})` serves MCP over Streamable HTTP on a loopback port of its own, prints its URL and writes a private `mcp.json` with the URL and a session Bearer token, so several applications run side by side with no other program (#632, ADR-025, `docs/AUTOMATION.md`).
- Use a custom network provider with `DeveloperAppWithNetwork`. The `BasicDeveloperApp` alias selects the existing TCP provider (#631).
- Pass the MSVC code analysis on the automation host probe and the discovery directory of `Enable.hpp` (C6031, C6244), which stopped the Windows desktop job of a dispatch or pull request at its build (#638).
Expand All @@ -26,6 +27,7 @@ these entries stays in the GitHub releases and the Git history.
- Run the MSVC code analysis in a pull request into `develop` that changes Windows code, and list the reruns each job needed before going green with `FlakeReport.py --days` (#628, `docs/TEST_TIERS.md`, `docs/TEST_PERFORMANCE.md`).

### Fixed
- Refuse every `Sec-Fetch-*` request header on the MCP listener, including `Sec-Fetch-Dest`, in both authenticated and unauthenticated modes (#637).
- Check the leftover STA of a WebView2 window only after a page that ran to its end, not after one that closes the window on a load failure, and record the apartment `WebView2Lifecycle-repeated-show` finds after each `show()`, so that a failure or a passing run says which page leaves one (#638, `docs/PROJECT_STATUS.md`).
- Pass the compiler analysis on the Windows pseudoterminal when it cannot prove the attribute list non-null (C6387), stop a unit test from opening the developer's real browser (the directory of its replacement opener was removed before the shell found it), and keep an accepted connection whose `TCP_NODELAY` the system refuses, as macOS does after a reset (#628).

Expand Down
6 changes: 6 additions & 0 deletions docs/DEVELOPER_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ checks the pinned header against the published archive. The headers of the core'
`@webfront/developer-environment`, `@webfront/app-starter` and `@webfront/life-starter`. They are distributed as static
GitHub Pages downloads; no npm publication or scope ownership is required.

The version in `distribution.json` is the version built from the current sources (currently 1.0.3, not yet published).
It can be ahead of `DeveloperReleaseData.hpp`, which pins the published 1.0.2 environment used by applications. The
compatibility table above records that published pin, not the next source build. The default branch receives a new
pin only after the new distribution is published and its files are verified. Before the tag, the release branch carries
the regenerated header, and `wf run build <directory> --refresh-bootstrap` rewrites it locally.

The `SelfBuild*` CTest cases run the scripts on a copy of the sources, with the dependencies installed from the local
registry: the build, a repeat build (same bytes), the checked-in bootstrap bundles and checksums rebuilt by wf alone (and the
core headers rendered from them by CMake), the staging of the site (a second staging repeats the same bytes, a changed
Expand Down
4 changes: 3 additions & 1 deletion docs/DEVELOPING_WITH_AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ argument. The [developer environment reference](DEVELOPER_ENVIRONMENT.md) has th

## Running wf yourself, through MCP

For a client configured once, the application can set a fixed `mcpPort` and provide the same `mcpToken` on each launch. Copy the first private `mcp.json` URL and Bearer header into the client user configuration, outside the project. Start the application before connecting. This opt-in mode accepts the local server impersonation risk described in [AUTOMATION.md](AUTOMATION.md); the default remains a fresh session token.

The application runs the same commands in its own window and serves them over MCP: in a development build, it is the MCP
server, at a URL of its own. An MCP client connects to that URL; no other program is built or launched.

Expand Down Expand Up @@ -92,7 +94,7 @@ for a project whose output you accept to regenerate.
WebFront MCP (grants: check, build, ...): http://127.0.0.1:PORT/mcp - client configuration: /home/me/.local/state/webfront/sessions/SESSION/mcp.json
```

Each running instance has its own port, so the URL is printed rather than known in advance. `mcp.json` is the client
By default each running instance has its own port, so the URL is printed rather than known in advance. `mcp.json` is the client
configuration of that instance, URL and Bearer token together, in a private directory outside the project:

```json
Expand Down
11 changes: 6 additions & 5 deletions docs/PROJECT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ WebFront is a header-only C++23 HTTP/WebSocket core plus a standalone developer
`mcp.json` client configuration; no other program is built or launched ([ADR-025](adr/ADR-025-mcp-http-dans-l-application.md),
#632). Native grants select check/build/test/preview, bounded inspection, semantic actions, the setup operations and the
owner's allow-listed callbacks (`call`). Several instances run side by side, each with its own URL and discovery record.
A fixed MCP port and application-supplied token can keep a client configuration stable; authentication can also be
explicitly disabled for development, with the local-process risks described in [Automation](AUTOMATION.md) (#637).
Remote access is out of scope and automation does not compile with `WEBFRONT_DISTRIBUTION`. This does not isolate
untrusted project code. [Automation](AUTOMATION.md) documents the listener, lifecycle, limits and the supported MCP profile.
The `webfront-agent` launcher, its JSON CLI and MCP on stdio were removed. Known limitation until the next environment
release: the published environment 1.0.1 that the library pins still tells agents (`wf help agents`, the `AGENTS.md`
that `wf create` writes) to run `webfront-agent`, which no longer exists, so that agent path is not ready from a pinned
environment. The replacement texts, which name the application's MCP URL and its `mcp.json`, are in the sources
(environment 1.0.2) and in `docs/DEVELOPING_WITH_AGENTS.md`, which an agent should follow meanwhile. First-contact
The `webfront-agent` launcher, its JSON CLI and MCP on stdio were removed. The environment 1.0.2 pinned in
[`DeveloperReleaseData.hpp`](../include/webfront/system/DeveloperReleaseData.hpp) describes MCP;
the starter guidance for stable client configuration is in the 1.0.3 sources and will reach `wf create` in the next
environment release. Until then agents can follow `docs/DEVELOPING_WITH_AGENTS.md`. First-contact
guidance for agents (README section, `docs/DEVELOPING_WITH_AGENTS.md`, `webfront_write_agent_guide()`, configuration and
startup notices) comes with the library.
- **Maintaining WebFront.** The repository is itself a `wf` project, selected with
Expand Down
7 changes: 4 additions & 3 deletions docs/adr/ADR-025-mcp-http-dans-l-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Le port est celui que l'OS attribue (`0`), selon le mécanisme de #617 ; une opt

Chaque activation tire un jeton de 256 bits de l'aléa de l'OS, distinct de la capacité du canal JSON-lines, du secret de
lancement de la page et de l'identifiant de session. Chaque requête porte `Authorization: Bearer <jeton>` ; la comparaison
est à temps constant et précède la lecture du JSON. Sinon : 401 avec `WWW-Authenticate: Bearer`, sans `resource_metadata`,
parcourt tout le jeton à temps constant lorsque les longueurs sont égales. Une différence de longueur est rejetée immédiatement.
La comparaison précède la lecture du JSON. Sinon : 401 avec `WWW-Authenticate: Bearer`, sans `resource_metadata`,
car aucun serveur d'autorisation OAuth n'est annoncé. Le jeton vit autant que la session : il est révoqué à sa fermeture
(fermeture normale, échéance native, fenêtre perdue, watchdog, signal que l'application intercepte pour fermer), l'écouteur est alors fermé, et une
nouvelle activation tire un nouveau jeton. Pas de rotation pendant la session.
Expand All @@ -104,7 +105,7 @@ Avant l'authentification, et donc même avec un jeton valide :

- **Host** doit valoir exactement `127.0.0.1:<port>` ou `localhost:<port>` ; sinon 421. Cela écarte le rebinding DNS.
- **Origin** non vide : 403, quelle que soit sa valeur, y compris l'origine de l'application. Un client MCP natif n'envoie
pas d'`Origin` ; un navigateur l'envoie sur tout `POST`. `Sec-Fetch-Site` ou `Sec-Fetch-Mode` présent : 403 aussi.
pas d'`Origin` ; un navigateur l'envoie sur tout `POST`. Tout en-tête `Sec-Fetch-*` présent reçoit aussi 403.
- **Content-Type** doit être `application/json` : une requête « simple » de formulaire est refusée (415), et la requête de
pré-vérification `OPTIONS` reçoit 405 sans aucun en-tête CORS. Aucune réponse ne porte `Access-Control-Allow-*`.

Expand Down Expand Up @@ -203,7 +204,7 @@ Les menaces, actifs et risques résiduels de l'ADR-019 restent valables. Ce qui
| Menace et gravité | Mesures | Risque résiduel |
| --- | --- | --- |
| Rebinding DNS, page web qui vise le port MCP — critique | Écouteur loopback distinct ; Host exact ; tout `Origin` et tout `Sec-Fetch-*` refusés ; `application/json` exigé ; aucun CORS ; jeton exigé en plus. | Un navigateur qui omettrait `Origin` sur un `POST` cross-origin et ignorerait la pré-vérification resterait sans jeton. |
| Client local non autorisé — critique | Jeton de 256 bits, comparaison à temps constant, avant tout traitement ; fichier privé hors projet. | Un processus du même utilisateur peut lire `mcp.json`, comme il lisait le fichier du canal JSON-lines. |
| Client local non autorisé — critique | Jeton de 256 bits, comparaison à temps constant à longueur égale, avant tout traitement ; fichier privé hors projet. | La longueur est observable ; un processus du même utilisateur peut lire `mcp.json`, comme il lisait le fichier du canal JSON-lines. |
| Fuite du jeton — élevée | Jamais dans le projet, la page, l'URL, la ligne de commande, les journaux, l'affichage ou l'enregistrement ; vie limitée à la session. | Une personne qui copie le fichier dans le projet ou un dépôt l'expose ; la documentation l'interdit, aucun contrôle ne l'empêche. |
| Exposition réseau — critique | Liaison 127.0.0.1 seule, indépendante de l'adresse et du TLS de l'application ; adresse non configurable. | Un transfert de port établi par l'utilisateur étend l'accès hors de cette décision. |
| Automatisation expédiée — critique | Erreur de compilation sous `WEBFRONT_DISTRIBUTION`. | Une build qui ne définit pas cette macro n'est pas protégée par elle. |
Expand Down
Loading
Loading