Dart MCP服务器
](https://www.npmjs.com/package/@egyleader/dart-mcp-server)  ](https://smithery.ai/server/@egyleader/dart-mcp)
一个可分发的模型上下文协议(MCP)服务器,为AI驱动的开发提供Dart SDK命令。该服务器通过实现模型上下文协议(MCP)弥合了AI编码助手和Dart/Flutter开发工作流程之间的差距。
特性
此MCP服务器提供对以下Dart SDK命令的无缝访问:
| 命令 | 描述 |
|---|---|
dart-analyze | 分析Dart代码中的错误、警告和lints |
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安装
通过以下方式自动安装Dart MCP Server for Claude Desktop 史密瑟里:
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代码中的错误、警告和lints:
{
"path": "lib/main.dart",
"options": ["--fatal-infos", "--fatal-warnings"]
}dart编译
将Dart代码编译为各种格式:
{
"path": "lib/main.dart",
"format": "exe",
"output": "build/app",
"options": ["--verbose"]
}支持的格式: exe, aot-snapshot, jit-snapshot, kernel, js
飞镖制造
从模板创建新的Dart项目:
{
"projectName": "my_awesome_app",
"template": "console",
"output": "projects/my_awesome_app",
"options": ["--force"]
}关于项目名称和输出的说明:
- 要是…就好了
projectName如果提供,它将用作创建项目的目录名。 - 如果
output如果提供,它将用作创建项目的目录。 - Dart中的实际包/项目名称由Dart CLI从最终目录名称派生而来。
支持的模板: console, package, server-shelf, web
达特医生
为Dart项目生成API文档:
{
"path": ".",
"output": "doc",
"options": ["--exclude", "lib/generated"]
}飞镖固定
对Dart源代码应用自动修复:
{
"path": "lib",
"apply": true,
"options": ["--pedantic"]
}飞镖格式
根据样式指南格式化Dart源代码:
{
"paths": ["lib/main.dart", "lib/models"],
"setExitIfChanged": true,
"options": ["--line-length=100"]
}飞镖信息
显示已安装Dart工具的诊断信息:
{
"options": ["--verbose"]
}飞镖包装
使用包(发布命令):
{
"command": "get",
"workingDir": ".",
"args": ["--offline"]
}支持的命令: get, upgrade, outdated, add, remove, publish, deps, downgrade, cache, run, global
飞镖跑
运行支持传递参数的Dart程序:
{
"script": "bin/server.dart",
"workingDir": ".",
"args": ["--port=8080", "--mode=production"]
}飞镖试验
运行支持过滤和报告选项的测试:
{
"path": "test",
"workingDir": ".",
"options": ["--name=login", "--platform=chrome"]
}许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
贡献
欢迎投稿!请随时提交拉取请求。
工具API参考
飞镖分析
分析目录或文件中的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项目。
{
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项目生成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源代码应用自动修复。
{
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源代码。
{
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"]
}飞镖信息
显示有关已安装工具的诊断信息。
{
options?: string[]; // Additional info options
}例子:
{
options: ["--verbose"]
}飞镖包装
使用包(发布命令)。
{
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命令中正确传播退出代码
贡献
请看 贡献.md 详细的贡献指南。
我们的提交格式如下:
[optional scope]: [JIRA-123(optional)] 例子:
feat(tools): [DART-456] add support for dart test tags许可证
麻省理工学院
