Dart MCP Server

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Integrates with Codeium IDE through the Model Context Protocol, allowing AI coding assistants to leverage Dart functionality

  • Provides seamless access to Dart SDK commands for AI-powered development, enabling analysis, compilation, project creation, documentation, fixes, formatting, package management, and testing of Dart code

  • Identifies and works with Flutter projects, providing Dart SDK commands that support Flutter development workflows

Dart MCP 服务器

一个可分布式的模型上下文协议 (MCP) 服务器,用于公开 Dart SDK 命令以支持 AI 开发。该服务器通过实现模型上下文协议 (MCP),弥合了 AI 编程助手与 Dart/Flutter 开发工作流程之间的差距。

特征

此 MCP 服务器提供对以下 Dart SDK 命令的无缝访问:

命令描述
dart-analyze分析 Dart 代码中的错误、警告和 lint
dart-compile将 Dart 编译为各种格式(exe、AOT/JIT 快照、JavaScript)
dart-create从模板创建新的 Dart 项目
dart-doc为 Dart 项目生成 API 文档
dart-fix对 Dart 源代码应用自动修复
dart-format根据样式指南格式化 Dart 源代码
dart-info显示有关已安装 Dart 工具的诊断信息
dart-package使用包(获取、添加、升级、过时等)
dart-run运行 Dart 程序并支持传递参数
dart-test运行支持过滤和报告选项的测试

主要优点

  • 智能路径处理:自动将相对路径解析为绝对路径,确保命令无论工作目录如何都能正常工作
  • 项目自动检测:识别主目录和工作区等常见位置中的 Dart/Flutter 项目
  • 跨平台支持:适用于 macOS、Linux 和 Windows
  • 零配置:开箱即用,具有合理的默认设置
  • MCP 集成:兼容任何 MCP 客户端,包括 Windsurf、Cline 和其他模型上下文协议实现

先决条件

  • Node.js :18.x 或更高版本
  • Dart SDK :已安装 3.0 或更高版本,并且可在 PATH 中使用

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 Dart MCP 服务器:

npx -y @smithery/cli install @egyleader/dart-mcp --client claude

使用 npx(推荐)

使用 npx 无需安装即可直接运行服务器:

npx @egyleader/dart-mcp-server

全局安装

为了更方便地访问,您可以全局安装服务器:

npm install -g @egyleader/dart-mcp-server

然后使用以下命令运行它:

dart-mcp-server

来自源

# Clone the repository git clone https://github.com/egyleader/dart-mcp-server.git cd dart-mcp-server # Install dependencies npm install # Build the project npm run build # Run the server node dist/index.js

与 MCP 客户端集成

Windsurf / Codeium IDE 配置

要将此 MCP 服务器与 Windsurf 或 Codeium IDE 一起使用,请将以下内容添加到您的mcp_config.json文件(通常位于~/.codeium/windsurf/mcp_config.json ):

{ "mcpServers": { "dart": { "command": "npx", "args": [ "-y", "@egyleader/dart-mcp-server" ] } } }

环境变量

  • DART_MCP_VERBOSE :设置为任意值以启用详细日志记录以进行调试

MCP 工具使用示例

以下是如何使用服务器提供的 MCP 工具的示例。这些示例展示了可以传递给每个工具的参数。

dart 分析

分析 Dart 代码中的错误、警告和 lint:

{ "path": "lib/main.dart", "options": ["--fatal-infos", "--fatal-warnings"] }

dart 编译

将 Dart 代码编译为各种格式:

{ "path": "lib/main.dart", "format": "exe", "output": "build/app", "options": ["--verbose"] }

支持的格式: exeaot-snapshotjit-snapshotkerneljs

dart 创建

从模板创建一个新的 Dart 项目:

{ "projectName": "my_awesome_app", "template": "console", "output": "projects/my_awesome_app", "options": ["--force"] }

关于项目名称和输出的注释:

  • 如果仅提供projectName ,则它将用作创建项目的目录名称。
  • 如果提供了output ,它将被用作创建项目的目录。
  • Dart 中的实际包/项目名称来自 Dart CLI 的最终目录名称。

支持的模板: consolepackageserver-shelfweb

dart 文档

为 Dart 项目生成 API 文档:

{ "path": ".", "output": "doc", "options": ["--exclude", "lib/generated"] }

dart-fix

对 Dart 源代码应用自动修复:

{ "path": "lib", "apply": true, "options": ["--pedantic"] }

dart 格式

根据样式指南格式化 Dart 源代码:

{ "paths": ["lib/main.dart", "lib/models"], "setExitIfChanged": true, "options": ["--line-length=100"] }

dart 信息

显示有关已安装的 Dart 工具的诊断信息:

{ "options": ["--verbose"] }

dart 包

使用包(pub 命令):

{ "command": "get", "workingDir": ".", "args": ["--offline"] }

支持的命令: getupgradeoutdatedaddremovepublishdepsdowngradecacherunglobal

飞镖跑

运行支持传递参数的 Dart 程序:

{ "script": "bin/server.dart", "workingDir": ".", "args": ["--port=8080", "--mode=production"] }

飞镖测试

运行支持过滤和报告选项的测试:

{ "path": "test", "workingDir": ".", "options": ["--name=login", "--platform=chrome"] }

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

工具 API 参考

dart 分析

分析目录或文件中的 Dart 代码。

{ path?: string; // Directory or file to analyze options?: string[]; // Additional options for the dart analyze command }

例子:

{ path: "lib", options: ["--fatal-infos", "--fatal-warnings"] }

dart 编译

将 Dart 编译为各种格式。

{ format: 'exe' | 'aot-snapshot' | 'jit-snapshot' | 'kernel' | 'js'; // Output format path: string; // Path to the Dart file to compile output?: string; // Output file path options?: string[]; // Additional compilation options }

例子:

{ format: "exe", path: "bin/main.dart", output: "bin/app" }

dart 创建

创建一个新的 Dart 项目。

{ template: 'console' | 'package' | 'server-shelf' | 'web'; // Project template projectName: string; // Name of the project to create output?: string; // Directory where to create the project options?: string[]; // Additional project creation options }

笔记:

  • 如果提供了output ,则项目将在该目录中创建。
  • 如果仅提供projectName ,它将被用作目录名称。
  • 实际的 Dart 包名称源自最终的目录名称。

例子:

{ template: "package", projectName: "my_dart_library", output: "projects/my_dart_library" }

dart 文档

为 Dart 项目生成 API 文档。

{ path?: string; // Directory containing the Dart package to document output?: string; // Output directory for the generated documentation options?: string[]; // Additional documentation options }

例子:

{ path: ".", output: "doc/api" }

dart-fix

对 Dart 源代码应用自动修复。

{ path?: string; // Directory or file to apply fixes to apply?: boolean; // Whether to apply the suggested fixes (default: true) options?: string[]; // Additional fix options }

例子:

{ path: "lib", apply: true, options: ["--pedantic"] }

dart 格式

惯用格式的 Dart 源代码。

{ paths: string[]; // Files or directories to format setExitIfChanged?: boolean; // Return exit code 1 if there are formatting changes (default: false) options?: string[]; // Additional format options }

例子:

{ paths: ["lib", "test"], setExitIfChanged: true, options: ["--line-length=80"] }

dart 信息

显示有关已安装工具的诊断信息。

{ options?: string[]; // Additional info options }

例子:

{ options: ["--verbose"] }

dart 包

使用包(pub 命令)。

{ command: 'get' | 'upgrade' | 'outdated' | 'add' | 'remove' | 'publish' | 'deps' | 'downgrade' | 'cache' | 'run' | 'global'; // Pub subcommand args?: string[]; // Arguments for the pub subcommand workingDir?: string; // Working directory for the command }

例子:

// Add a package { command: "add", args: ["rxdart"], workingDir: "my_project" } // Get dependencies { command: "get", workingDir: "my_project" }

飞镖跑

运行 Dart 程序。

{ script: string; // Path to the Dart script to run args?: string[]; // Arguments to pass to the script workingDir?: string; // Working directory for the command }

例子:

{ script: "bin/main.dart", args: ["--verbose"], workingDir: "my_project" }

飞镖测试

对项目运行测试。

{ path?: string; // Path to the test file or directory options?: string[]; // Additional test options workingDir?: string; // Working directory for the command }

例子:

{ path: "test", options: ["--coverage", "--name=auth"], workingDir: "my_project" }

发展

# Watch mode for development pnpm run dev # Build for production pnpm run build

错误处理

服务器实现了全面的错误处理:

  • 捕获命令执行错误并进行适当格式化
  • 路径解析问题通过详细诊断进行报告
  • 长时间运行操作的超时处理
  • Dart 命令的正确退出代码传播

贡献

请参阅CONTRIBUTING.md了解详细的贡献指南。

我们的提交格式如下:

<type>[optional scope]: [JIRA-123(optional)] <description>

例子:

feat(tools): [DART-456] add support for dart test tags

执照

麻省理工学院

ID: vuwii9l5gu