Extending
Every change below starts the same way: a failing test. See testing for where it goes. Before adding anything, read the closest existing example end to end — the repository already has one of each, and a parallel pattern rots the first time someone changes the original.
Adding an MCP tool
- Name it in
TOOL_NAMEinserver/src/domain/tool-names.ts. Names arefigma_*. The history classifies calls by these names, so they are domain vocabulary, not an adapter detail. If the tool modifies the Figma file, add it toWRITE_TOOLSin the same file. - Write the use case in
server/src/application/, against ports, with its test next to it. A new port gets an in-memory double inapplication/testing/before it gets a real adapter. - Register it in the
register*function ofserver/src/adapters/mcp/that matches its family (tools.ts,read-tools.ts,build-tools.ts,capture-tools.ts,history-tools.ts);createMcpServerinserver.tscalls them. Each registration declares:- an input schema in zod — the tool’s only validation, at the edge;
- an output schema, with the common envelope
{ ok, …, error, retryable }. Every write returns the ids of the nodes it touched; - annotations —
readOnlyHint: truefor anything that does not write.
- Wrap the handler in
track(recorder, TOOL_NAME.x, args, …)so the call reaches the activity log and the history. Build the reply with the helpers inpresenters.ts(reply,usageError). - Decide what the agent harness does with it.
server/src/domain/agent-harness.tslists which tools the dashboard chat agent may call without asking (MCP_READS); one that changes Figma or captures the web goes inCHAT_AGENT_DENIED_TOOLS(server/src/domain/tool-names.ts), which its settings, its guard and the server refuse. The exact generated configuration is pinned by a fixture inserver/test/fixtures/agent-harness/; update it in the same change. - Test it through MCP with an in-memory client and server: see
server/src/adapters/mcp/tools.int.test.ts. - Document it in the tools reference, in both languages.
Adding a kit step
A kit step is a { use: "kit/<name>@1", … } entry in a build manifest: fixed code the server
sends to the tab, which calls a piece of the Figma kit with parameters the server assembles from the
consumer project’s files.
- The piece goes in
kits/figma/steps/<name>.tsand is exported fromstepsinkits/figma/steps/index.ts. It returns astep@1result: the ids it created, mutated or removed, plus warnings and a report. - The name goes into the step lists and the name-to-piece map in
server/src/domain/step.ts, which also builds the fixed code (kitStepCode). - The manifest contract in
server/src/adapters/contracts/build-manifest.tsaccepts the newuseand its fields. Thennpm run schemas. - Resolving the parameters — from the loaded project, without reading disk — lives in
server/src/application/kit-step.ts(and its*-plan.tssiblings for screens, sheets and compose). - The simulator. Hermetic tests never run the kit in Figma:
server/test/harness/kit-step-reply.tsrecognises a step’s fixed code and answers astep@1result built from its parameters. Teach it the new step so E2E scenarios can exercise it. - Pure tests of the piece run against a fake Figma in
server/test/kits/figma/pure/. - Re-bundle with
npm run build:kit; the bundle test fails otherwise. - If the behaviour depends on what real Figma does, add a case to
make kit-contract(server/test/contract/figma-kit.e2e.test.ts).
Adding or changing a contract
- Change the zod schema in
server/src/adapters/contracts/. A contract is versioned (@1): an incompatible change is a new version, not an edit. npm run schemasregeneratesschemas/<name>.v<n>.json. The schema’s test compares the committed file withz.toJSONSchemaand tells you to regenerate when they differ.- The example in
server/test/contracts/is built from the schema and validated as it is built — never pasted from a real output. Update it and its cases incontracts.test.ts. - Each contract cites its public source in a
*_CONTRACT_SOURCESlist; keep it pointing at the contracts reference, and update that page in both languages.
Adding a configuration variable
Configuration has one reader: server/src/adapters/config/env.ts. Everything else receives the
parsed configuration. A new variable goes, in the same change, into:
- The schema in
server/src/adapters/config/schema.ts, with its.default(...)unless it is truly mandatory. Watch Zod 4:.default()takes the output value and skips thetransform, so a default path is passed already resolved withtoAbsolute(...)and a list as its array. - Exactly one class:
EDITABLE_KEYS(changeable from the dashboard’s settings page) with its entry inSETTING_INFO— group, name, help, unit and who uses it, which the page renders without touching the web — orBOOT_KEYS(fixed at startup). A test fails if a key is left unclassified. .env.example, as documentation of the override.- Shell scripts under
spikes/read the environment, not the schema: if one needs the variable, repeat its default with${VAR:-…}.
Changing the database
- Change
server/src/adapters/sqlite/schema.tsand runnpm run db:generate; the Drizzle migration lands inserver/src/adapters/sqlite/migrations/. - A table with project data gets
project_id(foreign key,ON DELETE CASCADE, first in its indexes), is read through a scoped repository, and is added to the project-table list inserver/test/architecture.test.ts— which fails if the schema and that list disagree. - Drizzle knows nothing about FTS5. Full-text tables and their triggers go in a hand-written SQL
migration, like
0002_fts.sql, with--> statement-breakpointbetween statements.