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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Agents is on; every MCP call fails with a 403 otherwise. An outside agent cannot
2. The approval settings are readable only in the window, so plan for a wait. With "Ask me before an agent deletes, replaces the open project or changes retention" on (`agentDestructive`), destructive tools and any `apply_commands` batch that removes something wait for a person's decision; only the person can change that choice.
3. If a call waits, it holds up to 100 seconds. Tell the person to watch Agent Connect and wait for the result. If it ends with "No one approved", the approval expired: ask them to be ready and retry once. If it ends with "The person denied", stop, do not rephrase the request to slip past the denial, and offer a non-destructive alternative.
4. Never approve your own request. Decisions are the person's, or a reviewer's for releases (see sibling `branch-and-review`).
5. For a client card, `GET /api/agents/clients` reports each file as missing, ready or changed. Writing that client's project file (`.mcp.json`, `.codex/config.toml` or `.cursor/mcp.json`) is done by the person from the card in Agent Connect; a request from outside the window is refused with "Only the FormWeb window can do this." Ask for the one card the person wants.
5. For a client card, `GET /api/agents/clients` reports each file as missing, ready or changed. Writing that client's project file (`.mcp.json`, `.codex/config.toml` or `.cursor/mcp.json`) is done by the person from the card in Agent Connect; a request from outside the window is refused with "Only the FormWeb window can do this." Ask for the one card the person wants. In the installed desktop app the written entries name the running app's `http://127.0.0.1:PORT/mcp` instead of the `formweb` launcher; after the app changes port the card reads changed and the person writes it again.
6. The terminal is a shell in the FormWeb folder that only the FormWeb window can open; an outside agent cannot, and should not look for another way in. It is for the person's own work; do not run commands that print tokens or provider secrets.
7. `./formweb run --list` lists engine commands. `./formweb run node.update id=headline 'patch={"text":"Hello"}'` applies one; values are parsed as JSON when possible. Add `--json` for machine output and `--revision N` to require a revision. The command line is an outside agent too: it calls the MCP endpoint, so Agents must be on and the approval settings apply. The change is one undo step, appears live and is attributed to the agent channel.
8. After changes, read `formweb://activity` to confirm who did what and under which channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Agents is on; every MCP call fails with a 403 otherwise. An outside agent cannot
2. The approval settings are readable only in the window, so plan for a wait. With "Ask me before an agent deletes, replaces the open project or changes retention" on (`agentDestructive`), destructive tools and any `apply_commands` batch that removes something wait for a person's decision; only the person can change that choice.
3. If a call waits, it holds up to 100 seconds. Tell the person to watch Agent Connect and wait for the result. If it ends with "No one approved", the approval expired: ask them to be ready and retry once. If it ends with "The person denied", stop, do not rephrase the request to slip past the denial, and offer a non-destructive alternative.
4. Never approve your own request. Decisions are the person's, or a reviewer's for releases (see sibling `branch-and-review`).
5. For a client card, `GET /api/agents/clients` reports each file as missing, ready or changed. Writing that client's project file (`.mcp.json`, `.codex/config.toml` or `.cursor/mcp.json`) is done by the person from the card in Agent Connect; a request from outside the window is refused with "Only the FormWeb window can do this." Ask for the one card the person wants.
5. For a client card, `GET /api/agents/clients` reports each file as missing, ready or changed. Writing that client's project file (`.mcp.json`, `.codex/config.toml` or `.cursor/mcp.json`) is done by the person from the card in Agent Connect; a request from outside the window is refused with "Only the FormWeb window can do this." Ask for the one card the person wants. In the installed desktop app the written entries name the running app's `http://127.0.0.1:PORT/mcp` instead of the `formweb` launcher; after the app changes port the card reads changed and the person writes it again.
6. The terminal is a shell in the FormWeb folder that only the FormWeb window can open; an outside agent cannot, and should not look for another way in. It is for the person's own work; do not run commands that print tokens or provider secrets.
7. `./formweb run --list` lists engine commands. `./formweb run node.update id=headline 'patch={"text":"Hello"}'` applies one; values are parsed as JSON when possible. Add `--json` for machine output and `--revision N` to require a revision. The command line is an outside agent too: it calls the MCP endpoint, so Agents must be on and the approval settings apply. The change is one undo step, appears live and is attributed to the agent channel.
8. After changes, read `formweb://activity` to confirm who did what and under which channel.
Expand Down
2 changes: 2 additions & 0 deletions .docs/wiki/Agents-and-MCP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ FormWeb works with four agent programs: Claude Code, Codex, Cursor and Antigravi

Run `./formweb boot` or `./formweb serve`, enable Agents in the editor, and trust this project in the client. `./formweb agents install` prints the included project configuration paths and launch commands; it does not change user-level configuration. Windows clients should use an absolute `formweb.bat` path and `mcp` argument.

In the installed desktop app there is no `formweb` launcher to start, so Write config in Agent Connect writes files that reach the running app over HTTP instead: `.mcp.json`, `.codex/config.toml` and `.cursor/mcp.json` in the FormWeb folder (`~/FormWeb`, or `FORMWEB_HOME`) each name `http://127.0.0.1:PORT/mcp`, with the port the app is using now, and the Antigravity card adds a `formweb` entry with that address to `~/.gemini/config/mcp_config.json`. Agents must be on in the window for these to connect, as before. If the app starts on another port later, the card says the file has changed; press Write config again. The Antigravity entry FormWeb wrote for an earlier port is updated; an entry you wrote yourself is left alone. With `FORMWEB_AUTH_TOKEN` set, the three project files name that variable, and the agent program reads the token from its own environment; the token is never written into a file. Antigravity's entry has no way to name a variable, so in that case its card writes nothing, and an entry FormWeb wrote there before shows as changed, because without the token it cannot connect; Open in terminal still starts Antigravity with FormWeb's tools. The address and the variable are built in `backend/app/clients.py`.

The server exposes 104 tools, 17 resources and 5 prompts (the site import tool `library_import_site`, which reviews or imports a static site zip sent as base64, made it 104; v0.19.5 added `copy_element` and `paste_element`, which move an element with its motion, code, variables and assets between pages and sites through `POST /api/fragment` and `POST /api/paste`; v0.19.6 added design tokens, text presets and CMS collections to the fragment, and `embed_assets` on `copy_element` so a fragment pastes in another FormWeb, with `paste_element` passing `embedded` through; v0.19.8 added `clip` on both, which carries assets beyond 4 MiB by the loopback clip link (15 minutes by default, `FORMWEB_CLIP_SECONDS` changes it) and needs `embed_assets` (v0.20.1 streams clip assets to disk on paste); v0.19.3 added the 14 authoring tools for motion, variables, components, the section library, new sites and Send to FormPublisher; v0.7.0 added `list_ui_commands`, `describe_ui_command` and `run_ui_command`, which list and run the open editor window's own commands through the window bridge, with an in-window Allow for risky ones; v0.5.6 added `write_copy` and `generate_site`, both using the language model set in formvis; v0.5.7 gave `generate_site` a `reference` action and outline revision; v0.5.5 added `generate_image` and `edit_in_formvis`, v0.5.4 added `search_stock` and `insert_stock`, v0.5.3 `remove_background`, v0.5.2 the team library tools). `generate_image` waits up to 90 seconds, below the stdio proxy's 130, and otherwise returns a job to pass back. Eight domain tools (`edit_nodes`, `edit_pages`, `edit_styles`, `edit_components`, `edit_cms`, `edit_locales`, `edit_site`, and since v0.7 `edit_creative` for tables, sliders, layout defaults, superscript and subscript and multi-step forms) are generated from the engine catalogue in `backend/app/mcp_domains.py` and list each command's parameters; edits return a compact summary unless `detail: "site"` is passed. Every tool has a title; `get_site`, `apply_commands` and `edit_nodes` carry `_meta["anthropic/alwaysLoad"]` so Claude Code loads them without a tool search. Errors carry a `next` sentence the agent can act on. Resources include `formweb://site/tree` (outline with IDs), `formweb://selection` (the editor's selection, reported while Agents is on), `formweb://tokens` and `formweb://audit`. Prompts: build_page, edit_copy, responsive_review, publish_site, recover_session. The stdio proxy forwards the server's instructions and prompts and waits up to 130 seconds per call so approval waits finish. The original authoring tools now share the catalog with content portability, library review, form delivery, releases, branches, comments/access, code compilation and provider workflows. `backend/app/advanced_catalog.py` and `backend/app/providers/catalog.py` define the additions. The live `tools/list` and `resources/list` are authoritative; use the [agent quick start](../../docs/AGENT_QUICKSTART.md) and [advanced Studio guide](../../docs/ADVANCED_GUIDE.md) for the actual operation loop.

## Authoring tools for motion, variables, components and the library (0.19.3)
Expand Down
53 changes: 45 additions & 8 deletions backend/app/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
reads one file for the whole account, ~/.gemini/config/mcp_config.json: its card adds the one entry named formweb there
when the person asks, keeps every other entry and key, and leaves alone an entry of that name it did not write. The
Claude Code card's Open button does not depend on its file: it starts Claude through POST /api/terminal/open with
FormWeb's own MCP config. On Windows the Codex file names formweb.bat in this folder. The installed app ships no
launcher, so there it writes none of these files.
FormWeb's own MCP config. On Windows the Codex file names formweb.bat in this folder.

The installed app ships no launcher, so there each file and the Antigravity entry name the running app's HTTP endpoint,
http://127.0.0.1:PORT/mcp, instead. With FORMWEB_AUTH_TOKEN set, the three project files name that variable for the
client to read from its own environment; the token itself is never written to disk. Antigravity's entry cannot name a
variable, so in that case its card writes nothing. An entry FormWeb wrote for an earlier port is pointed at this one.
"""
import json
import os
import re
from pathlib import Path

from . import claude_code
from .config import FROZEN, ROOT
from .config import AUTH_TOKEN, FROZEN, ROOT
from .engine import EngineError

CLIENTS = {
Expand Down Expand Up @@ -41,10 +46,24 @@
}


INSTALLED = 'The installed app does not include the formweb launcher these files start, so nothing was written. Open in Agent Connect starts each program with FormWeb\'s tools.'
TOKEN_VAR = 'FORMWEB_AUTH_TOKEN'
OWN_URL = re.compile(r'http://127\.0\.0\.1:[0-9]{1,5}/mcp')


def http_content(client_id):
url = claude_code.mcp_url()
if client_id == 'codex':
token = f'bearer_token_env_var = "{TOKEN_VAR}"\n' if AUTH_TOKEN else ''
return f'[mcp_servers.formweb]\nurl = {json.dumps(url)}\n{token}startup_timeout_sec = 30\ntool_timeout_sec = 120\n'
named = '${' + TOKEN_VAR + '}' if client_id == 'claude-code' else '${env:' + TOKEN_VAR + '}'
headers = {'headers': {'Authorization': 'Bearer ' + named}} if AUTH_TOKEN else {}
entry = {**({'type': 'http'} if client_id == 'claude-code' else {}), 'url': url, **headers}
return json.dumps({'mcpServers': {'formweb': entry}}, indent=2) + '\n'


def content(client_id, system=None):
if FROZEN:
return http_content(client_id)
if client_id == 'codex' and (system or os.name) == 'nt':
return f'[mcp_servers.formweb]\ncommand = {json.dumps(str(ROOT / "formweb.bat"), ensure_ascii=False)}\nargs = ["mcp"]\nstartup_timeout_sec = 30\ntool_timeout_sec = 120\n'
return CLIENTS[client_id]['content']
Expand All @@ -59,10 +78,20 @@ def antigravity_file():
return Path.home() / '.gemini' / 'config' / 'mcp_config.json'


PROTECTED = f'FORMWEB_AUTH_TOKEN is set, and FormWeb does not write that token into {ANTIGRAVITY["path"]}, so nothing was written. Open in Agent Connect starts Antigravity with FormWeb\'s tools.'


def antigravity_entry():
if FROZEN:
return {'serverUrl': claude_code.mcp_url()}
return {'command': str(ROOT / ('formweb.bat' if os.name == 'nt' else 'formweb')), 'args': ['mcp']}


def antigravity_ours(entry):
"""An installed app's entry for another port: only a serverUrl on this computer's /mcp, nothing a person added."""
return FROZEN and isinstance(entry, dict) and set(entry) == {'serverUrl'} and isinstance(entry['serverUrl'], str) and OWN_URL.fullmatch(entry['serverUrl']) is not None


def antigravity_read():
path = antigravity_file()
try:
Expand All @@ -75,21 +104,31 @@ def antigravity_read():
def antigravity_card():
data = antigravity_read()
entry = None if data is None else data.get('mcpServers', {}).get(ANTIGRAVITY_ENTRY)
status = 'changed' if data is None else 'missing' if entry is None else 'ready' if entry == antigravity_entry() else 'changed'
guarded = FROZEN and bool(AUTH_TOKEN) # the entry cannot carry the token, so no entry of FormWeb's can connect
status = 'changed' if data is None else 'missing' if entry is None else 'ready' if entry == antigravity_entry() and not guarded else 'changed'
notes = []
if data is None:
notes.append(f'{ANTIGRAVITY["path"]} is not an MCP servers file FormWeb can read, so it was left alone.')
elif guarded and antigravity_ours(entry):
notes.append(f'FORMWEB_AUTH_TOKEN is set, and the {ANTIGRAVITY_ENTRY} entry in {ANTIGRAVITY["path"]} carries no token, so it cannot connect.')
elif status == 'changed' and antigravity_ours(entry):
notes.append(f'The {ANTIGRAVITY_ENTRY} entry in {ANTIGRAVITY["path"]} names another port. Write points it at this one.')
elif status == 'changed':
notes.append(f'{ANTIGRAVITY["path"]} has an entry named {ANTIGRAVITY_ENTRY} that FormWeb did not write, so it was left alone.')
if guarded:
notes.append(f'FORMWEB_AUTH_TOKEN is set, so Write adds no entry to {ANTIGRAVITY["path"]}.')
if (Path.home() / '.gemini' / 'antigravity-cli' / 'mcp_config.json').is_file():
notes.append(f'An older file, {OLDER_FILE}, was seen and left alone.')
found = claude_code.located('antigravity').path is not None
return {'id': 'antigravity', 'name': ANTIGRAVITY['name'], 'file': ANTIGRAVITY['path'], 'status': status, 'cliFound': found, 'cli': ANTIGRAVITY['cli'], 'start': ANTIGRAVITY['start'], 'launch': None, 'note': ' '.join(notes)}


def antigravity_write():
if FROZEN and AUTH_TOKEN:
raise EngineError(PROTECTED, 409)
data = antigravity_read()
if data is not None and data.get('mcpServers', {}).get(ANTIGRAVITY_ENTRY) is None:
entry = None if data is None else data.get('mcpServers', {}).get(ANTIGRAVITY_ENTRY)
if data is not None and (entry is None or antigravity_ours(entry)):
path = antigravity_file()
data.setdefault('mcpServers', {})[ANTIGRAVITY_ENTRY] = antigravity_entry()
path.parent.mkdir(parents=True, exist_ok=True)
Expand All @@ -114,8 +153,6 @@ def cards():


def write(client_id):
if FROZEN:
raise EngineError(INSTALLED, 409)
if client_id == 'antigravity':
return antigravity_write()
if client_id not in CLIENTS:
Expand Down
Loading
Loading