1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dart MCP Server が動かない?誤解を招くエラーメッセージの正体と解決策

Last updated at Posted at 2025-11-25

TL;DR

Dart MCP Server を Claude Code で使用する際、以下のエラーに遭遇する可能性があります:

  1. 「A Dart SDK of version 3.9.0-163.0.dev or greater is required」 - 実際はバージョンの問題ではない
  2. 「Not connected」 - すべての MCP ツールが失敗する
{
  "mcpServers": {
    "dart": {
      "command": "dart",
      "args": ["mcp-server", "--force-roots-fallback"]
    }
  }
}

背景

Dart MCP Server は、AI アシスタント(Claude Code、Cursor、GitHub Copilot など)と Flutter/Dart 開発ツールを接続するための MCP (Model Context Protocol) サーバーです。

しかし、このツールはまだ 実験的 (Experimental) であり、設定や使用時に複数の落とし穴があります。


問題1: 誤解を招く SDK バージョンエラー

症状

connect_dart_tooling_daemon で接続成功後、hot_reloadget_widget_tree を実行すると以下のエラーが発生:

A Dart SDK of version 3.9.0-163.0.dev or greater is required to connect to Dart and Flutter applications.

実際の環境

$ dart --version
Dart SDK version: 3.10.0 (stable) (Thu Nov 6 05:24:55 2025 -0800)

$ flutter --version
Flutter 3.38.1 • channel stable

明らかに要件を満たしている にもかかわらず、エラーが発生します。

根本原因

このエラーメッセージは 誤解を招く ものです。実際の問題は以下のいずれかです:

  1. URI の種類の混同 - VM Service URI と DTD (Dart Tooling Daemon) URI は異なる
  2. MCP クライアントの Roots サポート問題 - Claude Code は Roots を正しく設定しない

関連 Issue

これらの Issue では、ユーザーが Dart 3.9.x〜3.10.x を使用しているにもかかわらず、同じエラーに遭遇しています。Flutter チームはこれを dart-lang/ai リポジトリにリダイレクトしています。


問題2: 「Not connected」エラー

症状

すべての dart MCP ツールが「Not connected」を返す:

mcp__dart__list_devices → "Not connected"
mcp__dart__connect_dart_tooling_daemon → "Not connected"
mcp__dart__pub_dev_search → "Not connected"

根本原因

Claude Code は MCP の Roots 機能をサポートしていると宣言していますが、実際には適切に設定しません。Dart MCP Server は Roots が設定されていることを期待しているため、接続に失敗します。

解決策

.mcp.json--force-roots-fallback フラグを追加:

{
  "mcpServers": {
    "dart": {
      "type": "stdio",
      "command": "dart",
      "args": ["mcp-server", "--force-roots-fallback"]
    }
  }
}

このフラグは「Roots サポートを主張するが実際には設定しないクライアント」向けのワークアラウンドです。

参考: Dart MCP Server README

If you are using a client that claims it supports roots but does not actually set them, pass --force-roots-fallback which will instead enable tools for managing the roots.


URI の種類について

Flutter アプリ起動時には複数の URI が提供されますが、MCP 接続には正しい URI を使用する必要があります。

URI の種類 用途 フォーマット例
VM Service URI デバッグ、パフォーマンス分析 http://127.0.0.1:8181/
DTD (Dart Tooling Daemon) URI MCP サーバー接続、IDE統合 ws://127.0.0.1:32979/abc123=
DevTools URI ブラウザベースのデバッグUI http://127.0.0.1:8181/devtools/?uri=...

DTD URI の取得方法

Flutter アプリを --print-dtd フラグ付きで起動:

flutter run -d linux --print-dtd

ログに以下の形式で出力されます:

The Dart Tooling Daemon is available at: ws://127.0.0.1:32979/LwN1PlcoQOo=

推奨設定

Claude Code 用 .mcp.json

{
  "mcpServers": {
    "dart": {
      "type": "stdio",
      "command": "dart",
      "args": ["mcp-server", "--force-roots-fallback"]
    }
  }
}

Cursor 用 .cursor/mcp.json

{
  "mcpServers": {
    "dart": {
      "command": "dart",
      "args": ["mcp-server", "--force-roots-fallback"]
    }
  }
}

VS Code + GitHub Copilot

VS Code 設定 (settings.json) に追加:

{
  "dart.mcpServer": true
}

Dart-Code 拡張機能 v3.114 以降で自動的に MCP サーバーが登録されます。


動作確認手順

  1. Flutter アプリを起動

    flutter run -d linux --print-dtd
    
  2. DTD URI を確認

    The Dart Tooling Daemon is available at: ws://127.0.0.1:XXXXX/abc=
    
  3. MCP 接続をテスト

    • mcp__dart__list_devices → デバイス一覧が返る
    • mcp__dart__connect_dart_tooling_daemon → "Connection succeeded"
    • mcp__dart__get_widget_tree → ウィジェットツリーが返る

トラブルシューティング

「Not connected」が解消しない場合

  1. Claude Code を再起動(MCP サーバーの設定を反映)
  2. .mcp.json のパスが正しいか確認(プロジェクトルートに配置)
  3. dart --version で Dart 3.9.0 以上か確認

DTD 接続後も操作が失敗する場合

  1. Flutter アプリが --print-dtd 付きで起動されているか確認
  2. DTD URI が最新か確認(アプリ再起動時に URI が変わる)
  3. ポートがファイアウォールでブロックされていないか確認

まとめ

問題 原因 解決策
SDK バージョンエラー 誤解を招くエラーメッセージ --force-roots-fallback を追加
Not connected Roots サポートの不整合 --force-roots-fallback を追加
DTD 接続失敗 間違った URI を使用 --print-dtd で正しい URI を取得

Dart MCP Server はまだ実験段階であり、今後の更新でこれらの問題が修正される可能性があります。公式ドキュメントと GitHub Issue を定期的に確認することをお勧めします。


参考リンク

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?