|
1 | 1 | The Dart Tooling MCP Server exposes Dart and Flutter development tool actions to compatible AI-assistant clients. |
2 | 2 |
|
3 | | -[](https://cursor.com/install-mcp?name=dart_tooling&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoiZGFydCBtY3Atc2VydmVyIC0tZXhwZXJpbWVudGFsLW1jcC1zZXJ2ZXIgLS1mb3JjZS1yb290cy1mYWxsYmFjayJ9) |
4 | | - |
5 | 3 | ## Status |
6 | 4 |
|
7 | 5 | WIP. This package is still experimental and is likely to evolve quickly. |
8 | 6 |
|
9 | | -## Tools |
| 7 | +## Set up your MCP client |
10 | 8 |
|
11 | | -| Tool Name | Feature Group | Description | |
12 | | -| --- | --- | --- | |
13 | | -| `analyze_files` | `static analysis` | Analyzes the entire project for errors. | |
14 | | -| `signature_help` | `static_analysis` | Gets signature information for usage at a given cursor position. | |
15 | | -| `hover` | `static_analysis` | Gets the hover information for a given cursor position. | |
16 | | -| `resolve_workspace_symbol` | `static analysis` | Look up a symbol or symbols in all workspaces by name. | |
17 | | -| `dart_fix` | `static tool` | Runs `dart fix --apply` for the given project roots. | |
18 | | -| `dart_format` | `static tool` | Runs `dart format .` for the given project roots. | |
19 | | -| `pub` | `static tool` | Runs a `dart pub` command for the given project roots. | |
20 | | -| `pub_dev_search` | `package search` | Searches pub.dev for packages relevant to a given search query. | |
21 | | -| `get_runtime_errors` | `runtime analysis` | Retrieves the list of runtime errors that have occurred in the active Dart or Flutter application. | |
22 | | -| `take_screenshot` | `runtime analysis` | Takes a screenshot of the active Flutter application in its current state. | |
23 | | -| `get_widget_tree` | `runtime analysis` | Retrieves the widget tree from the active Flutter application. | |
24 | | -| `get_selected_widget` | `runtime analysis` | Retrieves the selected widget from the active Flutter application. | |
25 | | -| `hot_reload` | `runtime tool` | Performs a hot reload of the active Flutter application. | |
26 | | -| `connect_dart_tooling_daemon`* | `configuration` | Connects to the locally running Dart Tooling Daemon. | |
27 | | -| `get_active_location` | `editor` | Gets the active cursor position in the connected editor (if available). | |
28 | | -| `run_tests` | `static tool` | Runs tests for the given project roots. | |
29 | | -| `create_project` | `static tool` | Creates a new Dart or Flutter project. | |
30 | | - |
31 | | -> *Experimental: may be removed. |
| 9 | +<!-- Note: since many of our tools require access to the Dart Tooling Daemon, we may want |
| 10 | +to be cautious about recommending tools where access to the Dart Tooling Daemon does not exist. --> |
32 | 11 |
|
33 | | -## Usage |
34 | | - |
35 | | -This server only supports the STDIO transport mechanism and runs locally on |
36 | | -your machine. Many of the tools require that your MCP client has `roots` |
37 | | -support, and usage of the tools is scoped to only these directories. |
| 12 | +The Dart MCP server can work with any MCP client that supports standard I/O (stdio) as the |
| 13 | +transport medium. To access all the features of the Dart MCP server, an MCP client must support |
| 14 | +[Tools](https://modelcontextprotocol.io/docs/concepts/tools) and |
| 15 | +[Resources](https://modelcontextprotocol.io/docs/concepts/resources). For the best development |
| 16 | +experience with the Dart MCP server, an MCP client should also support |
| 17 | +[Roots](https://modelcontextprotocol.io/docs/concepts/roots). |
38 | 18 |
|
39 | 19 | If you are using a client that claims it supports roots but does not actually |
40 | 20 | set them, pass `--force-roots-fallback` which will instead enable tools for |
41 | 21 | managing the roots. |
42 | 22 |
|
43 | | -### Running from the SDK |
44 | | - |
45 | | -For most users, you should just use the `dart mcp-server` command. For now you |
46 | | -also need to provide `--experimental-mcp-server` in order for the command to |
47 | | -succeed. |
| 23 | +Here are specific instructions for some popular tools: |
48 | 24 |
|
49 | | -### Running a local checkout |
| 25 | +### Gemini CLI |
50 | 26 |
|
51 | | -The server entrypoint lives at `bin/main.dart`, and can be ran however you |
52 | | -choose, but the easiest way is to run it as a globally activated package. |
| 27 | +To configure the [Gemini CLI](https://github.com/google-gemini/gemini-cli) to use the Dart MCP |
| 28 | +server, edit the `.gemini/settings.json` file in your local project (configuration will only |
| 29 | +apply to this project) or edit the global `~/.gemini/settings.json` file in your home directory |
| 30 | +(configuration will apply for all projects). |
53 | 31 |
|
54 | | -You can globally activate it from path for local development: |
55 | | - |
56 | | -```sh |
57 | | -dart pub global activate -s path . |
58 | | -``` |
59 | | - |
60 | | -Or from git: |
61 | | - |
62 | | -```sh |
63 | | -dart pub global activate -s git https://github.com/dart-lang/ai.git \ |
64 | | - --git-path pkgs/dart_mcp_server/ |
| 32 | +```json |
| 33 | +{ |
| 34 | + "mcpServers": { |
| 35 | + "dart": { |
| 36 | + "command": "dart", |
| 37 | + "args": [ |
| 38 | + "mcp-server", |
| 39 | + "--experimental-mcp-server", // Can be removed for Dart 3.9.0 or later. |
| 40 | + ] |
| 41 | + } |
| 42 | + } |
| 43 | +} |
65 | 44 | ``` |
66 | 45 |
|
67 | | -And then, assuming the pub cache bin dir is [on your PATH][set-up-path], the |
68 | | -`dart_mcp_server` command will run it, and recompile as necessary. |
| 46 | +For more information, see the official Gemini CLI documentation for |
| 47 | +[setting up MCP servers](https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md#how-to-set-up-your-mcp-server). |
69 | 48 |
|
70 | | -[set-up-path]: https://dart.dev/tools/pub/cmd/pub-global#running-a-script-from-your-path |
| 49 | +### Gemini Code Assist in VS Code |
71 | 50 |
|
72 | | -**Note:**: For some clients, depending on how they launch the MCP server and how |
73 | | -tolerant they are, you may need to compile it to exe to avoid extra output on |
74 | | -stdout: |
| 51 | +> Note: this currently requires the "Insiders" channel. Follow |
| 52 | +[instructions](https://developers.google.com/gemini-code-assist/docs/use-agentic-chat-pair-programmer#before-you-begin) |
| 53 | +to enable this build. |
75 | 54 |
|
76 | | -```sh |
77 | | -dart compile exe bin/main.dart |
78 | | -``` |
79 | | - |
80 | | -And then provide the path to the executable instead of using the globally |
81 | | -activated `dart_mcp_server` command. |
82 | | - |
83 | | -### With the example WorkflowBot |
| 55 | +[Gemini Code Assist](https://codeassist.google/)'s |
| 56 | +[Agent mode](https://developers.google.com/gemini-code-assist/docs/use-agentic-chat-pair-programmer) integrates the Gemini CLI to provide a powerful |
| 57 | +AI agent directly in your IDE. To configure Gemini Code Assist to use the Dart MCP |
| 58 | +server, follow the instructions to [configure the Gemini](#gemini-cli) CLI above. |
84 | 59 |
|
85 | | -After compiling the binary, you can run the example [workflow bot][workflow_bot] |
86 | | -to interact with the server. Note that the workflow bot sets the current |
87 | | -directory as the root directory, so if your server expects a certain root |
88 | | -directory you will want to run the command below from there (and alter the |
89 | | -paths as necessary). For example, you may want to run this command from the |
90 | | -directory of the app you wish to test the server against. |
| 60 | +You can verify the MCP server has been configured properly by typing `/mcp` in the chat window in Agent mode. |
91 | 61 |
|
92 | | -[workflow_bot]: https://github.com/dart-lang/ai/tree/main/mcp_examples/bin/workflow_client.dart |
93 | | - |
94 | | -```dart |
95 | | -dart pub add "dart_mcp_examples:{git: {url: https://github.com/dart-lang/ai.git, path: mcp_examples}}" |
96 | | -dart run dart_mcp_examples:workflow_client --server dart_mcp_server |
97 | | -``` |
| 62 | + |
98 | 63 |
|
99 | | -### With Cursor |
| 64 | +For more information see the official Gemini Code Assist documentation for |
| 65 | +[using agent mode](https://developers.google.com/gemini-code-assist/docs/use-agentic-chat-pair-programmer#before-you-begin). |
100 | 66 |
|
101 | | -The following button should work for most users: |
| 67 | +<!-- ### Android Studio --> |
| 68 | +<!-- TODO(https://github.com/dart-lang/ai/issues/199): once we are confident that the |
| 69 | +Dart MCP server will work well with Android Studio's MCP support, add documentation here |
| 70 | +for configuring the server in Android Studio. --> |
102 | 71 |
|
103 | | -[](https://cursor.com/install-mcp?name=dart_tooling&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoiZGFydCBtY3Atc2VydmVyIC0tZXhwZXJpbWVudGFsLW1jcC1zZXJ2ZXIgLS1mb3JjZS1yb290cy1mYWxsYmFjayJ9) |
| 72 | +### Cursor |
104 | 73 |
|
105 | | -To manually install it, go to Cursor -> Settings -> Cursor Settings and select "MCP". |
| 74 | +[](https://cursor.com/install-mcp?name=dart&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoiZGFydCBtY3Atc2VydmVyIC0tZXhwZXJpbWVudGFsLW1jcC1zZXJ2ZXIgLS1mb3JjZS1yb290cy1mYWxsYmFjayJ9) |
106 | 75 |
|
107 | | -Then, click "Add new global MCP server". |
| 76 | +The easiest way to configure the Dart MCP server with Cursor is by clicking the "Add to Cursor" |
| 77 | +button above. |
108 | 78 |
|
109 | | -If you are directly editing your mcp.json file, it should look like this: |
| 79 | +Alternatively, you can configure the server manually. Go to **Cursor -> Settings -> Cursor Settings > Tools & Integrations**, and then click **"Add Custom MCP"** or **"New MCP Server"** |
| 80 | +depending on whether you already have other MCP servers configured. Edit the `.cursor/mcp.json` file in your local project (configuration will only apply to this project) or |
| 81 | +edit the global `~/.cursor/mcp.json` file in your home directory (configuration will apply for |
| 82 | +all projects) to configure the Dart MCP server: |
110 | 83 |
|
111 | 84 | ```json |
112 | 85 | { |
113 | 86 | "mcpServers": { |
114 | | - "dart_mcp": { |
| 87 | + "dart": { |
115 | 88 | "command": "dart", |
116 | 89 | "args": [ |
117 | 90 | "mcp-server", |
118 | | - "--experimental-mcp-server", |
119 | | - "--force-roots-fallback" |
| 91 | + "--experimental-mcp-server", // Can be removed for Dart 3.9.0 or later |
| 92 | + "--force-roots-fallback" // Workaround for a Cursor issue with Roots support |
120 | 93 | ] |
121 | 94 | } |
122 | 95 | } |
123 | 96 | } |
124 | 97 | ``` |
125 | 98 |
|
126 | | -Each time you make changes to the server, you'll need to restart the server on |
127 | | -the MCP configuration page or reload the Cursor window (Developer: Reload Window |
128 | | -from the Command Palette) to see the changes. |
| 99 | +For more information, see the official Cursor documentation for |
| 100 | +[installing MCP servers](https://docs.cursor.com/context/model-context-protocol#installing-mcp-servers). |
| 101 | + |
| 102 | +### GitHub Copilot in VS Code |
| 103 | + |
| 104 | +<!-- TODO: once the dart.mcpServer setting is not hidden, we may be able |
| 105 | +to provide a deep link to the Dart Extension Settings UI for users to |
| 106 | +enable the server. See docs: https://code.visualstudio.com/docs/configure/settings#_settings-editor. |
| 107 | +This may be preferable to adding the deep link button to VS Code's mcp settings. --> |
| 108 | + |
| 109 | +To configure the Dart MCP server with Copilot or any other AI agent that supports the |
| 110 | +[VS Code MCP API](https://code.visualstudio.com/api/extension-guides/mcp), add the following |
| 111 | +to your VS Code user settings: |
| 112 | +```json |
| 113 | +"dart.mcpServer": true |
| 114 | +``` |
| 115 | + |
| 116 | +By adding this setting, the Dart VS Code extension will register the Dart MCP Server |
| 117 | +configuration with VS Code so that you don't have to manually configure the server. |
| 118 | +Copilot will then automatically configure the Dart MCP server on your behalf. This is |
| 119 | +a global setting. |
| 120 | + |
| 121 | +Alternatively, you can click the "Add to VS Code" button below to manually configure the server |
| 122 | +in your VS Code user settings. |
| 123 | + |
| 124 | +[](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22dart%22%2C%22command%22%3A%22dart%22%2C%22args%22%3A%5B%22mcp-server%22%2C%22--experimental-mcp%22%5D%7D) |
129 | 125 |
|
130 | | -## Development |
| 126 | +Or, you can manually edit the `.vscode/mcp.json` file in your workspace, |
| 127 | +which will only configure the Dart MCP server for the local workspace: |
131 | 128 |
|
132 | | -For local development, use the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector). |
| 129 | +```json |
| 130 | +"servers": { |
| 131 | + "dart": { |
| 132 | + "type": "stdio", |
| 133 | + "command": "dart", |
| 134 | + "args": [ |
| 135 | + "mcp-server", |
| 136 | + "--experimental-mcp-server", // Can be removed for Dart 3.9.0 or later |
| 137 | + ] |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
133 | 141 |
|
134 | | -1. Run the inspector with no arguments: |
135 | | - ```shell |
136 | | - npx @modelcontextprotocol/inspector |
137 | | - ``` |
| 142 | +For more information, see the official VS Code documentation for |
| 143 | +[enabling MCP support](https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_enable-mcp-support-in-vs-code). |
138 | 144 |
|
139 | | -2. Open the MCP Inspector in the browser and enter `dart_mcp_server` in |
140 | | -the "Command" field. |
| 145 | +## Tools |
141 | 146 |
|
142 | | -3. Click "Connect" to connect to the server and debug using the MCP Inspector. |
| 147 | +| Tool Name | Feature Group | Description | |
| 148 | +| --- | --- | --- | |
| 149 | +| `analyze_files` | `static analysis` | Analyzes the entire project for errors. | |
| 150 | +| `signature_help` | `static_analysis` | Gets signature information for usage at a given cursor position. | |
| 151 | +| `hover` | `static_analysis` | Gets the hover information for a given cursor position. | |
| 152 | +| `resolve_workspace_symbol` | `static analysis` | Look up a symbol or symbols in all workspaces by name. | |
| 153 | +| `dart_fix` | `static tool` | Runs `dart fix --apply` for the given project roots. | |
| 154 | +| `dart_format` | `static tool` | Runs `dart format .` for the given project roots. | |
| 155 | +| `pub` | `static tool` | Runs a `dart pub` command for the given project roots. | |
| 156 | +| `pub_dev_search` | `package search` | Searches pub.dev for packages relevant to a given search query. | |
| 157 | +| `get_runtime_errors` | `runtime analysis` | Retrieves the list of runtime errors that have occurred in the active Dart or Flutter application. | |
| 158 | +| `take_screenshot` | `runtime analysis` | Takes a screenshot of the active Flutter application in its current state. | |
| 159 | +| `get_widget_tree` | `runtime analysis` | Retrieves the widget tree from the active Flutter application. | |
| 160 | +| `get_selected_widget` | `runtime analysis` | Retrieves the selected widget from the active Flutter application. | |
| 161 | +| `hot_reload` | `runtime tool` | Performs a hot reload of the active Flutter application. | |
| 162 | +| `connect_dart_tooling_daemon`* | `configuration` | Connects to the locally running Dart Tooling Daemon. | |
| 163 | +| `get_active_location` | `editor` | Gets the active cursor position in the connected editor (if available). | |
| 164 | +| `run_tests` | `static tool` | Runs tests for the given project roots. | |
| 165 | +| `create_project` | `static tool` | Creates a new Dart or Flutter project. | |
| 166 | + |
| 167 | +> *Experimental: may be removed. |
0 commit comments