|
1 | 1 | --- |
2 | | -slug: /flutterflow-cli/mcp |
| 2 | +slug: /flutterflow-cli/build |
3 | 3 | title: Build with AI Agents |
4 | | -description: Learn how to created and edit FlutterFlow projects with your own agents. |
| 4 | +description: Create and edit FlutterFlow projects from your terminal using your preferred AI coding agent. |
5 | 5 | tags: [CLI, AI, MCP] |
6 | 6 | sidebar_position: 3 |
7 | 7 | keywords: [CLI, Agentic AI, Projects, Local Management, MCP] |
8 | 8 | --- |
9 | 9 |
|
10 | | - |
11 | 10 | # Build with AI Agents |
12 | | -The FlutterFlow CLI lets you build and edit FlutterFlow apps in the terminal instead of in the visual builder. You can use it to create brand-new apps or for changes to ones you already have. It's designed for AI agents, so you can hand work off and review their changes like any other code. |
13 | 11 |
|
14 | | -:::info[Remember] |
| 12 | +The FlutterFlow CLI lets you create and edit FlutterFlow apps from the terminal using your own AI coding agent — Claude Code, Gemini CLI, Codex, or any MCP-compatible client. You describe what you want in plain English, the agent plans and applies the changes, and the result lands as a real FlutterFlow project you can open in the visual builder. |
15 | 13 |
|
| 14 | +A FlutterFlow project is the source of truth. The CLI is how you create or edit it from your local workspace. |
| 15 | + |
| 16 | +:::info[Remember] |
16 | 17 | - **FF CLI is not a replacement for the visual builder.** FlutterFlow is still faster for most visual work. FF CLI is for precision, repeatability, and automation. |
17 | | -- **FF CLI doesn't execute your app.** It produces a FlutterFlow project, which you can test and run inside FlutterFlow visual builder. |
| 18 | +- **FF CLI doesn't execute your app.** It produces a FlutterFlow project, which you can test and run inside the FlutterFlow visual builder. |
18 | 19 | ::: |
19 | 20 |
|
20 | | -A FlutterFlow project is the source of truth. FF CLI is how you create or change it from code. You can write an app in the terminal, open the result in FlutterFlow's visual editor, and keep going in either direction. Both paths give you the same FlutterFlow app. |
21 | | - |
22 | 21 |  |
23 | 22 |
|
24 | | -### Create Projects |
| 23 | +## Architecture |
| 24 | + |
| 25 | +`flutterflow ai init` creates a local **workspace** - a folder pre-configured with an MCP config file pointing at the FlutterFlow MCP server. When you launch your AI agent inside that folder, it discovers the MCP server and gains a set of tools that talk to FlutterFlow's cloud: |
25 | 26 |
|
26 | | -Let’s walk through using the FlutterFlow CLI by building a simple meditation app: |
| 27 | +1. You prompt the agent. |
| 28 | +2. The agent plans changes and calls the MCP server's tools. |
| 29 | +3. The MCP server applies those changes to your FlutterFlow project. |
| 30 | +4. You verify the result in the FlutterFlow visual builder. |
27 | 31 |
|
28 | | -#### 1. Start the workspace setup |
| 32 | +The workspace is just a folder on your disk. The actual project lives in FlutterFlow. |
| 33 | + |
| 34 | +:::tip[What is MCP?] |
| 35 | +The [Model Context Protocol](https://modelcontextprotocol.io) is an open standard that lets AI agents call external tools. The FlutterFlow AI MCP server exposes FlutterFlow's project APIs to your agent so it can read and modify your project on your behalf. |
| 36 | +::: |
| 37 | + |
| 38 | +:::info[Prerequisites] |
| 39 | + |
| 40 | +Before you start, make sure you have: |
| 41 | + |
| 42 | +- **FlutterFlow CLI installed.** See [Installation](./overview.md). |
| 43 | +- **A FlutterFlow API key.** See [generating an API token](../../../accounts-billing/account-management.md#how-do-i-generate-an-api-token). |
| 44 | +- **An MCP-compatible AI agent installed locally** — for example, [Claude Code](https://www.claude.com/product/claude-code), [Gemini CLI](https://github.com/google-gemini/gemini-cli), or [Codex](https://github.com/openai/codex). |
| 45 | +- **A FlutterFlow project ID** (only if you're editing an existing project). |
| 46 | +::: |
| 47 | + |
| 48 | +## Setup Workspace |
29 | 49 |
|
30 | 50 | Open your terminal in the folder where you want the workspace to live, then run: |
31 | 51 |
|
32 | 52 | ```bash |
33 | 53 | flutterflow ai init |
34 | 54 | ``` |
35 | 55 |
|
36 | | -This launches an interactive setup wizard. |
| 56 | +This launches an interactive setup wizard. Walk through the prompts: |
| 57 | + |
| 58 | +1. **Workspace name.** A short, lowercase name with no spaces. This becomes the folder name for your project. |
| 59 | + ``` |
| 60 | + Workspace name |
| 61 | + Directory to scaffold the FlutterFlow AI workspace in. |
| 62 | + > mindfly |
| 63 | + ``` |
| 64 | +2. **Environment.** Use ↑ / ↓ to highlight the FlutterFlow environment you want this workspace to target, then press **Enter**. |
| 65 | +3. **Link to an existing FlutterFlow project?** Press **Enter** (default `N`) to create a new app. Answer `y` to bind the workspace to an existing project — the wizard will then ask for the project ID. |
| 66 | + ``` |
| 67 | + Link to an existing FlutterFlow project? [y/N] |
| 68 | + ``` |
| 69 | +4. **FlutterFlow API key.** Paste your API key and press **Enter**. Input is masked. |
| 70 | +5. **Register MCP server with detected coding CLIs.** The wizard scans your `PATH` and offers to register the FlutterFlow AI MCP server with each agent it finds (Claude Code, Gemini CLI, Codex). Answer `Y` (default) for each one you plan to use. |
| 71 | + ``` |
| 72 | + Register FlutterFlow AI MCP server with coding CLIs |
| 73 | + Detected: claude, gemini, codex |
| 74 | + Register with claude? [Y/n] |
| 75 | + ``` |
| 76 | +6. **Confirm.** The wizard prints a summary. Review it and press **Enter** (default `Y`) to proceed. |
| 77 | + ``` |
| 78 | + Ready to create: |
| 79 | + Workspace: mindfly |
| 80 | + Project ID: (none — unlinked) |
| 81 | + API key: set (***abcd) |
| 82 | + Base URL: https://api.flutterflow.io (built-in for prod) |
| 83 | + MCP CLIs: claude, gemini, codex |
| 84 | +
|
| 85 | + Proceed? [Y/n] |
| 86 | + ``` |
| 87 | + |
| 88 | +When the wizard finishes, you'll have a workspace folder ready for your agent. Depending on which CLIs you registered, the folder will contain one or more of: |
| 89 | + |
| 90 | +- `.mcp.json` — for Claude Code |
| 91 | +- `.gemini/settings.json` — for Gemini CLI |
| 92 | +- `.codex/config.toml` — for Codex |
| 93 | + |
| 94 | +Each file points the corresponding agent at the FlutterFlow AI MCP server. |
| 95 | + |
| 96 | +## Launch your Agent |
| 97 | + |
| 98 | +Move into the workspace and start your agent. The example below uses Claude Code; the same pattern applies to any agent you registered in the wizard — `cd` into the workspace and launch the agent's CLI. |
37 | 99 |
|
38 | | -#### 2. Name your workspace |
| 100 | +```bash |
| 101 | +cd mindfly |
| 102 | +claude |
| 103 | +``` |
39 | 104 |
|
40 | | -The wizard will ask for a workspace name or path. Type a short, lowercase name with no spaces. This becomes the folder name for your project. |
| 105 | +The first time the agent opens the workspace, it detects the new MCP server and asks you to approve it. The exact prompt varies by agent — Claude Code's looks like this: |
41 | 106 |
|
42 | 107 | ``` |
43 | | -Workspace name or path |
44 | | -> mindfly |
45 | | -``` |
| 108 | +New MCP server found in .mcp.json: flutterflow_ai |
46 | 109 |
|
47 | | -#### 3. Pick an environment |
| 110 | +MCP servers may execute code or access system resources. |
| 111 | +All tool calls require approval. |
48 | 112 |
|
49 | | -Next you'll see a list of FlutterFlow environments to connect to. Use ↑ / ↓ to highlight your choice and press **Enter**. |
| 113 | +> 1. Use this and all future MCP servers in this project |
| 114 | + 2. Use this MCP server |
| 115 | + 3. Continue without using this MCP server |
| 116 | +``` |
| 117 | + |
| 118 | +Choose **option 1** to approve the FlutterFlow AI MCP server (and any others added to this workspace later) without being asked again. |
50 | 119 |
|
| 120 | +> **Why approve?** Without the MCP server, the agent can edit local files but can't push changes to your FlutterFlow project. With it approved, the agent has the same tools you'd run yourself from the CLI. |
51 | 121 |
|
52 | | -#### 4. Paste your FlutterFlow API key |
| 122 | +## Generate a New App |
53 | 123 |
|
54 | | -The wizard will ask for your API key. Paste it and press **Enter**. |
| 124 | +With the agent connected, describe the app you want at the prompt: |
55 | 125 |
|
56 | 126 | ``` |
57 | | -FlutterFlow API key |
58 | | -> your-api-key-here |
| 127 | +> create a minimalist meditation app |
59 | 128 | ``` |
60 | 129 |
|
61 | | -#### 5. Choose: New app or Edit existing |
| 130 | +Phrase it however you like — `a recipe-sharing app with a social feed`, `a habit tracker with streaks`, `a tip calculator for restaurants`. The agent plans the app, generates the changes, pushes them to FlutterFlow through the MCP server, and reports back. Open FlutterFlow in your browser and navigate to the project — the generated app will be reflected in the visual builder. From there you can keep refining visually or send another prompt to the agent. |
62 | 131 |
|
63 | | -The wizard now asks whether you want to edit an existing FlutterFlow project or create a new one: |
| 132 | +Once the app exists, the workspace is bound to it. Follow-up prompts in the same session are treated as edits, not new generations, you'll see the agent acknowledge the switch with something like: |
64 | 133 |
|
65 | 134 | ``` |
66 | | -Existing project ID to edit (press Enter to create a new app) |
67 | | -> paste-your-project-id-here |
| 135 | +The project is bound, so I'll switch to edit mode. |
| 136 | +Let me check the workspace and read the edit template. |
68 | 137 | ``` |
69 | 138 |
|
70 | | -Press **Enter** with no input to create a new app. (To edit an existing project instead, paste its project ID here.) |
| 139 | +From that point on, the same rules apply as when [editing an existing project](#edit-an-existing-project) - concurrency, branches, scope, and refreshing context. |
71 | 140 |
|
72 | | -#### 6. Confirm the setup |
| 141 | +## Edit an Existing Project |
73 | 142 |
|
74 | | -The wizard prints a summary of what it's about to do: |
| 143 | +:::info[Prerequisite] |
| 144 | +Have your **project ID** ready. Open the project in the FlutterFlow editor. The project ID is the path segment after `/project/` in the URL. |
| 145 | +::: |
75 | 146 |
|
76 | | -``` |
77 | | -Ready to create FlutterFlow AI workspace: |
78 | | - Workspace: /Users/.../projects/mindfly |
79 | | - Flow: Create a new app |
80 | | - Environment: beta |
81 | | - SDK: 0.1.6 (build aed0f835) |
82 | | - Base URL: https://api.flutterflow.io/v2-staging |
83 | | -
|
84 | | -Proceed? [Y/n] |
| 147 | +Editing an existing project follows the same flow as [creating a new one](#set-up-a-workspace) — you run `flutterflow ai init` to scaffold a workspace, then drive changes from your agent. The only difference is one step in the wizard: when it asks **Link to an existing FlutterFlow project?**, answer `y` and paste your project ID: |
| 148 | + |
| 149 | +```dart |
| 150 | +Link to an existing FlutterFlow project? [y/N] y |
| 151 | +Project ID |
| 152 | +> my-meditation-app-x7k2p9 |
85 | 153 | ``` |
86 | 154 |
|
87 | | -Review the workspace path, environment, and flow. If everything looks right, press **Y** and **Enter**. |
| 155 | +The workspace is now bound to that project. `cd` into the workspace folder, [launch your agent](#launch-your-agent), and describe the changes you want — "add a profile screen", "switch the primary color to teal", "wire up the login form to Firebase Auth". The agent reads the current project, plans the change, and pushes it through the MCP server. Open FlutterFlow in your browser to verify. |
88 | 156 |
|
| 157 | +### Concurrent Edits with Builder |
89 | 158 |
|
90 | | -#### 7. Move into the workspace and launch your agent |
| 159 | +You can edit visually while an agent is working, but writes use **optimistic concurrency**: when the agent pushes, the server checks the project's last-modified timestamp against the agent's snapshot. If anyone else (you in the visual builder, a teammate, or another agent) modified the project in between, the push is rejected. The agent will re-read the latest state and retry — which may also mean re-planning, if your change conflicts with what it was about to do. |
91 | 160 |
|
92 | | -Move into the new workspace folder and start your preferred coding agent. This example uses Claude Code: |
| 161 | +So nothing gets silently overwritten, but expect occasional retries when you and the agent are editing the same project at once. |
93 | 162 |
|
94 | | -```bash |
95 | | -cd mindfly |
96 | | -``` |
97 | | -and then... |
98 | | -```bash |
99 | | -claude |
100 | | -``` |
| 163 | +## Branches and Rollback |
101 | 164 |
|
102 | | -#### 8. Approve the FlutterFlow AI MCP server |
| 165 | +:::warning[Agents commit to main] |
| 166 | +Workspaces always target the project's **main branch**. There's no flag to point them at a feature branch. Every successful push creates a commit on main, so for high-stakes projects, work on a clone, make sure version history is enabled, or coordinate with your team before letting an agent run. |
| 167 | +::: |
103 | 168 |
|
104 | | -The first time the agent opens the workspace, it will detect the new MCP server and ask for permission: |
| 169 | +To roll back, use FlutterFlow's project version history in the visual builder — the same mechanism you'd use for visual edits. Each agent push lands as a commit there with whatever commit message the agent supplied. |
105 | 170 |
|
106 | | -``` |
107 | | -New MCP server found in .mcp.json: flutterflow_ai |
| 171 | +## Refreshing Stale Context |
108 | 172 |
|
109 | | -MCP servers may execute code or access system resources. |
110 | | -All tool calls require approval. |
| 173 | +If you've made visual edits since the agent last read the project, the agent's local snapshot is stale. Two ways to fix it: |
111 | 174 |
|
112 | | -> 1. Use this and all future MCP servers in this project |
113 | | - 2. Use this MCP server |
114 | | - 3. Continue without using this MCP server |
115 | | -``` |
| 175 | +- **Ask the agent to refresh.** Most agents call the MCP `refreshContext` tool on their own when they detect drift, but you can prompt explicitly: "refresh the project context." |
| 176 | +- **Run it from the CLI.** `flutterflow ai context-check` reports whether the local snapshot is behind, and `flutterflow ai refresh-context <project-id>` pulls the latest. |
116 | 177 |
|
117 | | -Choose **option 1** to use the FlutterFlow AI MCP server (and any others added to this workspace later) without being asked again. Press **Enter** to confirm. |
| 178 | +## Switching Projects |
118 | 179 |
|
119 | | -> **Why approve?** Without the MCP server, the agent can edit local files but can't actually push changes to your FlutterFlow project. With it approved, the agent has the same tools you'd run yourself from the CLI. |
120 | | -> |
| 180 | +A workspace is bound to one project. To work on a different project, run `flutterflow ai init` in a **new** folder and link it to the new project ID. `init` refuses to run in a non-empty directory, so it won't re-bind an existing workspace. |
121 | 181 |
|
122 | | -#### 9. Describe your app in plain English |
| 182 | +## Agent edit scope |
123 | 183 |
|
124 | | -Claude Code is now connected to your workspace and the FlutterFlow AI MCP server. Type what you want to build at the prompt: |
| 184 | +**In scope** |
125 | 185 |
|
126 | | -``` |
127 | | -> create a minimalist meditation app |
128 | | -``` |
| 186 | +- Pages, components, app state, theme, navigation, action blocks, app events |
| 187 | +- Custom functions, actions, widgets, classes, and enums |
| 188 | +- API endpoints, queries, custom data types and enums |
| 189 | +- Pub and library dependencies, design tokens, GenUI catalog, Firebase Auth wiring |
| 190 | + |
| 191 | +**Out of scope** |
| 192 | + |
| 193 | +- A few DSL gaps that may close over time — shaders, and parameter types like `Document`, `SQLiteRow`, `WidgetBuilder`, `ChildSlotParam`, `ApiResponse`, `TimestampRange`, `GooglePlace`, `RevenueCat` types, `CustomCloudFunctionResponse`, and `ResponseStreamMessage`. |
| 194 | +- Anything outside the FlutterFlow project itself — running the app, deploying it, creating Firebase projects, managing secrets, App Store submissions. |
| 195 | + |
| 196 | +## MCP server tools |
| 197 | + |
| 198 | +Once approved, the FlutterFlow AI MCP server gives your agent the following tools. |
| 199 | + |
| 200 | +**Core actions** |
129 | 201 |
|
130 | | -Press **Enter**. The agent will plan the app, generate the code, push it to FlutterFlow through the MCP server, and report back. |
| 202 | +| Tool | What it does | |
| 203 | +| --- | --- | |
| 204 | +| `run` | Applies a planned set of changes to your FlutterFlow project. This is how edits get pushed. | |
| 205 | +| `validate` | Dry-runs a change without pushing it, so the agent can catch errors before committing. | |
| 206 | +| `inspect` | Reads project structure — either a whole-project summary or a scoped view. | |
| 207 | +| `resources` | Lists reusable project and library resources (components, custom code, etc.). | |
| 208 | +| `init` | Scaffolds a new FlutterFlow AI workspace. | |
131 | 209 |
|
132 | | -#### 10. Verify the app in the FlutterFlow visual builder |
133 | | -Open FlutterFlow in your browser and navigate to your project. You’ll see the generated app reflected in the visual builder. From here, you can continue refining the app visually or iterate further using the AI agent. |
| 210 | +**Supporting** |
134 | 211 |
|
135 | | -### Modify Projects |
136 | | -To modify an existing project, [paste your project ID](#5-choose-new-app-or-edit-existing) when prompted instead of pressing Enter. This connects the workspace to your current FlutterFlow app. Once set up, you can use the AI agent to make changes, and updates will be pushed directly to the existing project. |
| 212 | +`status`, `search`, `refreshContext`, `contextCheck`, `docs`, `history` — used by the agent for project metadata, searching, refreshing its context, looking up FlutterFlow documentation, and reviewing prior tool calls. |
137 | 213 |
|
| 214 | +The agent calls these tools on your behalf based on your prompts. Every tool call is subject to your agent's approval rules. |
0 commit comments